<template>
  <div class="table-wrap">
    <el-table :data="tableData" ref="tableRef"
        @cell-dblclick="cellDblclick"
        @select="select"
        highlight-current-row
        size="mini" stripe border  >
      <el-table-column type="index" label="序号"  width="60" show-overflow-tooltip>
      </el-table-column>

      <el-table-column v-for="(item, index) in colunms" :key="index"
            :prop="item.prop"
            :label="item.label"
            :fixed="item.fixed"
            :class-name="item.prop =='statusKey'?'c357F':'' "
            :show-overflow-tooltip="item.tooltip"
            :min-width="item.width"
            >
      </el-table-column>

      <el-table-column v-if=" projectStatus ==='draft'|| projectStatus ==='auditing' || projectStatus ==='audited'|| projectStatus ==='filed' "
          label="操作" min-width="150"  fixed="right">
        <template slot-scope="scope" >
          <el-button  @click="handleDetail(scope.row)" type="text">详情</el-button>
          <el-button v-if="scope.row.status ==='draft' " @click="handleEdit(scope.row)" type="text">编辑</el-button>
          <el-button v-if="scope.row.status ==='draft' " @click="handleDelete(scope.row)" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <dig-task-list ref="dialogTaskRef"
            @callback="doQuery"
            :hideedit="projectStatus !=='draft'?true:false"
            :preservationData="true"
            :modelId="3101"
            :cusdisabled="true"
            :p-code-enble="true"  >
    </dig-task-list>
  </div>
</template>

<script>


  export default {
    name: 'task-table',
    components:{

    },
    created() {
      this.doQuery();
    },
    mounted() {

    },
    methods: {
      // 查询数据
      doQuery () {

         let param = {
             relevance: this.projectid,
             moduleId: 3101,
         };

         this.$ajax.post({
           domain: 'crmUrl',
           url: 'task.listWorkCiteTaskInfo',
           data: param,
           requestType: 'body',
           showLoad: true,
           success: function (res) {
             if (res.errorCode === 200) {
                 this.tableData = res.data || [];
             }
           }.bind(this),
           error: function (res) {
             this.$message({
               type: 'error',
               message: res.body.msg || res.msg
             })
           }.bind(this)
         })
      },
      //新建
      newTask(){
        this.$refs.dialogTaskRef.visible = true;
        this.$refs.dialogTaskRef.openTitle = '新增';
        this.$refs.dialogTaskRef.paramForm.extId = this.projectid;
        this.$refs.dialogTaskRef.paramForm.customerName = this.customer;
        this.$refs.dialogTaskRef.paramForm.customerId = this.customerId;
        let data = {
          projectCode: this.projectCode,
          id: this.projectid,
        }
        this.$refs.dialogTaskRef.paramrow(data);
      },
      //编辑
      handleEdit(row){
        this.$refs.dialogTaskRef.visible = true;
        this.$refs.dialogTaskRef.openTitle = '编辑';
        this.$refs.dialogTaskRef.editDetail(row);
      },
      cellDblclick(row, column, cell, event){
        this.handleDetail(row);
      },
      //详情
      handleDetail(row){
       this.$router.push({
         path: 'taskDetail',
         query: {
           rowData: row.id,
           projectId: this.projectid
         }
       });
      },
      select(selection, row){
          if(row.status !== "draft"){
            this.$message('只有草稿状态允许删除');
            this.$refs.tableRef.toggleRowSelection(row, false);
          }
      },
      //删除
      handleDelete (row){
          this.$confirm('确定删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

             this.$ajax.post({
               domain: 'crmUrl',
               url: 'task.deleteTasks',
               data: [row.id],
               requestType: 'body',
               showLoad: true,
               success: function (res) {
                 if (res.errorCode === 200) {
                    this.$message({
                      type: 'success',
                      message: '删除成功'
                   })
                   this.doQuery();
                 }
               }.bind(this),
               error: function (res) {
                 this.$message({
                   type: 'error',
                   message: res.body.msg || res.msg
                 })
               }.bind(this)
             })
          }).catch(() => { });
      },
    },
    props:['projectid', 'projectStatus', 'customer', 'customerId', 'projectCode'],
    data() {
      return {

        tableData: [],

        //表格列
        colunms: [
           { prop: 'taskId', label: '任务ID',   width: 100, fixed: false,  tooltip: true },
           { prop: 'taskSourceKey', label: '任务来源',   width: 100, fixed: false,  tooltip: true },
           { prop: 'customerName', label: '客户',   width: 100, fixed: false,  tooltip: true },
           { prop: 'itemTypeKey', label: '事项类型',   width: 100, fixed: false,  tooltip: true },
           { prop: 'taskContent', label: '事项简述',   width: 100, fixed: false,  tooltip: true },
           { prop: 'taskUser', label: '责任人',   width: 100, fixed: false,  tooltip: true },
           { prop: 'userNamesStr', label: '协同人员',   width: 100, fixed: false,  tooltip: true },
           { prop: 'emergencyDegreeKey', label: '紧要程度',   width: 100, fixed: false,  tooltip: true },
           { prop: 'statusKey', label: '状态',   width: 120, fixed: false,  tooltip: true },
           { prop: 'taskRequestDate', label: '要求时间',   width: 120, fixed: false,  tooltip: true },
           { prop: 'visitReportCode', label: '关联拜访报告',   width: 120, fixed: false,  tooltip: true },
           { prop: 'projectCode', label: '关联项目',   width: 120, fixed: false,  tooltip: true },

        ],

      }
    },

  }
</script>

<style>

</style>
