<template>
  <div>
    <el-table :data="data" border stripe>
      <el-table-column label="序号"  prop="id"></el-table-column>
      <el-table-column
        label="企业名称"
        prop="company"
      ></el-table-column>
      <el-table-column
        label="产品名称"
        prop="product"
      ></el-table-column>
      <el-table-column
        label="产品数量"
        prop="amount"
      ></el-table-column>
      <el-table-column label="交易金额"  prop="fee">
        <template slot-scope="{ row }">
          <span>{{ row.fee | toFee }}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务员"  prop="saleman">
        <template slot-scope="{ row }">
          <span>{{ row.saleman || "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="关联企业"
        min-width="150"
        prop="target"
      ></el-table-column>
      <el-table-column label="日期"  prop="created_at">
        <template slot-scope="{ row }">
          <span>{{ row.bid_end_at | toDate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row}">
        <el-button 
          @click="confirmB2B(row)"
          size="small"
          type="primary"
          v-if="!row.confirm">
          审核
        </el-button>
      </template>
      
      </el-table-column>
      
    </el-table>

    <el-dialog title="审核任务" :visible.sync="confirm" center style="margin:0 auto">
      <el-form :model="info" style="width:400px;margin:0 auto;">
        <el-form-item label="实际费用" label-width="120px">
          <el-input  v-model="info.fee" type="number" class="w230">
            <template slot="append"> 元</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="confirm = false">取消 </el-button>
        <el-button type="primary" @click="doConfirm" class="pr20 pl20">
          确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { toDatetime, toDate } from "@/utils/date";
import {toFee} from '@/utils/stringFun'
import {confirmB2B} from "@/api/task";
export default {
  name: "Api",
  filters: { toDate, toDatetime,toFee },
  data() {
    return {
      info:{},
	    confirm: false,
      imgsVisible: false,
      errorImg: 'this.src="' + require("@/assets/null60.jpg") + '"',
    };
  },
  props: {
    data: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  methods: {
    confirmB2B( row ){
      this.info.id = row.id;
      this.info.fee = row.fee/100;
      this.info.company_id = row.company_id;
      this.confirm = true
      this.info.temp = row;
    },
    doConfirm(  ){
      let {id, fee, company_id, temp} = this.info
      confirmB2B( {id, fee, company_id} ).then(res=>{
          if(res.code == 200){
            temp.confirm = 1;
            this.confirm = false
            this.$message.successMsg("审核通过")
          }
        })
    }
  },
};
</script>
<style scoped lang="scss">
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
.el-tag--mini {
  margin-left: 5px;
}
.warning {
  color: #dc143c;
}
</style>