<template>
  <div class="app-container">
    <div>
      <div class="tab-header webtop">
        <div>车辆列表</div>
        <div>
          <el-button type="danger" size="small" @click="handleDelete">删除</el-button>
          <el-button type="info" size="small" @click="handleReturn">关闭</el-button>
        </div>
      </div>
      <div class="listconadd">
        <div class="titwu">
          <div>车辆列表</div>
        </div>
        <el-form class="formadd">
          <el-table :key="tableKey" ref="multipleTable" v-loading="listLoading" :data="list" border style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column width="50px" type="selection" align="center"/>
            <el-table-column width="80px" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column prop="modelName" label="车型" align="center" min-width="150" />
            <el-table-column prop="vinNo" label="车架号" align="center" width="150" />
            <el-table-column prop="costPrice" label="车辆入库价" align="center" width="140" />
            <el-table-column prop="priceDate" label="入库日期" align="center" width="120" />
            <el-table-column prop="salesDate" label="销售日期" align="center" width="120" />
            <el-table-column prop="solidDate" label="买断日期" align="center" width="120" />
          </el-table>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import req from '@/api/specialrebate/specialrebatedistribution'

export default {
  name: 'SpecialRebateToBeAllocatedByDisNum',
  data() {
    return {
      index: 0,
      tableKey: 0,
      sids: [],
      list: [],
      listLoading: false,
      specialRebateSid: ''
    }
  },
  methods: {
    handleDelete() {
      if (this.sids.length === 0) {
        this.$message({ showClose: true, type: 'error', message: '请选择至少一条记录进行删除操作' })
        return
      }
      const tip = '请确认是否删除所选 ' + this.sids.length + ' 条记录?'
      this.$confirm(tip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        req.delBySids(this.sids).then((resp) => {
          if (resp.success) {
            this.$message({ showClose: true, type: 'success', message: '删除成功' })
            this.getList()
          }
        })
      })
    },
    // 返回
    handleReturn() {
      this.$emit('doback')
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      req.getVehBySpecialRebateSid({ specialRebateSid: this.specialRebateSid }).then((response) => {
        this.listLoading = false
        if (response.success) {
          this.list = response.data
        }
      })
    },
    handleSelectionChange(row) {
      this.sids = []
      const aa = []
      row.forEach((element) => {
        aa.push(element.specialRebateVehSid)
      })
      this.sids = aa
    },
    showData(row) {
      this.specialRebateSid = row.sid
      this.getList()
    }
  }
}
</script>
<style scoped>
</style>
