certificateManagement.vue 7.7 KB
<route lang="yaml">
    name: certificateManagement
    </route>

<script lang="ts" setup name="certificateManagement">

import { ref } from 'vue';
import TableTools from "@/components/Tools/table_tools.vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import {
  getRegistDocumentList,
  updateCertificate
} from "@/api/modules/dataAsset";
import useUserStore from "@/store/modules/user";
import useDataAssetStore from "@/store/modules/dataAsset";

const assetStore = useDataAssetStore();

const router = useRouter();
const { proxy } = getCurrentInstance() as any;

const userStore = useUserStore();
const userData = JSON.parse(userStore.userData);

/** 是否时企业端。不是企业端,则是服务端,需要显示企业名称。 */
const isCompanyPlatform = ref(userData.tenantType == 1);

onBeforeMount(() => {
  if (isCompanyPlatform.value) {
    tableInfo.value.fields = tableFields.value;
  } else {
    tableFields.value.splice(4, 0, { label: "企业名称", field: "tenantName", width: 240, align: "left" })
    tableInfo.value.fields = tableFields.value;
  }
})

onActivated(() => {
  if (assetStore.isRefresh) {//如果是首次加载,则不需要调用
    page.value.curr = 1;
    getTableData();
    assetStore.set(false);
  }
});

const searchItemList = ref([
  {
    type: "input",
    label: "",
    field: "daName",
    default: "",
    placeholder: "资产名称",
    clearable: true,
  },
  {
    type: 'select',
    label: '',
    field: 'state',
    default: '',
    placeholder: '全部状态',
    options: [
      { label: '已过期', value: 0 },
      { label: '待制证', value: 1 },
      { label: '待发证', value: 2 },
      { label: '发证中', value: 3 },
      { label: '已发证', value: 4 }
    ],
    clearable: true
  },
  {
    type: 'select',
    label: '',
    field: 'documentType',
    default: '',
    placeholder: '全部类型',
    options: [
      { label: 'A证', value: 1 },
      { label: 'B证', value: 2 },
      { label: 'C证', value: 3 }
    ],
    clearable: true
  },
]);

const toSearch = (val: any, clear: boolean = false) => {
  page.value.curr = 1;
  if (clear) {
    searchItemList.value.map((item) => (item.default = ""));
    page.value.daName = '';
    page.value.state = "";
    page.value.documentType = "";
  } else {
    page.value.daName = val.daName;
    page.value.state = val.state;
    page.value.documentType = val.documentType;
  }
  getTableData();
};

const getTableData = () => {
  tableInfo.value.loading = true;
  getRegistDocumentList({
    pageSize: page.value.limit,
    pageIndex: page.value.curr,
    daName: page.value.daName,
    state: page.value.state,
    documentType: page.value.documentType
  }).then((res: any) => {
    tableInfo.value.loading = false;
    if (res.code == proxy.$passCode) {
      const data = res.data || {};
      tableInfo.value.data = data.records || [];
      tableInfo.value.page.curr = data.pageIndex;
      tableInfo.value.page.rows = data.totalRows || 0;
    } else {
      ElMessage.error(res.msg);
    }
  })
}

const page = ref({
  limit: 50,
  curr: 1,
  sizes: [
    { label: "10", value: 10 },
    { label: "50", value: 50 },
    { label: "100", value: 100 },
    { label: "150", value: 150 },
    { label: "200", value: 200 },
  ],
  daName: '',
  state: '',
  documentType: ''
});

const tableFields = ref([
  { label: "序号", type: "index", width: 56, align: "center" },
  { label: "资产名称", field: "daName", width: 160, align: "left" },
  { label: "资产编码", field: "daCode", width: 160, align: "left" },
  { label: "登记时间", field: "registerTime", width: 120 },
  { label: "有限期", field: "effectiveDate", width: 140 },
  //{ label: "企业名称", field: "tenantName", width: 240, align: "left" },
  { label: "发证主体", field: "issuingEntityName", width: 250, align: "left" },
  {
    label: "类型", field: "documentType", width: 96, align: "left", getName: (scope) => {
      let type = scope.row.documentType;
      return type == 1 ? 'A证' : (type == 2 ? 'B证' : 'C证');
    }
  },
  { label: "状态", field: "state", type: "tag", width: 96, align: 'center' },
]);

const tableInfo = ref({
  id: 'certificate-data-table',
  rowKey: 'guid',
  loading: false,
  fields: tableFields.value,
  data: [],
  page: {
    type: "normal",
    rows: 0,
    ...page.value,
  },
  actionInfo: {
    label: "操作",
    type: "btn",
    width: 120,
    btns: (scope) => {
      let row = scope.row;
      return getTableBtns(row);
    }
  }
});

const getTableBtns = (row) => {
  let btnsArr: any[] = [];
  if (row.state == 3) {
    btnsArr.push({ label: "确认", value: "confirm" })
  }
  btnsArr.push({ label: "详情", value: "path_detail" })
  return btnsArr;
}

const currTableData: any = ref({});

const tableBtnClick = (scope, btn) => {
  const type = btn.value;
  const row = scope.row;
  currTableData.value = row;
  if (type == "confirm") {
    formItems.value[0].default = [];
    dialogInfo.value.visible = true;
  } if (type === 'path_detail') { // 详情
    router.push({
      name: 'certificateDetail',
      query: { guid: row.registerGuid, certificateGuid: row.guid, type: 'certificate', daTenantGuid: row.tenantGuid }
    });
  }
};

const tablePageChange = (info) => {
  page.value.curr = Number(info.curr);
  page.value.limit = Number(info.limit);
  getTableData();
};

const formItems = ref([{
  label: '证件上传',
  tip: '支持扩展名:.jpg .png',
  accept: '.jpg, .png',
  type: 'upload-file',
  placeholder: '请选择',
  field: 'documentFile',
  default: [],
  block: true,
  required: true
}]);

const formRules = ref({
  documentFile: [{
    validator: (rule: any, value: any, callback: any) => {
      if (!value?.length) {
        callback(new Error('请上传证件'))
      } else {
        callback();
      }
    }, trigger: 'change'
  }]
});

const dialogInfo = ref({
  visible: false,
  size: 400,
  direction: "column",
  header: {
    title: "确认发证",
  },
  type: '',
  contents: [
    {
      type: 'form',
      title: '',
      formInfo: {
        id: 'confirm-upload-file',
        items: formItems.value,
        rules: formRules.value
      }
    }
  ],
  footer: {
    btns: [
      { type: "default", label: "取消", value: "cancel" },
      { type: "primary", label: "确定", value: "submit" },
    ],
  },
});

const updatePromise: any = ref(null);

/** 确认发证上传后的确定按钮处理。 */
const dialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    if (updatePromise.value) {
      return;
    }
    updatePromise.value = updateCertificate({
      guid: currTableData.value.guid,
      tenantGuid: userData.tenantGuid,
      daCode: currTableData.value.daCode,
      state: 4,
      documentFile: info.documentFile?.map(f => f.url) || []
    }).then((res: any) => {
      updatePromise.value = null;
      if (res?.code == proxy.$passCode) {
        ElMessage.success('该资产发证确认成功');
        dialogInfo.value.visible = false;
        page.value.curr = 1;
        getTableData();
      } else {
        ElMessage.error(res.msg);
      }
    })
  } else if (btn.value == 'cancel') {
    dialogInfo.value.visible = false;
  }
};

</script>

<template>
  <div class="container_wrap">
    <div class="table_tool_wrap">
      <TableTools :searchItems="searchItemList" :searchId="'register-data-search'" @search="toSearch" :init="true" />
    </div>
    <div class="table_panel_wrap">
      <Table :tableInfo="tableInfo" @tableBtnClick="tableBtnClick" @tablePageChange="tablePageChange" />
    </div>
    <Dialog :dialogInfo="dialogInfo" @btnClick="dialogBtnClick" />
  </div>
</template>

<style scoped lang="scss">
.container_wrap {
  padding: 0 16px;

  .table_panel_wrap {
    height: calc(100% - 44px);
  }
}

:deep(.upload-file) {
  .el-upload__tip {
    margin-left: 0px;
  }
}
</style>