<template>
  <ele-pro-table
    ref="certificateTable"
    :columns="certificateColumns"
    :need-page="false"
    :datasource="tableList"
    :toolkit="[]"
  >
    <!-- 表头工具栏 -->
    <template v-slot:toolbar>
      <el-button
        type="primary"
        v-if="form.approvalStatus==0"
        @click="addCertificate('add', '')"
        >新增</el-button
      >
    </template>
    <!-- 操作栏 -->
    <template v-slot:action="scope">
      <el-link
        v-if="[1, 2].includes(scope.row.processStatus)"
        type="primary"
        :underline="false"
        icon="el-icon-edit"
        @click="addCertificate('view', scope.row)"
      >
        详情
      </el-link>
      <el-link
        v-if="(isNeed_process_is_close&&[0, 3].includes(scope.row.processStatus))||!isNeed_process_is_close"
        type="primary"
        :underline="false"
        icon="el-icon-edit"
        @click="addCertificate('update', scope.row)"
      >
        修改
      </el-link>

      <el-link
        v-if="isNeed_process_is_close&&[0, 3].includes(scope.row.processStatus)"
        type="primary"
        :underline="false"
        icon="el-icon-plus"
        @click="submit(scope.row)"
      >
        提交
      </el-link>

      <el-popconfirm
        class="ele-action"
        title="确定要删除此资质吗？"
        @confirm="handleRemove(scope.row)"
      >
        <template v-slot:reference>
          <el-link
            v-if="(isNeed_process_is_close&&[0, 3].includes(scope.row.processStatus))||!isNeed_process_is_close"
            type="danger"
            :underline="false"
            icon="el-icon-delete"
          >
            删除
          </el-link>
        </template>
      </el-popconfirm>
    </template>
    <!-- 资质证书弹窗   -->
    <certificate-qualifications-dialog
      :certificate-qualifications-dialog-flag.sync="
        certificateQualificationsDialogFlag
      "
      v-if="certificateQualificationsDialogFlag"
      ref="certificateQualificationsDialogRef"
      typeInfo="1"
      :contactInfo="form"
      @reload="init(form)"
    >
    </certificate-qualifications-dialog>
    <process-submit-dialog :processSubmitDialogFlag.sync="processSubmitDialogFlag" v-if="processSubmitDialogFlag" ref="processSubmitDialogRef" @reload="reload"></process-submit-dialog>

  </ele-pro-table>
</template>

<script>
import certificateQualificationsDialog from '@/views/purchasingManage/supplierManage/components/certificateQualificationsDialog.vue';
import {
  contactQcPackDeleteAPI,
  contactQcSubmit,
  contactQcPackPageAPI
} from '@/api/saleManage/contact';
import {reviewStatus} from "@/enum/dict";

import dictMixins from '@/mixins/dictMixins';
import processSubmitDialog from "@/BIZComponents/processSubmitDialog/processSubmitDialog.vue";
export default {
  mixins: [dictMixins],
  components: {processSubmitDialog, certificateQualificationsDialog },
  data() {
    return {
      tableList: [],
      form: {},
      certificateColumns: [
        {
          type: 'index',
          width: 55,
          align: 'center'
        },
        {
          label: '编码',
          prop: 'code',
          slot: 'code',
          align: 'center',
          minWidth: 120
        },
        {
          label: '名称',
          prop: 'name',
          slot: 'name',
          align: 'center',
          minWidth: 120
        },

        {
          label: '创建时间',
          prop: 'createTime',
          slot: 'createTime',
          align: 'center',
          minWidth: 120
        },
        {
          label: '状态',
          prop: 'processStatus',
          slot: 'processStatus',
          align: 'center',
          width: 120,
          formatter: (_row, _column, cellValue) => {
            return reviewStatus[_row.processStatus];
          }
        },
        {
          label: '备注',
          prop: 'remark',
          slot: 'remark',
          align: 'center',
          minWidth: 120
        },
        {
          action: 'action',
          slot: 'action',
          label: '操作',
          align: 'center',
          width: 200
        }
      ],
      certificateQualificationsDialogFlag: false,
      processSubmitDialogFlag: false,
    };
  },
  methods: {
    async init(row) {
      this.form = row;
      const data = await contactQcPackPageAPI({
        certificationType: '1',
        relationId: row.id
      });
      this.tableList=data
    },

    //删除资质包
    handleRemove(row) {
      contactQcPackDeleteAPI([row.id]).then((res) => {
        this.$message.success('删除成功！');
        this.reload();
      });
    },
    //新增/查看/修改资质
    addCertificate(type, row) {
      this.certificateQualificationsDialogFlag = true;
      this.$nextTick(() => {
        this.$refs.certificateQualificationsDialogRef.init(type, row);
      });
    },
    //开启资质提交流程
    async submit(row) {
      // await contactQcSubmit({ businessId: row.id, certificationType: 1 });
      this.processSubmitDialogFlag = true
      this.$nextTick(()=>{
        let params = {
          businessId: row.id,
          businessKey : 'contact_qc_approve',
          formCreateUserId: row.createUserId,
          variables:{
            certificationType: 1
          },
          // callBackMethodType : '1',
          // callBackMethod : 'proTargetPlanApproveApiImpl.updatePlanApprovalStatus',
          // pcHandle : '/bpm/handleTask/components/project-manage/plan-manage/submit.vue',
          // pcView : '/bpm/handleTask/components/project-manage/plan-manage/detailDialog.vue',
          // miniHandle : '',
          // miniView : '',
        }
        this.$refs.processSubmitDialogRef.init(params)
      })

    },
    reload(){
      this.init(this.form);
    }
  }
};
</script>
