qualityEvaluate.vue 28.6 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 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
<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,
  qualityAllow,
  deleteQuality,
  updatQuality,
  getTenantList
} from "@/api/modules/dataAsset";
import useUserStore from "@/store/modules/user";
import useDataAssetStore from "@/store/modules/dataAsset";
import {
  getStaffDetailInfo
} from "@/api/modules/queryService";
import { isNeedApprove, rejectFlowData, revokeFlowData, getCamundaDeploymentId, getProcessNodesPromise, isMyFirstNode, passFlowData } from "@/api/modules/workFlowService";

const assetStore = useDataAssetStore();

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

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

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

const tableFields = ref([
  { label: "序号", type: "index", width: 56, align: "center" },
  { label: "资产名称", field: "daName", width: 160, align: "left", type: 'text_btn', value: 'productDetail', columClass: 'text_btn' },
  { label: "登记时间", field: "registerTime", width: 120 },
  //   { label: "企业名称", field: "tenantName", width: 240, align: "left" },
  { label: "评估机构", field: "evaluationAgencyName", width: 250, align: "left" },
  { label: "审批状态", field: "approveVO", type: "approveTag", enableNoApprove: true, width: 96, align: 'center' },
  { label: "专区名称", field: "zqName", width: 160, align: "left" },
]);

const deploymentId = ref('');

const tenantList: any = ref([]);

onBeforeMount(() => {
  getTenantList({
    bizState: 'Y',
    pageSize: -1
  }).then((res: any) => {
    tenantList.value = [];
    if (res.code == proxy.$passCode) {
      tenantList.value = res.data?.records || [];
      formItems.value[1].options = tenantList.value;
    } else {
      proxy.$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' },
      { label: '--', value: 'null' }
    ],
    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,
    isApprove: page.value.approveState == 'null' ? 'N' : '',
    approveState: page.value.approveState == 'null' ? null : page.value.approveState,
    currentStaffGuid: userData.staffGuid
  }).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);
    }
  })
}

let needApprovePromise = ref();

const needApprove = ref(true);

const handleCreate = () => {
  if (!assetListData.value.length) {
    ElMessage.warning('当前没有可发起质量评价的资产!');
    return;
  }
  if (needApprovePromise.value) {
    return;
  }
  needApprovePromise.value = isNeedApprove({ funcCode: 'ZCZLPJ' }).then((res1: any) => {
    needApprovePromise.value = null;
    if (res1.code == proxy.$passCode) {
      needApprove.value = res1.data;
      formItems.value[0].visible = true;
      formItems.value[0].default = '';
      formItems.value[1].visible = !needApprove.value;
      formItems.value[1].default = '';
      formItems.value[2].visible = true;
      formItems.value[2].default = [];
      dialogInfo.value.visible = true;
      dialogInfo.value.type = '';
      if (needApprove.value) {
        getCamundaDeploymentId('10018', userData.tenantGuid, userData.staffGuid).then((res: any) => {
          if (res.code == proxy.$passCode) {
            deploymentId.value = res.data;
          } else {
            deploymentId.value = '';
            proxy.$ElMessage.error(res.msg);
          }
        })
      }
    } else {
      proxy.$ElMessage.error(res1.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: '',
  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: 175,
    btns: (scope) => {
      let row = scope.row;
      return getTableBtns(row);
    }
  }
});

const getTableBtns = (row) => {
  let btnsArr: any[] = [];
  const approveVO = row.approveVO;
  if (!approveVO && row.isApprove == 'N') {
    btnsArr.push({ label: "编辑", value: "redit" });
    btnsArr.push({ label: "删除", value: "del" });
    btnsArr.push({ label: "详情", value: "detail" });
    return btnsArr;
  }
  const approveState = row.approveVO.approveState || null;
  const approveStaffGuids = approveVO.approveStaffGuids || [];
  const staffGuid = approveVO.staffGuid || '';
  const bizApproveState = row.approveState;
  const currentStaffGuid = userData.staffGuid
  let isShowCancel = false;
  let flowState;
  if (approveState == 'N') {
    flowState = 1;
  }
  if (approveState == 'A' && approveStaffGuids.indexOf(currentStaffGuid) > -1) {
    flowState = 2;
  }
  if ((bizApproveState == 'D' || approveState == 'C' || approveState == 'R') && staffGuid == currentStaffGuid) {
    flowState = 3;
  }
  if (approveVO && approveVO.approveState == 'A' && staffGuid == currentStaffGuid) {
    isShowCancel = true;
  }
  if (flowState === 1) {
    btnsArr = [{ label: "删除", value: "del" }]
  }
  if (flowState === 2) {
    btnsArr = [{ label: "通过", value: "pass" }, { label: "驳回", value: "reject" }]
  }
  if (flowState === 3 && !row.zqName) {
    btnsArr.push({ label: "删除", value: "del" })
  }
  if (flowState === 3 && bizApproveState != 'D' && !row.zqName) {
    btnsArr.push({ label: "重新提交", value: "redit" })
  }
  if (isShowCancel && !row.zqName) {
    btnsArr.push({ label: "撤销", value: "revoke" })
  }
  if (flowState !== 1) {
    btnsArr.push({ label: "详情", value: "detail" })
  }
  return btnsArr;
}

const currTableData: any = ref({});

let getFirstNodePromise: any = ref({});

const tableBtnClick = (scope, btn) => {
  const type = btn.value;
  const row = scope.row;
  currTableData.value = row;
  console.log(row, '-------');
  if (type == "redit") {
    isNeedApprove({ funcCode: 'ZCZLPJ' }).then((res1: any) => {
      if (res1.code == proxy.$passCode) {
        needApprove.value = res1.data;
        formItems.value[0].visible = false;
        formItems.value[0].default = row.damGuid;
        formItems.value[1].visible = !needApprove.value;
        formItems.value[1].default = row.evaluationAgencyGuid;
        formItems.value[2].default = row.qualityEvaluationFile || [];
        dialogInfo.value.contents[0].formInfo.items = formItems.value;
        dialogInfo.value.visible = true;
        dialogInfo.value.type = 'reSubmit';
      } else {
        proxy.$ElMessage.error(res1.msg);
      }
    })
  } else if (type == "del") {
    delTableOpen("此操作将永久删除该资产质量评价,是否继续?", "warning");
  } else if (type === 'reject') {
    rejectDialogInfo.value.visible = true;
  } else if (type === 'pass') {
    if (row.zqName) {// 专区的审批通过,也不需要填写质量得分。
      passCommonDialogInfo.value.visible = true;
      return;
    }
    if (getFirstNodePromise.value[row.guid]) {
      return;
    }
    getFirstNodePromise.value[row.guid] = isMyFirstNode({
      deploymentId: row.approveVO.camundaDeploymentId,
      processInstanceId: row.approveVO.camundaInstanceId,
      staffGuid: userData.staffGuid
    }).then((res: any) => {
      getFirstNodePromise.value[row.guid] = null;
      if (res?.code == proxy.$passCode) {
        if (res.data) {
          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 {
          passCommonDialogInfo.value.visible = true;
        }
      } else {
        proxy.$ElMessage.error(res.msg);
      }
    })
  } else if (type === 'revoke') { // 撤销,状态为审批中时可以撤销。
    ElMessageBox.confirm(`撤销后,该流程将不再进行审核,确定这样操作吗?`, "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: 'warning',
    }).then(() => {
      revokeFlowData({
        guid: row.approveVO.approveGuid,
        flowType: row.approveVO.flowType,
        approveStaffGuid: userData.staffGuid,
        serviceTenantGuid: row.tenantGuid
      }).then((res: any) => {
        if (res.code == '00000') {
          ElMessage.success('撤销成功!')
          getTableData();
        } else {
          ElMessage.error(res.msg)
        }
      })
    }).catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消撤销'
      });
    });
  } else if (type === 'detail') { // 详情
    if (row.registerApproveState == 'Y') {
      router.push({
        name: 'registerDetail',
        query: { guid: row.registerGuid, evaGuid: row.guid, type: 'qualityEvaluate', tenantGuid: row.tenantGuid, tenantName: row.tenantName }
      });
    } else {
      router.push({
        name: 'evaCatalogDetail',
        query: { guid: row.damGuid, evaGuid: row.guid, type: 'qualityEvaluate', tenantGuid: row.tenantGuid }
      });
    }
  } else if (type == 'productDetail') {
    router.push({
      name: 'registerCatalogDetail',
      query: { guid: row.damGuid, tenantGuid: 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);
  tableInfo.value.page.curr = page.value.curr;
  tableInfo.value.page.limit = page.value.limit;
  getTableData();
};

const formItems = ref([{
  label: '资产名称',
  type: 'select',
  placeholder: '请选择',
  field: 'damGuid',
  default: '',
  block: true,
  options: assetListData.value,
  props: {
    value: 'guid',
    label: 'damName'
  },
  visible: true,
  required: true
}, {
  label: '评估机构',
  type: 'select',
  placeholder: '请选择',
  field: 'evaluationAgencyGuid',
  default: '',
  block: true,
  options: tenantList.value,
  props: {
    value: 'guid',
    label: 'tenantName'
  },
  visible: false,
  required: true
}, {
  label: '附件上传',
  tip: '支持格式:xls .xlsx .doc .docx .rar .zip',
  type: 'upload-file',
  accept: '.xls, .xlsx, .doc, .docx, .rar, .zip',
  templateUrl: 'auto',
  templateClick: () => {
    const link = document.createElement('a');
    link.href = "/files/数据质量评价.docx";
    link.download = '数据质量评价.docx';
    document.body.appendChild(link);
    link.click();
    link.remove();
  },
  required: true,
  block: true,
  visible: true,
  default: [],
  field: 'qualityEvaluationFile',
  limit: 1,
}]);

const formRules = ref({
  damGuid: [
    { 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", loading: false },
    ],
  },
});

/** 编辑质量评价发起资产申请按钮处理。 */
const dialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    if (!needApprove.value) {
      // 不需要走流程审批的提交
      dialogInfo.value.footer.btns[1].loading = true;
      if (dialogInfo.value.type == 'reSubmit') {
        updatQuality({
          guid: currTableData.value.guid,
          tenantGuid: userData.tenantGuid,
          damGuid: currTableData.value.damGuid,
          daName: currTableData.value.daName,
          immediateApprove: true,
          evaluationAgencyGuid: info.evaluationAgencyGuid,
          qualityEvaluationFile: info.qualityEvaluationFile?.map(file => {
            return {
              name: file.name,
              url: file.url
            }
          }) || []
        }).then((res: any) => {
          dialogInfo.value.footer.btns[1].loading = false;
          if (res?.code == proxy.$passCode) {
            ElMessage.success('该资产质量评价重新提交成功');
            dialogInfo.value.visible = false;
            page.value.curr = 1;
            getTableData();
          } else {
            ElMessage.error(res.msg);
          }
        })
      } else {
        let daInfo = assetListData.value.find(a => a.guid == info.damGuid);
        saveQuality({
          tenantGuid: userData.tenantGuid,
          damGuid: info.damGuid,
          daName: daInfo.damName,
          immediateApprove: true,
          evaluationAgencyGuid: info.evaluationAgencyGuid,
          qualityEvaluationFile: info.qualityEvaluationFile?.map(file => {
            return {
              name: file.name,
              url: file.url
            }
          }) || []
        }).then((res: any) => {
          dialogInfo.value.footer.btns[1].loading = false;
          if (res?.code == proxy.$passCode) {
            ElMessage.success('质量评价发起成功');
            dialogInfo.value.visible = false;
            page.value.curr = 1;
            getTableData();
          } else {
            ElMessage.error(res.msg);
          }
        })
      }
    } else {
      // 需要走流程的审批功能。
      dialogInfo.value.footer.btns[1].loading = true;
      let submitFunc = () => {
        getProcessNodesPromise({
          deploymentId: deploymentId.value,
          processInstanceId: null,
        }).then((res: any) => {
          if (res?.code == proxy.$passCode) {
            getStaffDetailInfo(res.data?.[1]?.candidateUsers?.[0]?.staffGuid).then((resUser: any) => {
              if (resUser?.code == proxy.$passCode) {
                if (dialogInfo.value.type == 'reSubmit') {
                  updatQuality({
                    guid: currTableData.value.guid,
                    tenantGuid: userData.tenantGuid,
                    damGuid: currTableData.value.damGuid,
                    daName: currTableData.value.daName,
                    immediateApprove: true,
                    evaluationAgencyGuid: resUser.data?.tenantGuid,
                    qualityEvaluationFile: info.qualityEvaluationFile?.map(file => {
                      return {
                        name: file.name,
                        url: file.url
                      }
                    }) || []
                  }).then((res: any) => {
                    dialogInfo.value.footer.btns[1].loading = false;
                    if (res?.code == proxy.$passCode) {
                      ElMessage.success('该资产质量评价重新提交成功');
                      dialogInfo.value.visible = false;
                      page.value.curr = 1;
                      getTableData();
                    } else {
                      ElMessage.error(res.msg);
                    }
                  })
                } else {
                  let daInfo = assetListData.value.find(a => a.guid == info.damGuid);
                  saveQuality({
                    tenantGuid: userData.tenantGuid,
                    damGuid: info.damGuid,
                    daName: daInfo.damName,
                    immediateApprove: true,
                    evaluationAgencyGuid: resUser.data?.tenantGuid,
                    qualityEvaluationFile: info.qualityEvaluationFile?.map(file => {
                      return {
                        name: file.name,
                        url: file.url
                      }
                    }) || []
                  }).then((res: any) => {
                    dialogInfo.value.footer.btns[1].loading = false;
                    if (res?.code == proxy.$passCode) {
                      ElMessage.success('质量评价发起成功');
                      dialogInfo.value.visible = false;
                      page.value.curr = 1;
                      getTableData();
                    } else {
                      ElMessage.error(res.msg);
                    }
                  })
                }
              } else {
                dialogInfo.value.footer.btns[1].loading = false;
                ElMessage.error(res.msg);
              }
            })
          } else {
            dialogInfo.value.footer.btns[1].loading = false;
            ElMessage.error(res.msg);
          }
        })
      }
      if (deploymentId.value) {
        submitFunc();
      } else {
        getCamundaDeploymentId('10018', userData.tenantGuid, userData.staffGuid).then((res: any) => {
          if (res.code == proxy.$passCode) {
            deploymentId.value = res.data;
            submitFunc();
          } else {
            dialogInfo.value.footer.btns[1].loading = false;
            proxy.$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", loading: false },
    ],
  },
});

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') {
    passDialogInfo.value.footer.btns[1].loading = true;
    qualityAllow({
      guid: currTableData.value.approveVO.approveGuid,
      bizGuid: currTableData.value.guid,
      flowType: currTableData.value.approveVO.flowType,
      approveStaffGuid: userData.staffGuid,
      qualityScore: info.qualityScore,
      evaluationRangeStart: info.evaluationRange[0],
      evaluationRangeEnd: info.evaluationRange[1],
      evaluationNote: info.evaluationNote,
      evaluationFile: info.evaluationFile?.map(file => {
        return {
          name: file.name,
          url: file.url
        }
      }) || [],
    }, currTableData.value.tenantGuid).then((res: any) => {
      passDialogInfo.value.footer.btns[1].loading = false;
      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", loading: false },
    ],
  },
});

const rejectDialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    if (info.approveSuggest == '') {
      ElMessage.error('请填写驳回理由');
      return
    }
    let row = currTableData.value;
    rejectDialogInfo.value.footer.btns[1].loading = true;
    let params = {
      guid: row.approveVO.approveGuid,
      flowType: row.approveVO.flowType,
      approveStaffGuid: userData.staffGuid,
      approveSuggest: info.approveSuggest
    }
    rejectFlowData(params, currTableData.value.tenantGuid).then((res: any) => {
      rejectDialogInfo.value.footer.btns[1].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;
  }
};

const passCommonDialogInfo = ref({
  visible: false,
  size: 460,
  direction: "column",
  header: {
    title: "通过",
  },
  type: '',
  contents: [
    {
      type: 'form',
      title: '',
      formInfo: {
        id: 'batch-pass-form',
        items: [
          {
            label: '',
            type: "textarea",
            placeholder: "请填写通过备注(选填)",
            field: "approveSuggest",
            clearable: true,
            maxlength: 400,
            block: true,
            col: 'margin_b_0',
          }
        ]
      }
    }
  ],
  footer: {
    btns: [
      { type: "default", label: "取消", value: "cancel" },
      { type: "primary", label: "确定", value: "submit", loading: false },
    ],
  },
});

const passCommonDialogBtnClick = (btn, info) => {
  if (btn.value == 'submit') {
    passCommonDialogInfo.value.footer.btns[1].loading = true;
    let params = {
      guid: currTableData.value.approveVO.approveGuid,
      flowType: currTableData.value.approveVO.flowType,
      approveSuggest: info.approveSuggest,
      approveStaffGuid: userData.staffGuid
    }
    passFlowData(params, currTableData.value.tenantGuid).then((res: any) => {
      passCommonDialogInfo.value.footer.btns[1].loading = false;
      if (res?.code == proxy.$passCode) {
        if (res.data) {
          ElMessage.success('审批成功');
          passCommonDialogInfo.value.visible = false;
          getTableData();
        } else {
          ElMessage.error('审批失败');
        }
      } else {
        ElMessage.error(res.msg);
      }
    })
  } else if (btn.value == 'cancel') {
    passCommonDialogInfo.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" />
    <Dialog :dialogInfo="passCommonDialogInfo" @btnClick="passCommonDialogBtnClick" />
  </div>
</template>

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