src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
@@ -10,6 +10,9 @@
  saveApprovalInstance,
  updateApprovalInstance,
} from "@/api/officeProcessAutomation/approvalInstance.js";
import { getQuotationList } from "@/api/salesManagement/salesQuotation.js";
import { getPurchaseByCode } from "@/api/procurementManagement/procurementLedger.js";
import { getDeliveryDetailByShippingNo } from "@/api/salesManagement/deliveryLedger.js";
import useUserStore from "@/store/modules/user";
import { Search } from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
@@ -34,6 +37,7 @@
import {
  APPROVAL_STATUS_SEARCH_OPTIONS,
  APPROVAL_TYPE_OPTIONS,
  approvalRecordResultLabel,
  approvalStatusLabel,
  approvalStatusTagType,
  approvalTypeLabel,
@@ -45,6 +49,7 @@
  mapInstanceFromApi,
  mapSubmitTemplateCard,
  matchBusinessTypeValue,
  normalizeApprovalStatusKey,
  unwrapInstancePage,
} from "./approveListConstants.js";
@@ -77,6 +82,7 @@
  const detailDialog = reactive({ visible: false });
  const detailRow = ref({});
  const detailData = ref({});
  const approveDialog = reactive({ visible: false, row: null });
  const approveOpinion = ref("");
@@ -134,9 +140,19 @@
    ...buildFormPayloadRules(submitFormFields.value),
  }));
  /** 仅「发起人本人」在「已驳回」状态下可修改 */
  function canEditInstanceRow(row) {
    if (!row) return false;
    const key = normalizeApprovalStatusKey(row.approvalStatus ?? row.statusRaw ?? row.status);
    if (key !== "rejected") return false;
    const applicantId = row.applicantId ?? row.applicantNo;
    if (applicantId == null || applicantId === "") return false;
    return String(applicantId) === String(userStore.id);
  }
  const tableColumn = ref([
    { label: "申请人编号", prop: "applicantNo", width: 110 },
    { label: "申请人名称", prop: "applicantName", minWidth: 100 },
    // { label: "申请人编号", prop: "applicantNo", width: 110 },
    { label: "发起人", prop: "applicantName", minWidth: 100 },
    { label: "模板类型", prop: "businessName", minWidth: 120 },
    {
      label: "审批类型",
@@ -150,7 +166,9 @@
      prop: "unread",
      width: 90,
      align: "center",
      dataType: "tag",
      formatData: (v) => (v ? "是" : "否"),
      formatType: (v) => (v ? "success" : "danger"),
    },
    {
      label: "审批状态",
@@ -177,7 +195,7 @@
        {
          name: "修改",
          type: "text",
          disabled: (row) => row.approvalStatus !== "pending",
          disabled: (row) => !canEditInstanceRow(row),
          clickFun: (row) => openEditDialog(row),
        },
        {
@@ -186,11 +204,11 @@
          disabled: (row) => row.approvalStatus !== "pending" || !row.isApprove,
          clickFun: (row) => openApprove(row),
        },
        {
          name: "删除",
          type: "danger",
          clickFun: (row) => removeInstance(row),
        },
        // {
        //   name: "删除",
        //   type: "danger",
        //   clickFun: (row) => removeInstance(row),
        // },
      ],
    },
  ]);
@@ -220,7 +238,7 @@
        fetchBusinessTypeOptions(),
        listApprovalTemplate(TEMPLATE_TYPE_CUSTOM),
      ]);
      submitBusinessTypeOptions.value = typeOptions;
      submitBusinessTypeOptions.value = typeOptions.filter((x) => ![5, 6, 7].includes(x.value));
      allSubmitTemplates.value = unwrapTemplateList(customRes)
        .filter((row) => mapEnabledFromApi(row.enabled))
        .map(mapSubmitTemplateCard);
@@ -288,11 +306,46 @@
      await openReimburseDetail(row, "detail");
      return;
    }
    detailRow.value = { ...row };
    // 报价审批:用审批事由字段承载的"报价单号"去查报价列表
    if (row.businessType === 6) {
      const quotationNo = row?.quotationNo;
      if (quotationNo) {
        const res = await getQuotationList({ quotationNo });
        const records = res?.data?.records || [];
        detailData.value = records[0] || {};
      }
    }
    // 采购审批:用审批事由字段承载的"采购合同号"去查采购详情
    else if (row.businessType === 5) {
      const purchaseContractNumber = row?.purchaseContractNumber;
      if (purchaseContractNumber) {
        const res = await getPurchaseByCode({ purchaseContractNumber });
        detailData.value = res || {};
      }
    }
    // 发货审批:用审批事由字段承载的"发货单号"去查发货详情
    else if (row.businessType === 7) {
      const shippingNo = row?.shippingNo;
      if (shippingNo) {
        const res = await getDeliveryDetailByShippingNo({ shippingNo });
        detailData.value = res?.data || res || {};
      }
    }
    // 其他审批类型
    else {
      detailData.value = {};
    }
    detailDialog.visible = true;
  }
  async function openApprove(row) {
    if (inferReimburseModuleKeyFromInstance(row)) {
      approveOpinion.value = "";
      await openReimburseDetail(row, "approve");
@@ -300,6 +353,38 @@
    }
    approveDialog.row = { ...row };
    approveOpinion.value = "";
    // 报价审批:用审批事由字段承载的"报价单号"去查报价列表
    if (row.businessType === 6) {
      const quotationNo = row?.quotationNo;
      if (quotationNo) {
        const res = await getQuotationList({ quotationNo });
        const records = res?.data?.records || [];
        detailData.value = records[0] || {};
      }
    }
    // 采购审批:用审批事由字段承载的"采购合同号"去查采购详情
    else if (row.businessType === 5) {
      const purchaseContractNumber = row?.purchaseContractNumber;
      if (purchaseContractNumber) {
        const res = await getPurchaseByCode({ purchaseContractNumber });
        detailData.value = res || {};
      }
    }
    // 发货审批:用审批事由字段承载的"发货单号"去查发货详情
    else if (row.businessType === 7) {
      const shippingNo = row?.shippingNo;
      if (shippingNo) {
        const res = await getDeliveryDetailByShippingNo({ shippingNo });
        detailData.value = res?.data || res || {};
      }
    }
    // 其他审批类型
    else {
      detailData.value = {};
    }
    approveDialog.visible = true;
  }
@@ -322,8 +407,8 @@
  }
  async function openEditDialog(row) {
    if (row?.approvalStatus !== "pending") {
      ElMessage.warning("仅审核中的审批可修改");
    if (!canEditInstanceRow(row)) {
      ElMessage.warning("仅本人发起、且已被驳回的审批可修改");
      return;
    }
    const moduleKey = inferReimburseModuleKeyFromInstance(row);
@@ -564,9 +649,7 @@
  }
  function approvalActionLabel(result) {
    if (result === "approved") return "通过";
    if (result === "rejected") return "驳回";
    return "待处理";
    return approvalRecordResultLabel(result);
  }
  return {
@@ -586,6 +669,7 @@
    tableColumn,
    detailDialog,
    detailRow,
    detailData,
    reimburseDialog,
    approveDialog,
    approveOpinion,
@@ -614,6 +698,7 @@
    resetSubmitDialogState,
    openSubmitDialog,
    openEditDialog,
    canEditInstanceRow,
    onBusinessTypePick,
    onTemplatePick,
    backToBusinessTypePick,
@@ -625,4 +710,4 @@
    openApprove,
    fetchApprovalList,
  };
}
}