<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <!--标题按钮部分开始-->
      <div class="tab-header webtop">
        <!--标题-->
        <div>{{ viewTitle }}</div>
        <!--start 添加修改按钮-->
        <div>
          <el-button type="danger" size="small" @click="handleDelete">删除</el-button>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <!--标题按钮部分结束-->
      <!--Start 新增修改部分-->
      <div class="listconadd">
        <el-form ref="form_obj" :rules="rules" class="formadd">
          <el-table :key="tableKey" :data="list" :index="index" border style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column fixed type="selection" align="center" width="50px"/>
            <el-table-column fixed width="80px" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column prop="purchaseSystemName" label="采购系统" align="center" width="140" />
            <el-table-column prop="brandName" label="品牌" align="center" width="120" />
            <el-table-column prop="vehModelName" label="车型" align="center" min-width="150" />
            <el-table-column prop="vinNo" label="车架号" align="center" width="140" />
            <el-table-column prop="manufactorSettlementPrice" label="车辆入库价" align="center" width="130" />
            <el-table-column prop="freight" label="其中运费" align="center" width="120" />
            <el-table-column prop="createTime" label="创建日期" align="center" width="120" />
            <el-table-column prop="rebateTypeValue" label="返利类型" align="center" width="120" />
            <el-table-column prop="rebateName" label="返利名称" align="center" min-width="150" />
            <el-table-column prop="calculationStandard" label="计算标准" align="center" width="120" />
            <el-table-column prop="estimateRebate" label="预计返利" align="center" width="120" />
            <el-table-column prop="expectTreatCost" label="其中待支付费用" align="center" width="140" />
            <el-table-column prop="expectSuppCost" label="其中抵顶费用" align="center" width="140" />
            <el-table-column prop="expectSuppRemark" label="抵顶费用说明" align="center" min-width="200" />
            <el-table-column prop="palceGenDate" label="所属年月" align="center" width="120" />
          </el-table>
        </el-form>
      </div>
    </div>
    <!--End 添加修改部分-->
  </div>
</template>

<script>
import req from '@/api/bikerebate/bicyclerebatewithholding'

export default {
  name: 'DanCheFanLiAdd',
  data() {
    return {
      viewTitle: '',
      index: 0,
      tableKey: 0,
      viewState: 1,
      rebateType: '', // 返利类型
      purchaseSystemName: '', // 采购系统
      brandName: '', // 品牌
      sids: [],
      // 表单数据
      list: [],
      rules: {},
      submitdisabled: false
    }
  },
  methods: {
    handleSelectionChange(row) {
      const aa = []
      row.forEach((element) => {
        aa.push(element.sid)
      })
      this.sids = aa
      console.log('sids', this.sids)
    },
    showInfo(row) {
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.viewTitle = '待预提单车返利明细'
      this.rebateType = row.rebateTypeValue
      this.purchaseSystemName = row.purchaseSystemName
      this.brandName = row.brandName
      console.log('编辑回显', row.sid)
      req.vehRebateWithDetails(row.vehRebateSids).then((resp) => {
        this.list = resp.data
      }).catch((e) => {
        this.formobj = row
      })
    },
    handleDelete() {
      if (this.sids.length === 0) {
        this.$message({
          showClose: true,
          type: 'error',
          message: '请选择至少一条记录进行删除操作'
        })
        return
      }
      for (var i = 0; i < this.list.length; i++) {
        for (var j = 0; j < this.sids.length; j++) {
          if (this.list[i].sid === this.sids[j]) {
            this.list.splice(i, 1)
          }
        }
      }
    },
    // 返回（===既判断）
    handleReturn() {
      const data_list = []
      for (var i = 0; i < this.list.length; i++) {
        data_list.push({
          sid: this.list[i].sid,
          rebateTypeValue: this.list[i].rebateTypeValue,
          rebateTypeKey: this.list[i].rebateTypeKey,
          withRebate: this.list[i].estimateRebate,
          expectTreatCost: this.list[i].expectTreatCost,
          expectSuppCost: this.list[i].expectSuppCost,
          brandName: this.list[i].brandName,
          brandSid: this.list[i].brandSid,
          purchaseSystemName: this.list[i].purchaseSystemName,
          purchaseSystemSid: this.list[i].purchaseSystemSid
        })
      }
      this.$emit('backAdd', data_list, this.rebateType, this.purchaseSystemName, this.brandName)
    }
  }
}
</script>
<style scoped>
</style>

