From 1daa22ed05c77e4a8c3069124a1849d5d6504f69 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 30 七月 2026 17:57:00 +0800
Subject: [PATCH] 修改报工审批数据显示

---
 src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js |  366 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 307 insertions(+), 59 deletions(-)

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js b/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
index 4b8510a..91cf317 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
@@ -10,20 +10,33 @@
   saveApprovalInstance,
   updateApprovalInstance,
 } from "@/api/officeProcessAutomation/approvalInstance.js";
+import { productionProductMainGetInfo } from "@/api/productionManagement/productionProductMain.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";
-import { computed, reactive, ref } from "vue";
+import { computed, getCurrentInstance, reactive, ref } from "vue";
+import {
+  inferReimburseModuleKeyFromInstance,
+  loadReimburseDetailForInstance,
+  navigateToReimburseManageForEdit,
+  resolveFinReimbursementIdFromInstance,
+} from "../../ReimburseManage/shared/reimburseApproveBridge.js";
 import {
   fetchBusinessTypeOptions,
   formatDisplayTime,
   mapEnabledFromApi,
-  mapTemplateFromApi,
-  unwrapTemplateDetail,
   unwrapTemplateList,
 } from "../approve-template/approveTemplateConstants.js";
-import { buildSubmitTemplateFromRow } from "../approve-template/formConfigUtils.js";
 import {
+  buildFormPayloadRules,
+  buildTemplateBindingFromDetail,
+  validateTemplateBinding,
+} from "../approve-shared/approvalTemplateBindingUtils.js";
+import {
+  APPROVAL_STATUS_SEARCH_OPTIONS,
   APPROVAL_TYPE_OPTIONS,
   approvalStatusLabel,
   approvalStatusTagType,
@@ -32,20 +45,19 @@
   buildApproveInstanceDto,
   buildEditFormFromInstanceRow,
   buildInstanceDto,
-  clearLegacyApproveListStorage,
   createEmptySubmitForm,
   mapInstanceFromApi,
   mapSubmitTemplateCard,
   matchBusinessTypeValue,
-  validateSubmitFlowNodes,
   unwrapInstancePage,
 } from "./approveListConstants.js";
 
 export function useApproveList() {
-  clearLegacyApproveListStorage();
+  const { proxy } = getCurrentInstance() || {};
   const userStore = useUserStore();
 
   const tableData = ref([]);
+  const searchBusinessTypeOptions = ref([]);
   const submitBusinessTypeOptions = ref([]);
   const allSubmitTemplates = ref([]);
   const selectedBusinessType = ref("");
@@ -59,8 +71,8 @@
   });
 
   const searchForm = reactive({
-    approvalType: "",
-    applicantKeyword: "",
+    businessType: "",
+    status: "",
     createTimeRange: [],
   });
 
@@ -69,10 +81,21 @@
 
   const detailDialog = reactive({ visible: false });
   const detailRow = ref({});
+  const detailData = ref({});
 
   const approveDialog = reactive({ visible: false, row: null });
   const approveOpinion = ref("");
   const approveSubmitting = ref(false);
+
+  /** 宸梾/璐圭敤鎶ラ攢涓撶敤璇︽儏銆佸鎵瑰脊绐� */
+  const reimburseDialog = reactive({
+    visible: false,
+    mode: "detail",
+    moduleKey: "",
+    loading: false,
+    reimburseRow: {},
+    instanceRow: null,
+  });
 
   const submitDialog = reactive({ visible: false, step: 1, mode: "add" });
   const submitEditRow = ref(null);
@@ -111,27 +134,15 @@
     return submitForm.formFieldDefs || [];
   });
 
-  const submitFormRules = computed(() => {
-    const rules = {
-      templateKey: [{ required: true, message: "璇烽�夋嫨瀹℃壒绫诲瀷", trigger: "change" }],
-    };
-    submitFormFields.value.forEach((f) => {
-      if (!f.required) return;
-      if (f.type === "number") {
-        rules[`formPayload.${f.key}`] = [{ required: true, message: `璇峰~鍐�${f.label}`, trigger: "blur" }];
-      } else if (f.type === "datetimerange") {
-        rules[`formPayload.${f.key}`] = [{ required: true, message: `璇烽�夋嫨${f.label}`, trigger: "change" }];
-      } else {
-        rules[`formPayload.${f.key}`] = [{ required: true, message: `璇峰~鍐�${f.label}`, trigger: "blur" }];
-      }
-    });
-    return rules;
-  });
+  const submitFormRules = computed(() => ({
+    templateKey: [{ required: true, message: "璇烽�夋嫨瀹℃壒绫诲瀷", trigger: "change" }],
+    ...buildFormPayloadRules(submitFormFields.value),
+  }));
 
   const tableColumn = ref([
-    { label: "鐢宠浜虹紪鍙�", prop: "applicantNo", width: 110 },
-    { label: "鐢宠浜哄悕绉�", prop: "applicantName", minWidth: 100 },
-    { label: "涓氬姟绫诲瀷", prop: "businessName", minWidth: 120 },
+    // { label: "鐢宠浜虹紪鍙�", prop: "applicantNo", width: 110 },
+    { label: "鍙戣捣浜�", prop: "applicantName", minWidth: 100 },
+    { label: "妯℃澘绫诲瀷", prop: "businessName", minWidth: 120 },
     {
       label: "瀹℃壒绫诲瀷",
       prop: "approvalType",
@@ -144,7 +155,9 @@
       prop: "unread",
       width: 90,
       align: "center",
+      dataType: "tag",
       formatData: (v) => (v ? "鏄�" : "鍚�"),
+      formatType: (v) => (v ? "success" : "danger"),
     },
     {
       label: "瀹℃壒鐘舵��",
@@ -171,7 +184,7 @@
         {
           name: "淇敼",
           type: "text",
-          disabled: (row) => row.approvalStatus !== "pending",
+          disabled: (row) => row.approvalStatus !== "pending" || Number(row?.businessType) === 19,
           clickFun: (row) => openEditDialog(row),
         },
         {
@@ -180,11 +193,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),
+        // },
       ],
     },
   ]);
@@ -214,7 +227,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);
@@ -233,10 +246,18 @@
   }
 
   function resetSearch() {
-    searchForm.approvalType = "";
-    searchForm.applicantKeyword = "";
+    searchForm.businessType = "";
+    searchForm.status = "";
     searchForm.createTimeRange = [];
     handleQuery();
+  }
+
+  async function loadSearchBusinessTypeOptions() {
+    try {
+      searchBusinessTypeOptions.value = await fetchBusinessTypeOptions();
+    } catch {
+      searchBusinessTypeOptions.value = [];
+    }
   }
 
   function pagination({ page: p, limit }) {
@@ -245,15 +266,201 @@
     fetchApprovalList();
   }
 
-  function openDetail(row) {
+  async function openReimburseDetail(row, mode) {
+    const moduleKey = inferReimburseModuleKeyFromInstance(row);
+    if (!moduleKey) return false;
+    reimburseDialog.mode = mode;
+    reimburseDialog.moduleKey = moduleKey;
+    reimburseDialog.instanceRow = row;
+    reimburseDialog.visible = true;
+    reimburseDialog.loading = true;
+    reimburseDialog.reimburseRow = {};
+    try {
+      const { reimburseRow, moduleKey: resolvedMk } =
+        await loadReimburseDetailForInstance(row, moduleKey);
+      reimburseDialog.moduleKey = resolvedMk || moduleKey;
+      reimburseDialog.reimburseRow = reimburseRow;
+      return true;
+    } catch {
+      ElMessage.error("鍔犺浇鎶ラ攢璇︽儏澶辫触");
+      reimburseDialog.visible = false;
+      return false;
+    } finally {
+      reimburseDialog.loading = false;
+    }
+  }
+
+  async function openDetail(row) {
+    if (isReimburseApprovalInstance(row)) {
+      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 if (row.businessType === 19) {
+      detailData.value = {};
+      detailRow.value = await mergeProductionReportDetail(detailRow.value);
+    }
+    
+    // 鍏朵粬瀹℃壒绫诲瀷
+    else {
+      detailData.value = {};
+    }
+    
     detailDialog.visible = true;
   }
 
-  function openApprove(row) {
+  async function openApprove(row) {
+
+    if (inferReimburseModuleKeyFromInstance(row)) {
+      approveOpinion.value = "";
+      await openReimburseDetail(row, "approve");
+      return;
+    }
     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 if (row.businessType === 19) {
+      detailData.value = {};
+      approveDialog.row = await mergeProductionReportDetail(approveDialog.row);
+    }
+
+    // 鍏朵粬瀹℃壒绫诲瀷
+    else {
+      detailData.value = {};
+    }
     approveDialog.visible = true;
+  }
+
+  async function mergeProductionReportDetail(row) {
+    const businessId = row?.businessId ?? row?.bizId ?? row?.id;
+    if (!businessId) return row;
+    try {
+      const res = await productionProductMainGetInfo(businessId);
+      const report = res?.data || res || {};
+      const formConfigPayload = row?.formConfig?.formPayload || {};
+      const schedulingNum = Number(
+        report?.schedulingNum ?? report?.planQuantity ?? formConfigPayload.schedulingNum ?? row?.schedulingNum ?? 0
+      );
+      const finishedNum = Number(
+        report?.finishedNum ?? report?.quantity ?? formConfigPayload.finishedNum ?? row?.finishedNum ?? row?.quantity ?? 0
+      );
+      const scrapQty = Number(
+        report?.scrapQty ?? formConfigPayload.scrapQty ?? row?.scrapQty ?? 0
+      );
+      const pendingNum = Number(
+        formConfigPayload.pendingNum ?? report?.pendingNum ?? row?.pendingNum ?? Math.max(schedulingNum - finishedNum, 0)
+      );
+      const reportTypeOptions = [
+        { label: "鍚堟牸", value: 0 },
+        { label: "杞诲井杩斿伐", value: 1 },
+        { label: "涓ラ噸杩斿伐", value: 2 },
+        { label: "鎶ュ簾", value: 3 },
+      ];
+      const mergedFields = [
+        { key: "productNo", label: "鎶ュ伐鍗曞彿", type: "text" },
+        { key: "userName", label: "鎶ュ伐浜哄憳", type: "text" },
+        { key: "teamInfo", label: "鐝粍淇℃伅", type: "text" },
+        { key: "workOrderNo", label: "宸ュ崟缂栧彿", type: "text" },
+        { key: "pendingNum", label: "寰呯敓浜ф暟閲�", type: "number", precision: 2 },
+        { key: "finishedNum", label: "鐢熶骇鍚堟牸鏁伴噺", type: "number", precision: 2 },
+        { key: "scrapQty", label: "鎶ュ簾鏁伴噺", type: "number", precision: 2 },
+        { key: "reportType", label: "鎶ュ伐绫诲瀷", type: "select", options: reportTypeOptions },
+      ];
+      const rawReportType = report?.reportType ?? row?.formPayload?.reportType ?? row?.reportType;
+      const reportType = Number.isFinite(Number(rawReportType)) ? Number(rawReportType) : 0;
+      const formPayload = {
+        productNo: report?.productNo || row?.productNo || row?.formPayload?.productNo || "鈥�",
+        userName: report?.userName || row?.applicantName || row?.formPayload?.userName || "鈥�",
+        teamInfo: report?.teamInfo || row?.applicantName || row?.formPayload?.teamInfo || "鈥�",
+        workOrderNo: report?.workOrderNo || row?.workOrderNo || row?.formPayload?.workOrderNo || "鈥�",
+        pendingNum,
+        finishedNum,
+        scrapQty,
+        reportType,
+      };
+      const mergedRow = {
+        ...row,
+        schedulingNum,
+        pendingNum,
+        scrapQty,
+        finishedNum,
+        formFieldDefs: mergedFields,
+        formPayload,
+        formConfig: {
+          ...(typeof row.formConfig === "object" ? row.formConfig : {}),
+          ...(row?.formConfig?.formPayload ? { formPayload: { ...row.formConfig.formPayload } } : {}),
+          fields: mergedFields,
+          formPayload,
+          approvalType: "production_report",
+        },
+      };
+      return mergedRow;
+    } catch (error) {
+      console.error("鍔犺浇鎶ュ伐瀹℃壒涓氬姟璇︽儏澶辫触", error);
+    }
+    return row;
+  }
+
+  function isReimburseApprovalInstance(row) {
+    return Boolean(inferReimburseModuleKeyFromInstance(row));
   }
 
   function resetSubmitDialogState() {
@@ -270,14 +477,31 @@
     loadSubmitTemplates();
   }
 
-  function openEditDialog(row) {
+  async function openEditDialog(row) {
     if (row?.approvalStatus !== "pending") {
       ElMessage.warning("浠呭鏍镐腑鐨勫鎵瑰彲淇敼");
+      return;
+    }
+    const moduleKey = inferReimburseModuleKeyFromInstance(row);
+    if (moduleKey) {
+      const rid = resolveFinReimbursementIdFromInstance(row);
+      if (rid == null) {
+        ElMessage.warning("鏃犳硶淇敼锛氱己灏戞姤閿�鍗� ID");
+        return;
+      }
+      try {
+        await navigateToReimburseManageForEdit(proxy?.$router, moduleKey, rid);
+      } catch {
+        ElMessage.warning("鏈壘鍒板樊鏃�/璐圭敤鎶ラ攢鑿滃崟璺敱锛岃浠庡乏渚ц彍鍗曡繘鍏ュ悗鍐嶇紪杈�");
+      }
       return;
     }
     if (!row?.id) {
       ElMessage.warning("鏃犳硶淇敼锛氱己灏戝鎵瑰疄渚� ID");
       return;
+    }
+    if (row.businessType === 19) {
+      row = await mergeProductionReportDetail(row);
     }
     submitDialog.mode = "edit";
     submitDialog.step = 3;
@@ -291,18 +515,12 @@
     submitTemplatesLoading.value = true;
     try {
       const res = await getApprovalTemplateDetail(card.id);
-      const mapped = mapTemplateFromApi(unwrapTemplateDetail(res));
-      const tpl = {
-        ...buildSubmitTemplateFromRow(mapped),
-        templateId: mapped.id,
-      };
-      const base = createEmptySubmitForm(String(card.id), tpl, mapped.flowNodes);
+      const applied = buildTemplateBindingFromDetail(res);
       Object.assign(submitForm, {
-        ...base,
-        templateName: mapped.templateName || tpl.label || "",
-        businessType: mapped.businessType ?? card.businessType ?? selectedBusinessType.value,
-        templateSnapshot: tpl,
-        formFieldDefs: tpl.fields || [],
+        templateKey: String(card.id),
+        ...applied,
+        businessType:
+          applied.businessType ?? card.businessType ?? selectedBusinessType.value,
       });
       submitDialog.step = 3;
     } catch {
@@ -343,9 +561,9 @@
       return false;
     }
     if (!activeTemplate.value) return false;
-    const flowCheck = validateSubmitFlowNodes(submitForm.flowNodes);
-    if (!flowCheck.ok) {
-      ElMessage.warning(flowCheck.message);
+    const bindingCheck = validateTemplateBinding({ flowNodes: submitForm.flowNodes });
+    if (!bindingCheck.ok) {
+      ElMessage.warning(bindingCheck.message);
       return false;
     }
     if (!submitForm.templateId) {
@@ -360,7 +578,7 @@
           submitForm,
           activeTemplate: activeTemplate.value,
           userStore,
-          flowNodes: flowCheck.nodes,
+          flowNodes: bindingCheck.nodes,
         })
       );
       submitDialog.visible = false;
@@ -382,9 +600,9 @@
       return false;
     }
     if (!activeTemplate.value) return false;
-    const flowCheck = validateSubmitFlowNodes(submitForm.flowNodes);
-    if (!flowCheck.ok) {
-      ElMessage.warning(flowCheck.message);
+    const bindingCheck = validateTemplateBinding({ flowNodes: submitForm.flowNodes });
+    if (!bindingCheck.ok) {
+      ElMessage.warning(bindingCheck.message);
       return false;
     }
     if (!submitForm.instanceId) {
@@ -398,7 +616,7 @@
         buildInstanceDto({
           submitForm,
           activeTemplate: activeTemplate.value,
-          flowNodes: flowCheck.nodes,
+          flowNodes: bindingCheck.nodes,
           existingRow: submitEditRow.value,
         })
       );
@@ -453,6 +671,29 @@
     }
   }
 
+  async function submitReimburseApprove(result) {
+    const row = reimburseDialog.instanceRow;
+    if (!row?.id) return { ok: false };
+    if (result === "rejected" && !(approveOpinion.value || "").trim()) {
+      return { needOpinion: true };
+    }
+    if (approveSubmitting.value) return { ok: false };
+    approveSubmitting.value = true;
+    try {
+      await approveApprovalInstance(
+        buildApproveInstanceDto(row, result, approveOpinion.value)
+      );
+      reimburseDialog.visible = false;
+      await fetchApprovalList();
+      return { ok: true, result };
+    } catch {
+      ElMessage.error("瀹℃壒鎿嶄綔澶辫触");
+      return { ok: false };
+    } finally {
+      approveSubmitting.value = false;
+    }
+  }
+
   async function submitApprove(result) {
     const row = approveDialog.row;
     if (!row?.id) return { ok: false };
@@ -490,6 +731,9 @@
   return {
     Search,
     APPROVAL_TYPE_OPTIONS,
+    APPROVAL_STATUS_SEARCH_OPTIONS,
+    searchBusinessTypeOptions,
+    loadSearchBusinessTypeOptions,
     approvalTypeLabel,
     approvalStatusLabel,
     approvalStatusTagType,
@@ -501,9 +745,13 @@
     tableColumn,
     detailDialog,
     detailRow,
+    detailData,
+    reimburseDialog,
     approveDialog,
     approveOpinion,
     approveSubmitting,
+    submitReimburseApprove,
+    isReimburseApprovalInstance,
     submitDialog,
     isSubmitEdit,
     submitDialogTitle,

--
Gitblit v1.9.3