From 97081b89ee45da49b8dbb4173ab45df031fe3c0d Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 16:58:40 +0800
Subject: [PATCH] 删除冗余和无效代码

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

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js b/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
index 337b00d..3523ef4 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-list/useApproveList.js
@@ -1,7 +1,6 @@
 import {
   getApprovalTemplateDetail,
   listApprovalTemplate,
-  TEMPLATE_TYPE_BUILTIN,
   TEMPLATE_TYPE_CUSTOM,
 } from "@/api/officeProcessAutomation/approvalTemplate.js";
 import {
@@ -16,14 +15,18 @@
 import { ElMessage, ElMessageBox } from "element-plus";
 import { computed, reactive, ref } from "vue";
 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,25 +35,33 @@
   buildApproveInstanceDto,
   buildEditFormFromInstanceRow,
   buildInstanceDto,
-  clearLegacyApproveListStorage,
   createEmptySubmitForm,
   mapInstanceFromApi,
   mapSubmitTemplateCard,
-  validateSubmitFlowNodes,
+  matchBusinessTypeValue,
   unwrapInstancePage,
 } from "./approveListConstants.js";
 
 export function useApproveList() {
-  clearLegacyApproveListStorage();
   const userStore = useUserStore();
 
   const tableData = ref([]);
-  const submitTemplateCards = ref([]);
+  const searchBusinessTypeOptions = ref([]);
+  const submitBusinessTypeOptions = ref([]);
+  const allSubmitTemplates = ref([]);
+  const selectedBusinessType = ref("");
   const submitTemplatesLoading = ref(false);
 
+  const submitTemplateCards = computed(() => {
+    if (selectedBusinessType.value == null || selectedBusinessType.value === "") return [];
+    return allSubmitTemplates.value.filter((card) =>
+      matchBusinessTypeValue(card.businessType, selectedBusinessType.value)
+    );
+  });
+
   const searchForm = reactive({
-    approvalType: "",
-    applicantKeyword: "",
+    businessType: "",
+    status: "",
     createTimeRange: [],
   });
 
@@ -75,9 +86,22 @@
     if (submitDialog.mode === "edit") {
       return `淇敼${activeTemplate.value?.label || submitForm.templateName || "瀹℃壒"}`;
     }
-    if (submitDialog.step === 1) return "閫夋嫨瀹℃壒妯℃澘";
+    if (submitDialog.step === 1) return "閫夋嫨妯℃澘绫诲瀷";
+    if (submitDialog.step === 2) return `閫夋嫨瀹℃壒妯℃澘${businessTypeLabel(selectedBusinessType.value) ? `锛�${businessTypeLabel(selectedBusinessType.value)}锛塦 : ""}`;
     return `鎻愪氦${activeTemplate.value?.label || "瀹℃壒"}`;
   });
+
+  const selectedBusinessTypeLabel = computed(() => businessTypeLabel(selectedBusinessType.value));
+
+  function businessTypeLabel(type) {
+    if (type == null || type === "") return "";
+    const hit = submitBusinessTypeOptions.value.find((x) => matchBusinessTypeValue(x.value, type));
+    return hit?.label || "";
+  }
+
+  function countTemplatesByBusinessType(type) {
+    return allSubmitTemplates.value.filter((card) => matchBusinessTypeValue(card.businessType, type)).length;
+  }
 
   const activeTemplate = computed(() => submitForm.templateSnapshot || null);
 
@@ -88,27 +112,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: "businessName", minWidth: 120 },
     {
       label: "瀹℃壒绫诲瀷",
       prop: "approvalType",
@@ -187,17 +199,17 @@
   async function loadSubmitTemplates() {
     submitTemplatesLoading.value = true;
     try {
-      const [builtinRes, customRes] = await Promise.all([
-        listApprovalTemplate(TEMPLATE_TYPE_BUILTIN),
+      const [typeOptions, customRes] = await Promise.all([
+        fetchBusinessTypeOptions(),
         listApprovalTemplate(TEMPLATE_TYPE_CUSTOM),
       ]);
-      const merged = [
-        ...unwrapTemplateList(builtinRes),
-        ...unwrapTemplateList(customRes),
-      ].filter((row) => mapEnabledFromApi(row.enabled));
-      submitTemplateCards.value = merged.map(mapSubmitTemplateCard);
+      submitBusinessTypeOptions.value = typeOptions;
+      allSubmitTemplates.value = unwrapTemplateList(customRes)
+        .filter((row) => mapEnabledFromApi(row.enabled))
+        .map(mapSubmitTemplateCard);
     } catch {
-      submitTemplateCards.value = [];
+      submitBusinessTypeOptions.value = [];
+      allSubmitTemplates.value = [];
       ElMessage.error("鍔犺浇瀹℃壒妯℃澘澶辫触");
     } finally {
       submitTemplatesLoading.value = false;
@@ -210,10 +222,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 }) {
@@ -236,6 +256,7 @@
   function resetSubmitDialogState() {
     submitDialog.mode = "add";
     submitDialog.step = 1;
+    selectedBusinessType.value = "";
     submitEditRow.value = null;
     Object.assign(submitForm, createEmptySubmitForm(""));
   }
@@ -256,7 +277,7 @@
       return;
     }
     submitDialog.mode = "edit";
-    submitDialog.step = 2;
+    submitDialog.step = 3;
     submitEditRow.value = { ...row };
     Object.assign(submitForm, buildEditFormFromInstanceRow(row));
     submitDialog.visible = true;
@@ -267,19 +288,14 @@
     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 || "",
-        templateSnapshot: tpl,
-        formFieldDefs: tpl.fields || [],
+        templateKey: String(card.id),
+        ...applied,
+        businessType:
+          applied.businessType ?? card.businessType ?? selectedBusinessType.value,
       });
-      submitDialog.step = 2;
+      submitDialog.step = 3;
     } catch {
       ElMessage.error("鍔犺浇妯℃澘璇︽儏澶辫触");
     } finally {
@@ -287,8 +303,22 @@
     }
   }
 
-  function backToTemplatePick() {
+  function onBusinessTypePick(type) {
+    if (!countTemplatesByBusinessType(type)) {
+      ElMessage.warning("璇ョ被鍨嬩笅鏆傛棤鍙敤瀹℃壒妯℃澘");
+      return;
+    }
+    selectedBusinessType.value = type;
+    submitDialog.step = 2;
+  }
+
+  function backToBusinessTypePick() {
+    selectedBusinessType.value = "";
     submitDialog.step = 1;
+  }
+
+  function backToTemplatePick() {
+    submitDialog.step = 2;
   }
 
   async function submitInstanceForm() {
@@ -304,9 +334,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) {
@@ -321,7 +351,7 @@
           submitForm,
           activeTemplate: activeTemplate.value,
           userStore,
-          flowNodes: flowCheck.nodes,
+          flowNodes: bindingCheck.nodes,
         })
       );
       submitDialog.visible = false;
@@ -343,9 +373,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) {
@@ -359,7 +389,7 @@
         buildInstanceDto({
           submitForm,
           activeTemplate: activeTemplate.value,
-          flowNodes: flowCheck.nodes,
+          flowNodes: bindingCheck.nodes,
           existingRow: submitEditRow.value,
         })
       );
@@ -451,6 +481,9 @@
   return {
     Search,
     APPROVAL_TYPE_OPTIONS,
+    APPROVAL_STATUS_SEARCH_OPTIONS,
+    searchBusinessTypeOptions,
+    loadSearchBusinessTypeOptions,
     approvalTypeLabel,
     approvalStatusLabel,
     approvalStatusTagType,
@@ -474,7 +507,12 @@
     activeTemplate,
     submitFormFields,
     submitFormRules,
+    submitBusinessTypeOptions,
     submitTemplateCards,
+    selectedBusinessType,
+    selectedBusinessTypeLabel,
+    businessTypeLabel,
+    countTemplatesByBusinessType,
     submitTemplatesLoading,
     handleQuery,
     resetSearch,
@@ -482,7 +520,9 @@
     resetSubmitDialogState,
     openSubmitDialog,
     openEditDialog,
+    onBusinessTypePick,
     onTemplatePick,
+    backToBusinessTypePick,
     backToTemplatePick,
     submitInstanceForm,
     submitNewApproval,

--
Gitblit v1.9.3