<template>
  <div>
    <el-table :data="data" border stripe>
      <el-table-column label="任务单号" prop="id"></el-table-column>
      <el-table-column label="任务标题" prop="title"></el-table-column>

      <el-table-column label="预算金额">
        <template slot-scope="{ row }">
          <span class="text-blue"> ￥{{ row.budget_fee / 100 }} </span>
        </template>
      </el-table-column>

      <el-table-column label="任务分类" prop="category"></el-table-column>

      <el-table-column label="发布企业" prop="company"></el-table-column>

      <el-table-column label="接单人" prop="maker"></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <el-button type="text" v-if="!row.confirm" @click="confirmTask(row)">
            审核
          </el-button>
          <el-button
            type="text"
            v-if="row.confirm == 0 && row.maker_id > 0"
            @click="deleteTaskMaker(row)"
          >
            驳回
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="审核任务" :visible.sync="confirm" center style="margin:0 auto">
      <el-form :model="info" ref="finish"  style="width:400px;margin:0 auto;">
        <el-form-item label="实际费用" label-width="120px" prop="fee">
          <el-input  v-model="info.fee"  class="w230" type="number">
            <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 showImg from "@/components/customPic/showImg.vue";
import { confirmTask,deleteTaskMaker } from "@/api/task";

export default {
  name: "Api",
  components: { showImg },
  data() {
    return {
      confirm: false,
      info:{fee:0},
      imgsVisible: false,
      errorImg: 'this.src="' + require("@/assets/null60.jpg") + '"',
    };
  },
  props: {
    data: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  methods: {
    confirmTask( row ){
      this.info.id = row.id;
      this.info.fee = (row.fee ||row.budget_fee)/100;
      this.info.company_id = row.company_id;
      this.confirm = true
      this.info.temp = row;
    },
    deleteTaskMaker( row ){
      let param = {id:row.id}
      deleteTaskMaker( param).then(res=>{
        if(res.code == 200){
          this.$message.successMsg("驳回成功", 1);
          row.maker_id=0
          row.maker=""
        }
      })
    },
    doConfirm(  ){
      let {id, fee, company_id, temp} = this.info
      fee= parseInt( fee *100 )
      confirmTask( {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>