qualityEvaluate.vue 19 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
<route lang="yaml">
  name: qualityEvaluate
  </route>

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

import { ref } from 'vue';
import TableTools from "@/components/Tools/table_tools.vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import {
  getQualityEvaList,
  getRegisteredList,
  saveQuality,
  registerApproveCancel,
  registerApproveBackup,
  qualityAllow,
  deleteQuality,
  updatQuality
} from "@/api/modules/dataAsset";
import useUserStore from "@/store/modules/user";
import {
  getTenantAttach
} from "@/api/modules/queryService";
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);

/** 数据来源于该企业申请登记的数据资产已通过且剔除数据质量评价中已通过、审批中的资产。 */
const assetListData: any = ref([]);
/** 会员附件模板 */
const attachDataInfo: any = ref({});

const tableFields = ref([
  { label: "序号", type: "index", width: 56, align: "center" },
  { label: "资产名称", field: "daName", width: 160, align: "left" },
  { label: "登记时间", field: "registerTime", width: 120 },
  //   { label: "企业名称", field: "tenantName", width: 240, align: "left" },
  { label: "发证主体", field: "issuingEntityName", width: 250, align: "left" },
  { label: "状态", field: "approveState", type: "tag", width: 96, align: 'center' },
]);

onBeforeMount(() => {
  if (isCompanyPlatform.value) {
    tableInfo.value.fields = tableFields.value;
  } else {
    tableFields.value.splice(3, 0, { label: "企业名称", field: "tenantName", width: 250, align: "left" })
    tableInfo.value.fields = tableFields.value;
  }
  getTenantAttach(userData.tenantGuid).then((res: any) => {
    if (res?.code == proxy.$passCode) {
      attachDataInfo.value = res.data || {};
      formItems.value[1].templateUrl = attachDataInfo.value.quality_evaluation_file;
    } else {
      ElMessage.error(res.msg);
    }
  })
});

onActivated(() => {
  getRegisteredList(1).then((res: any) => {
    if (res.code == proxy.$passCode) {
      assetListData.value = res.data || [];
      formItems.value[0].options = assetListData.value;
    } else {
      ElMessage.error(res.msg);
    }
  })
  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: 'approveState',
    default: '',
    placeholder: '全部状态',
    options: [
      { label: '审批中', value: 'A' },
      { label: '已通过', value: 'Y' },
      { label: '已驳回', value: 'R' },
      { label: '已撤销', value: 'C' }
    ],
    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.approveState = "";
  } else {
    page.value.daName = val.daName;
    page.value.approveState = val.approveState;
  }
  getTableData();
};

const getTableData = () => {
  tableInfo.value.loading = true;
  getQualityEvaList({
    pageSize: page.value.limit,
    pageIndex: page.value.curr,
    daName: page.value.daName,
    approveState: page.value.approveState
  }).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 handleCreate = () => {
  if (!assetListData.value.length) {
    ElMessage.warning('当前没有可发起质量评价的资产!');
    return;
  }
  formItems.value[0].visible = true;
  formItems.value[0].default = '';
  formItems.value[1].visible = true;
  formItems.value[1].default = [];
  dialogInfo.value.visible = true;
  dialogInfo.value.type = '';
}

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: '',
  approveState: ''
});

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

const getTableBtns = (row) => {
  let btnsArr: any[] = [];
  if (row.approveState == 'A') {//审批中
    btnsArr.push({ label: "详情", value: "path_detail" })
    if (row.tenantGuid == userData.tenantGuid) {
      btnsArr.push({ label: "撤销", value: "revoke" });
    }
    if (row.approveTenantGuids?.includes(userData.tenantGuid)) {
      btnsArr.push({ label: "通过", value: "pass" });
      btnsArr.push({ label: "驳回", value: "backup" });
    }
  } else if (row.approveState == 'Y') {//已通过的不能删除。
    btnsArr.push({ label: "详情", value: "path_detail" })
  } else if (row.approveState == 'R' || row.approveState == 'C') {//已驳回或已撤销
    btnsArr.push({ label: "详情", value: "path_detail" });
    if (row.tenantGuid == userData.tenantGuid) {
      btnsArr.push({ label: "重新提交", value: "edit", disabled: false })
    }
    if (row.tenantGuid == userData.tenantGuid) {
      btnsArr.push({ label: "删除", value: "delete" });
    }
  }
  return btnsArr;
}

const currTableData: any = ref({});

const tableBtnClick = (scope, btn) => {
  const type = btn.value;
  const row = scope.row;
  currTableData.value = row;
  if (type == "edit") {
    dialogInfo.value.visible = true;
    dialogInfo.value.type = 'reSubmit';
    formItems.value[0].visible = false;
    formItems.value[0].default = row.registerGuid;
    formItems.value[1].default = row.qualityEvaluationFile || [];
  } else if (type == "delete") {
    delTableOpen("此操作将永久删除该资产质量评价,是否继续?", "warning");
  } else if (type === 'backup') {
    rejectDialogInfo.value.visible = true;
  } else if (type === 'pass') {
    passDialogInfo.value.visible = true;
    if (row.dataStartDate) {
      passFormItems.value[1].disabled = true;
      passFormItems.value[1].default = [row.dataStartDate, row.dataEndDate];
    } else {
      passFormItems.value[1].disabled = false;
      passFormItems.value[1].default = null;
    }
    passFormItems.value[2].placeholder = `本次评估数据资产总体质量得分为**分\n准确性:\n一致性:\n可访问性:\n规范性:\n完整性:`;
  } else if (type === 'revoke') { // 撤销,状态为审批中时可以撤销。
    ElMessageBox.confirm('确定撤销该资产质量评价吗?', "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: 'warning',
    }).then(() => {
      let params = {
        bizGuid: row.guid,
        funcCode: row.funcCode
      }
      tableInfo.value.loading = true;
      registerApproveCancel(params).then((res: any) => {
        tableInfo.value.loading = false;
        if (res?.code == proxy.$passCode) {
          if (res.data) {
            ElMessage.success('该资产质量评价流程撤销成功!');
            getTableData();
          } else {
            ElMessage.error('该资产质量评价流程撤销失败!');
          }
        } else {
          ElMessage.error(res.msg);
        }
      });
    }).catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消撤销'
      });
    });
  } else if (type === 'path_detail') { // 详情
    router.push({
      name: 'registerDetail',
      query: { guid: row.registerGuid, evaGuid: row.guid, type: 'qualityEvaluate', daTenantGuid: row.tenantGuid }
    });
  }
};

const delTableOpen = (msg, type, isBatch: boolean = false) => {
  ElMessageBox.confirm(msg, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: type,
  }).then(() => {
    let guids: any = [];
    guids = [currTableData.value.guid]
    deleteQuality(guids).then((res: any) => {
      if (res.code == proxy.$passCode) {
        page.value.curr = 1;
        getTableData();
        ElMessage({
          type: "success",
          message: "删除资产质量评价成功",
        });
      } else {
        ElMessage({
          type: "error",
          message: res.msg,
        });
      }
    })
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消删除'
    });
  });
};

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

const formItems = ref([{
  label: '资产名称',
  type: 'select',
  placeholder: '请选择',
  field: 'registerGuid',
  default: '',
  block: true,
  options: assetListData.value,
  props: {
    value: 'guid',
    label: 'daName'
  },
  visible: true,
  required: true
}, {
  label: '附件上传',
  tip: '支持格式:xls .xlsx .doc .docx .rar .zip',
  type: 'upload-file',
  accept: '.xls, .xlsx, .doc, .docx, .rar, .zip',
  templateUrl: null,
  required: true,
  block: true,
  visible: true,
  default: [],
  field: 'qualityEvaluationFile',
}]);

const formRules = ref({
  registerGuid: [
    { required: true, trigger: 'change', message: "请填写资产名称" }
  ],
  qualityEvaluationFile: [{
    validator: (rule: any, value: any, callback: any) => {
      if (!value?.length) {
        callback(new Error('请上传数据质量评价附件'))
      } else {
        callback();
      }
    }, trigger: 'change'
  }],
});

const dialogInfo = ref({
  visible: false,
  size: 510,
  direction: "column",
  header: {
    title: "质量评价发起",
  },
  type: '',
  contents: [
    {
      type: 'form',
      title: '',
      formInfo: {
        id: 'quality-start-level',
        items: formItems.value,
        rules: formRules.value
      }
    }
  ],
  footer: {
    btns: [
      { type: "default", label: "取消", value: "cancel" },
      { type: "primary", label: "确定", value: "submit" },
    ],
  },
});

const savePromise: any = ref(null);
const reSubmitPromise: any = ref(null);

/** 编辑质量评价发起资产申请按钮处理。 */
const dialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    if (dialogInfo.value.type == 'reSubmit') {
      if (reSubmitPromise.value) {
        return;
      }
      reSubmitPromise.value = updatQuality({
        guid: currTableData.value.guid,
        tenantGuid: userData.tenantGuid,
        registerGuid: currTableData.value.registerGuid,
        daName: currTableData.value.daName,
        registerTime: currTableData.value.registerTime,
        issuingEntityGuid: currTableData.value.issuingEntityGuid,
        qualityEvaluationFile: info.qualityEvaluationFile?.map(f => f.url) || []
      }).then((res: any) => {
        reSubmitPromise.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 (savePromise.value) {
        return;
      }
      let daInfo = assetListData.value.find(a => a.guid == info.registerGuid);
      savePromise.value = saveQuality({
        tenantGuid: userData.tenantGuid,
        registerGuid: info.registerGuid,
        daName: daInfo.daName,
        registerTime: daInfo.registerTime,
        issuingEntityGuid: daInfo.exchangeGuid,
        qualityEvaluationFile: info.qualityEvaluationFile?.map(f => f.url) || []
      }).then((res: any) => {
        savePromise.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;
  }
};

const passFormItems = ref([
  {
    label: '质量得分',
    type: 'input',
    inputType: 'scoreNumber',
    placeholder: '请输入数值',
    field: 'qualityScore',
    default: null,
    min: 0,
    max: 100,
    required: true
  },
  {
    label: "评价对象范围",
    type: "date-picker",
    field: "evaluationRange",
    default: null,
    placeholder: "开始时间~结束时间",
    clearable: true,
    required: true,
  },
  {
    label: '质量评价说明',
    type: 'textarea',
    field: 'evaluationNote',
    focusValue: true,
    example: '示例:本次评估数据资产总体质量得分为99.80分。从评价维度分析,准确性、一致性和可访问性均为 100 分;规范性 99.42 分、完整性 99.50分。',
    placeholder: `本次评估数据资产总体质量得分为**分\n准确性:\n一致性:\n可访问性:\n规范性:\n完整性:`,
    default: '',
    rows: 6,
    clearable: true,
    required: true,
    block: true,
  },
  {
    label: '质量评价报告',
    tip: '支持扩展名:PDF',
    type: 'upload-file',
    required: true,
    limit: 1,
    block: true,
    accept: '.pdf',
    default: [],
    field: 'evaluationFile',
  }
]);

const passFormRules = ref({
  qualityScore: [{
    validator: (rule: any, value: any, callback: any) => {
      if (value === 0) {
        callback();
        return;
      }
      if (!value) {
        callback(new Error('请填写质量得分'));
        return;
      }
      //TODO 请填写1~100以内的整数
      // const r = /(^[0-9]([0-9]*)$|^[0-9]$)/; // 正整数(可以以0打头)
      // if (value && !r.test(value)) {
      //   callback(new Error('请填写大于或等于零整数'));
      //   return;
      // }
      // if ((value + '').length > 6) {
      //   callback(new Error('请填写1~100以内的整数'));
      //   return;
      // }
      callback();
    },
    trigger: "blur",
  }],
  evaluationRange: [{
    type: 'array', required: true, message: '请填写评价对象范围', trigger: 'change',
  }],
  evaluationNote: [{
    validator: (rule: any, value: any, callback: any) => {
      if (!value) {
        callback(new Error('请填写质量评价说明'));
        return;
      }
      if (value && value.length > 500) {
        callback(new Error('请填写小于500个字的质量评价说明'));
        return;
      }
      callback();
    },
    trigger: "blur",
  }],
  evaluationFile: [{
    validator: (rule: any, value: any, callback: any) => {
      if (!value?.length) {
        callback(new Error('请上传质量评价报告'));
        return;
      }
      callback();
    },
    trigger: "blur",
  }]
});

const passDialogInfo = ref({
  visible: false,
  size: 700,
  direction: "column",
  header: {
    title: "通过",
  },
  type: '',
  contents: [
    {
      type: 'form',
      title: '',
      formInfo: {
        id: 'quality-pass-dialog',
        items: passFormItems.value,
        rules: passFormRules.value
      }
    }
  ],
  footer: {
    btns: [
      { type: "default", label: "取消", value: "cancel" },
      { type: "primary", label: "确定", value: "submit" },
    ],
  },
});

const passDialogInputChange = (val, item) => {
  if (item.field == 'qualityScore') {
    passFormItems.value[2].placeholder = `本次评估数据资产总体质量得分为${val}分\n准确性:\n一致性:\n可访问性:\n规范性:\n完整性:`;
  }
}

const passDialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    qualityAllow({
      guid: currTableData.value.guid,
      qualityScore: info.qualityScore,
      evaluationRangeStart: info.evaluationRange[0],
      evaluationRangeEnd: info.evaluationRange[1],
      evaluationNote: info.evaluationNote,
      evaluationFile: info.evaluationFile.map(f => f.url),
    }).then((res: any) => {
      if (res?.code == proxy.$passCode) {
        if (res.data) {
          ElMessage.success('审批成功');
          passDialogInfo.value.visible = false;
          getTableData();
        } else {
          ElMessage.error('审批失败');
        }
      } else {
        ElMessage.error(res.msg);
      }
    })
  } else if (btn.value == 'cancel') {
    passDialogInfo.value.visible = false;
  }
};

const rejectDialogInfo = ref({
  visible: false,
  size: 460,
  direction: "column",
  header: {
    title: "驳回",
  },
  type: '',
  contents: [
    {
      type: 'form',
      title: '',
      formInfo: {
        id: 'batch-reject-form',
        items: [
          {
            label: '',
            type: "textarea",
            placeholder: "请填写驳回理由(必填)",
            field: "approveSuggest",
            clearable: true,
            block: true,
            col: 'margin_b_0',
          }
        ]
      }
    }
  ],
  footer: {
    btns: [
      { type: "default", label: "取消", value: "cancel" },
      { type: "primary", label: "确定", value: "submit" },
    ],
  },
});

const rejectDialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    if (info.approveSuggest == '') {
      ElMessage.error('请填写驳回理由');
      return
    }
    tableInfo.value.loading = true;
    let params = {
      bizGuid: currTableData.value.guid,
      funcCode: currTableData.value.funcCode,
      approveSuggest: info.approveSuggest
    }
    registerApproveBackup(params).then((res: any) => {
      tableInfo.value.loading = false;
      if (res?.code == proxy.$passCode) {
        if (res.data) {
          ElMessage.success('驳回成功');
          getTableData();
          rejectDialogInfo.value.visible = false;
        } else {
          ElMessage.error('驳回失败');
        }
      } else {
        ElMessage.error(res.msg);
      }
    });
  } else if (btn.value == 'cancel') {
    rejectDialogInfo.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 class="tools_btns">
        <el-button type="primary" @click="handleCreate">质量评价发起</el-button>
      </div>
    </div>
    <div class="table_panel_wrap">
      <Table :tableInfo="tableInfo" @tableBtnClick="tableBtnClick" @tablePageChange="tablePageChange" />
    </div>
    <Dialog :dialogInfo="dialogInfo" @btnClick="dialogBtnClick" />
    <Dialog :dialogInfo="passDialogInfo" @btnClick="passDialogBtnClick" @inputChange=passDialogInputChange  />
    <Dialog :dialogInfo="rejectDialogInfo" @btnClick="rejectDialogBtnClick" />
  </div>
</template>

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