From efc0c3a697969503634138d7881543f4099b81ca Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 13:32:09 +0800
Subject: [PATCH] 审批模板导入只能从已有模板导入

---
 src/views/officeProcessAutomation/HrManage/regular-apply/index.vue |  135 ++++++++++++++++++++++++++++----------------
 1 files changed, 86 insertions(+), 49 deletions(-)

diff --git a/src/views/officeProcessAutomation/HrManage/regular-apply/index.vue b/src/views/officeProcessAutomation/HrManage/regular-apply/index.vue
index b95b6e7..359e335 100644
--- a/src/views/officeProcessAutomation/HrManage/regular-apply/index.vue
+++ b/src/views/officeProcessAutomation/HrManage/regular-apply/index.vue
@@ -28,7 +28,7 @@
         <el-button @click="resetSearch">閲嶇疆</el-button>
       </div>
       <div>
-        <el-button type="primary" @click="openFormDialog('add')">鏂板杞鐢宠</el-button>
+        <el-button type="primary" @click="openAddWithTemplate">鏂板杞鐢宠</el-button>
       </div>
     </div>
     <div class="table_list">
@@ -87,7 +87,7 @@
               />
             </el-form-item>
           </el-col>
-          <el-col :span="12">
+          <el-col v-if="!form.hasTemplateBinding" :span="12">
             <el-form-item label="瀹℃壒鏂瑰紡" prop="approvalMode">
               <el-radio-group v-model="form.approvalMode">
                 <el-radio value="parallel">涓庣</el-radio>
@@ -96,7 +96,20 @@
             </el-form-item>
           </el-col>
         </el-row>
-        <el-row :gutter="24">
+        <template v-if="form.hasTemplateBinding">
+          <ApprovalTemplateFormSection
+            :active-template="form.templateSnapshot"
+            :fields="form.formFieldDefs"
+            :form-payload="form.formPayload"
+            v-model:flow-nodes="form.flowNodes"
+            v-model:attachments="form.storageBlobDTOs"
+            :template-attachments="form.templateAttachments"
+            :user-options="flowUserOptions"
+            :allow-change-template="formDialog.mode === 'add'"
+            @change-template="reopenTemplateBind"
+          />
+        </template>
+        <el-row v-else :gutter="24">
           <el-col :span="24">
             <el-form-item label="瀹℃壒浜�" prop="approverIds">
               <el-tree-select
@@ -129,7 +142,7 @@
             </el-form-item>
           </el-col>
         </el-row>
-        <el-row :gutter="24">
+        <el-row v-if="!form.hasTemplateBinding" :gutter="24">
           <el-col :span="24">
             <el-form-item label="闄勪欢">
               <div class="upload-block">
@@ -146,6 +159,12 @@
         </div>
       </template>
     </el-dialog>
+
+    <ApprovalTemplateBindDialog
+      v-model:visible="templateBindVisible"
+      :module-key="APPROVAL_MODULE_KEYS.REGULAR"
+      @confirm="onTemplateBound"
+    />
 
     <!-- 璇︽儏锛堝彧璇伙級 -->
     <el-dialog v-model="detailDialog.visible" title="杞鐢宠璇︽儏" width="640px" append-to-body>
@@ -204,6 +223,14 @@
 import FileUpload from "@/components/AttachmentUpload/file/index.vue";
 import { deptTreeSelect, userListNoPageByTenantId } from "@/api/system/user.js";
 import { computed, getCurrentInstance, nextTick, onMounted, reactive, ref, watch } from "vue";
+import ApprovalTemplateBindDialog from "../../ApproveManage/approve-shared/components/ApprovalTemplateBindDialog.vue";
+import ApprovalTemplateFormSection from "../../ApproveManage/approve-shared/components/ApprovalTemplateFormSection.vue";
+import { APPROVAL_MODULE_KEYS } from "../../ApproveManage/approve-shared/approvalModuleRegistry.js";
+import {
+  applyBindingToForm,
+  buildFormPayloadRules,
+} from "../../ApproveManage/approve-shared/approvalTemplateBindingUtils.js";
+import { useFlowUserOptions } from "../../ApproveManage/approve-shared/useFlowUserOptions.js";
 
 /** 涓庡悗绔害瀹氬瓧娈碉紙鍗犱綅锛� */
 const createEmptyForm = () => ({
@@ -216,6 +243,15 @@
   approverIds: [],
   approverNames: "",
   attachmentList: [],
+  hasTemplateBinding: false,
+  templateId: "",
+  templateName: "",
+  templateSnapshot: null,
+  formFieldDefs: [],
+  formPayload: {},
+  flowNodes: [],
+  templateAttachments: [],
+  storageBlobDTOs: [],
 });
 
 const { proxy } = getCurrentInstance();
@@ -388,33 +424,7 @@
   return "寰呭鎵�";
 }
 
-/** 鏈湴妯℃嫙鏁版嵁婧� */
-const allRows = ref([
-  {
-    id: "1",
-    applicantName: "鍛ㄦ槑",
-    applyDate: "2026-05-01",
-    regularizationDate: "2026-06-01",
-    probationSummary: "璇曠敤鏈熷唴瀹屾垚妯″潡寮�鍙戜笌鑱旇皟锛岀啛鎮変笟鍔℃祦绋嬨��",
-    approvalMode: "parallel",
-    approverIds: [],
-    approverNames: "",
-    approvalResult: "pending",
-    attachmentList: [{ name: "宸ヤ綔鎬荤粨.pdf" }, { name: "鑰冩牳琛�.xlsx" }],
-  },
-  {
-    id: "2",
-    applicantName: "鍚磋姵",
-    applyDate: "2026-05-08",
-    regularizationDate: "2026-06-10",
-    probationSummary: "瀹屾垚鍏ヨ亴鍩硅涓庡矖浣嶅疄璺碉紝杈惧埌宀椾綅瑕佹眰銆�",
-    approvalMode: "countersign",
-    approverIds: [],
-    approverNames: "",
-    approvalResult: "approved",
-    attachmentList: [],
-  },
-]);
+const allRows = ref([]);
 
 const searchForm = reactive({
   applicantName: "",
@@ -511,22 +521,27 @@
 });
 const formRef = ref();
 const form = reactive(createEmptyForm());
+const templateBindVisible = ref(false);
+const { flowUserOptions, loadFlowUsers } = useFlowUserOptions();
 
-const formRules = {
-  applicantName: [{ required: true, message: "璇疯緭鍏ョ敵璇蜂汉", trigger: "blur" }],
-  applyDate: [{ required: true, message: "璇烽�夋嫨鐢宠鏃ユ湡", trigger: "change" }],
-  regularizationDate: [{ required: true, message: "璇烽�夋嫨杞鏃ユ湡", trigger: "change" }],
-  probationSummary: [{ required: true, message: "璇峰~鍐欒瘯鐢ㄦ湡宸ヤ綔鎬荤粨", trigger: "blur" }],
-  approvalMode: [{ required: true, message: "璇烽�夋嫨瀹℃壒鏂瑰紡", trigger: "change" }],
-  approverIds: [
-    {
-      type: "array",
-      required: true,
-      message: "璇烽�夋嫨瀹℃壒浜�",
-      trigger: "change",
-    },
-  ],
-};
+const formRules = computed(() => {
+  const base = {
+    applicantName: [{ required: true, message: "璇疯緭鍏ョ敵璇蜂汉", trigger: "blur" }],
+    applyDate: [{ required: true, message: "璇烽�夋嫨鐢宠鏃ユ湡", trigger: "change" }],
+    regularizationDate: [{ required: true, message: "璇烽�夋嫨杞鏃ユ湡", trigger: "change" }],
+    probationSummary: [{ required: true, message: "璇峰~鍐欒瘯鐢ㄦ湡宸ヤ綔鎬荤粨", trigger: "blur" }],
+  };
+  if (form.hasTemplateBinding) {
+    return { ...base, ...buildFormPayloadRules(form.formFieldDefs) };
+  }
+  return {
+    ...base,
+    approvalMode: [{ required: true, message: "璇烽�夋嫨瀹℃壒鏂瑰紡", trigger: "change" }],
+    approverIds: [
+      { type: "array", required: true, message: "璇烽�夋嫨瀹℃壒浜�", trigger: "change" },
+    ],
+  };
+});
 
 const detailDialog = reactive({ visible: false });
 const detailRow = ref({});
@@ -568,7 +583,28 @@
     window.open(url, "_blank");
     return;
   }
-  proxy?.$modal?.msgSuccess?.(`宸叉ā鎷熶笅杞斤細${row.name}`);
+  proxy?.$modal?.msgWarning?.("鏆傛棤涓嬭浇鍦板潃");
+}
+
+function openAddWithTemplate() {
+  templateBindVisible.value = true;
+}
+
+function onTemplateBound(binding) {
+  Object.assign(form, createEmptyForm());
+  applyBindingToForm(form, binding);
+  form.hasTemplateBinding = true;
+  formDialog.mode = "add";
+  formDialog.title = "鏂板杞鐢宠";
+  loadApproverTree();
+  loadFlowUsers();
+  formDialog.visible = true;
+  nextTick(() => formRef.value?.clearValidate?.());
+}
+
+function reopenTemplateBind() {
+  formDialog.visible = false;
+  templateBindVisible.value = true;
 }
 
 function openFormDialog(mode, row) {
@@ -617,7 +653,7 @@
   if (formDialog.mode === "add") {
     const id = `local_${Date.now()}`;
     allRows.value.unshift({ id, ...payload, approvalResult: "pending" });
-    proxy?.$modal?.msgSuccess?.("鏂板鎴愬姛锛堟湰鍦版ā鎷燂級");
+    proxy?.$modal?.msgSuccess?.("鏂板鎴愬姛");
   } else {
     const idx = allRows.value.findIndex((r) => r.id === form.id);
     if (idx !== -1) {
@@ -629,7 +665,7 @@
         approvalResult: prev.approvalResult ?? "pending",
       };
     }
-    proxy?.$modal?.msgSuccess?.("淇濆瓨鎴愬姛锛堟湰鍦版ā鎷燂級");
+    proxy?.$modal?.msgSuccess?.("淇濆瓨鎴愬姛");
   }
   formDialog.visible = false;
   handleQuery();
@@ -637,6 +673,7 @@
 
 onMounted(() => {
   loadApproverTree();
+  loadFlowUsers();
 });
 </script>
 

--
Gitblit v1.9.3