<template>
  <ele-pro-table
    ref="table"
    :columns="columns"
    :datasource="tableList"
    class="dict-table"
    tool-class="ele-toolbar-form"
    :need-page="false"
  >
    <addDialog ref="addDialogRef" @success="reload" />
    <detailDialog ref="detailDialogRef" />
    <!-- 工具栏 -->
    <template v-slot:toolbar>
      <el-button
        type="primary"
        icon="el-icon-plus"
        @click="handleUpload('add')"
        v-if="holderData.holderId"
        >添加</el-button
      >
      <!-- <el-button type="primary" @click="handleUpload">导入</el-button> -->
    </template>
    <template v-slot:code="{ row }">
      <el-link type="primary" :underline="false" @click="openDetail(row)">{{
        row.code
      }}</el-link>

      <p class="ele-text-info">
        {{ getDictValue('客户/供应商资质类型', row.type) }}
      </p>
    </template>
    <template v-slot:time="{ row }">
      <p>起：{{ row.validityStartTime }}</p>
      <p class="ele-text-info">止：{{ row.validityEndTime }}</p>
    </template>
    <template v-slot:createUser="{ row }">
      <p>{{ row.createUserName }}</p>
      <p>{{ row.createUserDeptName }}</p>
      <p class="ele-text-info">{{ row.createTime }}</p>
    </template>
    <template v-slot:picture="{ row }">
      <fileMain v-model="row.fileObj" type="view"></fileMain>
    </template>
    <template v-slot:action="{ row }">
      <el-link
        type="primary"
        :underline="false"
        icon="el-icon-edit"
        @click="handleUpload('edit',row)"
        v-if="[0, 3].includes(row.approvalStatus)"
      >
        修改
      </el-link>
      <el-link
        type="primary"
        :underline="false"
        icon="el-icon-edit"
        @click="submit(row)"
        v-if="[0, 3].includes(row.approvalStatus)"
      >
        提交
      </el-link>
      <el-popconfirm
        class="ele-action"
        title="确定要删除此信息吗？"
        @confirm="remove([row.id])"
        v-if="[0, 3].includes(row.approvalStatus)"
      >
        <template v-slot:reference>
          <el-link type="danger" :underline="false" icon="el-icon-delete">
            删除
          </el-link>
        </template>
      </el-popconfirm>
    </template>
    <process-submit-dialog
      api-fun-name="purchaseinquiryStatusAPI"
      :processSubmitDialogFlag.sync="processSubmitDialogFlag"
      v-if="processSubmitDialogFlag"
      ref="processSubmitDialogRef"
      @reload="reload"

    ></process-submit-dialog>
  </ele-pro-table>
</template>

<script>
  import addDialog from './components/add-dialog.vue';
  import detailDialog from './components/detail-dialog.vue';
  import {
    identityphotoList,
    deleteIdentityphoto
  } from '@/api/saleManage/contact';
  import dictMixins from '@/mixins/dictMixins';
  import { holderTypeOptions } from '@/enum/dict.js';
  // import fileMain from '@/components/addDoc/index.vue';
  import { reviewStatus } from '@/enum/dict';
  import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';

  export default {
    mixins: [dictMixins],
    components: { addDialog, detailDialog,
      //  fileMain,
       processSubmitDialog },
    data() {
      return {
        processSubmitDialogFlag:false,

        tableList: [],
        columns: [
          {
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center'
          },
          {
            label: '持证类型',
            align: 'center',
            prop: 'holderType',
            formatter: (row) => {
              return holderTypeOptions.find(
                (item) => item.value == row.holderType
              )?.label;
            },
            width: 150
          },
          {
            align: 'center',
            label: '证照编号',
            prop: 'code',
            slot: 'code',
            width: 180
          },
          {
            label: '状态',
            align: 'center',
            prop: 'status',
            formatter: (row) => {
              return this.getDictValue('规则状态', row.status);
            }
          },
          {
            label: '执证对象',
            align: 'center',
            prop: 'holder'
          },
          {
            align: 'center',
            label: '有效期限',
            prop: 'time',
            slot: 'time',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            label: '创建人信息',
            align: 'center',
            prop: 'createUser',
            slot: 'createUser',
            minWidth: '200',
            showOverflowTooltip: true
          },
          {
            label: '证照',
            align: 'center',
            prop: 'picture',
            slot: 'picture'
          },
          {
            label: '备注',
            align: 'center',
            prop: 'remark',
            minWidth: '100',
            showOverflowTooltip: true
          },
          {
            label: '审核状态',
            prop: 'approvalStatus',
            align: 'center',
            width: 120,
            formatter: (_row, _column, cellValue) => {
              return reviewStatus[_row.approvalStatus];
            }
          },
          {
            columnKey: 'action',
            label: '操作',
            align: 'center',
            width: 200,
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        holderData: {
          holderId: '',
          holder: '',
          holderType: ''
        }
      };
    },
    created() {
      this.requestDict('客户/供应商资质类型');
      this.requestDict('规则状态');
    },
    methods: {
      init(holderType, holderId, holder) {
        this.holderData = { holderId, holder, holderType };
        this.getTable();
      },
      async submit(row) {
        this.processSubmitDialogFlag = true;

        this.$nextTick(() => {
          let params = {
            businessId: row.id,
            businessKey:
              row.holderType == 1
                ? 'profession_person_approve'
                : row.holderType == 4
                ? 'contact_qc_approve'
                : 'supplier_qc_approve',
            formCreateUserId: row.createUserId,
            variables: {
              businessCode: row.code,
              businessName: row.holder,
              businessType:
                row.holderType == 1
                  ? this.getDictValue('证件类型', row.type)
                  : this.getDictValue('客户/供应商资质类型', row.type)
            }
          };
          this.$refs.processSubmitDialogRef.init(params);
        });
      },
      getTable() {
        identityphotoList({
          holderType: this.holderData.holderType,
          holderId: this.holderData.holderId
        }).then((res) => {
          this.tableList = res;
        });
      },
      reload(data) {
        if (data) {
          this.tableList.push(data);
        } else {
          this.getTable();
        }
      },
      handleUpload(type, row) {
        this.$refs.addDialogRef.open(row, type, this.holderData);
      },

      //删除接口
      remove(delData) {
        deleteIdentityphoto(delData).then((res) => {
          this.$message.success('删除成功！');
          this.reload();
        });
      },
      openDetail(row) {
        this.$refs.detailDialogRef.open(row);
      }
    }
  };
</script>

<style class=""></style>
