From 0a58164ce2ea3f1a2b46781757d78b94b212883b Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 15:13:49 +0800
Subject: [PATCH] 工作交接/调岗申请/转正申请/请假申请/加班申请新增调用模板

---
 src/views/officeProcessAutomation/HrManage/work-handover/index.vue |  495 ++++++++++++++++++------------------------------------
 1 files changed, 167 insertions(+), 328 deletions(-)

diff --git a/src/views/officeProcessAutomation/HrManage/work-handover/index.vue b/src/views/officeProcessAutomation/HrManage/work-handover/index.vue
index ddf6acd..ed2e8d0 100644
--- a/src/views/officeProcessAutomation/HrManage/work-handover/index.vue
+++ b/src/views/officeProcessAutomation/HrManage/work-handover/index.vue
@@ -34,7 +34,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">
@@ -52,122 +52,41 @@
 
     <!-- 鏂板 / 缂栬緫 -->
     <el-dialog
+      v-if="formDialog.visible"
       v-model="formDialog.visible"
       :title="formDialog.title"
-      width="720px"
+      width="960px"
       append-to-body
       destroy-on-close
       class="work-handover-form-dialog"
       @closed="onFormClosed"
     >
-      <el-form ref="formRef" :model="form" :rules="formRules" label-width="120px" class="work-handover-form">
-        <el-row :gutter="24">
-          <el-col :span="24">
-            <el-form-item label="鐢宠浜�" prop="applicantId">
-              <el-select
-                v-model="form.applicantId"
-                filterable
-                remote
-                clearable
-                reserve-keyword
-                placeholder="璇烽�夋嫨鎴栨悳绱㈢敵璇蜂汉"
-                style="width: 100%"
-                :remote-method="remoteSearchApplicantForm"
-                :loading="applicantFormSearchLoading"
-                @change="onApplicantChange"
-              >
-                <el-option
-                  v-for="u in applicantFormOptions"
-                  :key="u.userId"
-                  :label="userSelectLabel(u)"
-                  :value="u.userId"
-                />
-              </el-select>
-            </el-form-item>
-          </el-col>
-        </el-row>
-        <el-row :gutter="24">
-          <el-col :span="12">
-            <el-form-item label="绂昏亴鏃ユ湡" prop="leaveDate">
-              <el-date-picker
-                v-model="form.leaveDate"
-                type="date"
-                placeholder="璇烽�夋嫨绂昏亴鏃ユ湡"
-                format="YYYY-MM-DD"
-                value-format="YYYY-MM-DD"
-                style="width: 100%"
-              />
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="浜ゆ帴鐘舵��" prop="handoverStatus">
-              <el-select v-model="form.handoverStatus" placeholder="璇烽�夋嫨浜ゆ帴鐘舵��" style="width: 100%">
-                <el-option v-for="o in handoverStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
-              </el-select>
-            </el-form-item>
-          </el-col>
-        </el-row>
-        <el-row :gutter="24">
-          <el-col :span="12">
-            <el-form-item label="浜ゆ帴绫诲瀷" prop="handoverType">
-              <el-select v-model="form.handoverType" placeholder="璇烽�夋嫨浜ゆ帴绫诲瀷" style="width: 100%">
-                <el-option v-for="o in handoverTypeOptions" :key="o.value" :label="o.label" :value="o.value" />
-              </el-select>
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="浜ゆ帴浜�" prop="handoverPersonId">
-              <el-select
-                v-model="form.handoverPersonId"
-                filterable
-                remote
-                clearable
-                reserve-keyword
-                placeholder="璇烽�夋嫨鎴栨悳绱氦鎺ヤ汉"
-                style="width: 100%"
-                :remote-method="remoteSearchHandoverPerson"
-                :loading="handoverPersonSearchLoading"
-                @change="onHandoverPersonChange"
-              >
-                <el-option
-                  v-for="u in handoverPersonOptions"
-                  :key="u.userId"
-                  :label="userSelectLabel(u)"
-                  :value="u.userId"
-                />
-              </el-select>
-            </el-form-item>
-          </el-col>
-        </el-row>
-        <el-row :gutter="24">
-          <el-col :span="12">
-            <el-form-item label="瀹℃壒鏂瑰紡" prop="approvalMode">
-              <el-radio-group v-model="form.approvalMode">
-                <el-radio value="parallel">涓庣</el-radio>
-                <el-radio value="countersign">浼氱</el-radio>
-              </el-radio-group>
-            </el-form-item>
-          </el-col>
-        </el-row>
-        <el-row :gutter="24">
-          <el-col :span="24">
-            <el-form-item label="瀹℃壒浜�" prop="approverIds">
-              <el-tree-select
-                v-model="form.approverIds"
-                :data="approverTreeData"
-                multiple
-                collapse-tags
-                collapse-tags-tooltip
-                :max-collapse-tags="2"
-                :render-after-expand="false"
-                placeholder="璇烽�夋嫨瀹℃壒浜猴紙鍙閫夛級"
-                style="width: 100%"
-                :props="{ value: 'id', label: 'label', children: 'children', disabled: 'disabled' }"
-                check-strictly
-              />
-            </el-form-item>
-          </el-col>
-        </el-row>
+      <el-form ref="formRef" :model="form" :rules="formRules" label-width="140px" class="work-handover-form">
+        <el-form-item v-if="form.templateSnapshot" label="瀹℃壒妯℃澘">
+          <span class="template-name">{{ form.templateSnapshot.label || form.templateName }}</span>
+          <el-button
+            v-if="formDialog.mode === 'add'"
+            type="primary"
+            link
+            class="ml12"
+            @click="reopenTemplateBind"
+          >
+            鏇存崲妯℃澘
+          </el-button>
+        </el-form-item>
+        <FormPayloadFields :fields="form.formFieldDefs" :form-payload="form.formPayload" :columns="2" />
+        <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"
+          flow-attachments-only
+          hide-template-name
+          :allow-change-template="false"
+        />
       </el-form>
       <template #footer>
         <div class="dialog-footer">
@@ -176,6 +95,14 @@
         </div>
       </template>
     </el-dialog>
+
+    <ApprovalTemplateBindDialog
+      v-model:visible="templateBindVisible"
+      :module-key="APPROVAL_MODULE_KEYS.WORK_HANDOVER"
+      skip-form-confirm
+      @confirm="onTemplateBound"
+      @closed="onTemplateBindClosed"
+    />
 
     <!-- 璇︽儏 -->
     <el-dialog v-model="detailDialog.visible" title="宸ヤ綔浜ゆ帴璇︽儏" width="560px" append-to-body>
@@ -199,8 +126,18 @@
 </template>
 
 <script setup>
-import { deptTreeSelect, userListNoPageByTenantId } from "@/api/system/user.js";
+import { 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 FormPayloadFields from "../../ApproveManage/approve-list/components/FormPayloadFields.vue";
+import { APPROVAL_MODULE_KEYS } from "../../ApproveManage/approve-shared/approvalModuleRegistry.js";
+import {
+  applyBindingToForm,
+  buildFormPayloadRules,
+  validateTemplateBinding,
+} from "../../ApproveManage/approve-shared/approvalTemplateBindingUtils.js";
+import { useFlowUserOptions } from "../../ApproveManage/approve-shared/useFlowUserOptions.js";
 
 const { proxy } = getCurrentInstance();
 
@@ -233,9 +170,15 @@
   handoverType: "resignation",
   handoverPersonId: "",
   handoverPersonName: "",
-  approvalMode: "parallel",
-  approverIds: [],
-  approverNames: "",
+  hasTemplateBinding: false,
+  templateId: "",
+  templateName: "",
+  templateSnapshot: null,
+  formFieldDefs: [],
+  formPayload: {},
+  flowNodes: [],
+  templateAttachments: [],
+  storageBlobDTOs: [],
 });
 
 const allUsersCache = ref([]);
@@ -288,49 +231,6 @@
   }
 }
 
-const applicantFormSearchLoading = ref(false);
-const applicantFormOptions = ref([]);
-
-async function remoteSearchApplicantForm(query) {
-  applicantFormSearchLoading.value = true;
-  try {
-    if (!allUsersCache.value.length) {
-      await loadUserPool();
-    }
-    applicantFormOptions.value = filterUsersByQuery(query);
-  } finally {
-    applicantFormSearchLoading.value = false;
-  }
-}
-
-function onApplicantChange(uid) {
-  const u = userById(uid);
-  form.applicantName = u ? u.nickName || u.userName || "" : "";
-}
-
-const handoverPersonSearchLoading = ref(false);
-const handoverPersonOptions = ref([]);
-
-async function remoteSearchHandoverPerson(query) {
-  handoverPersonSearchLoading.value = true;
-  try {
-    if (!allUsersCache.value.length) {
-      await loadUserPool();
-    }
-    handoverPersonOptions.value = filterUsersByQuery(query);
-  } finally {
-    handoverPersonSearchLoading.value = false;
-  }
-}
-
-function onHandoverPersonChange(uid) {
-  const u = userById(uid);
-  form.handoverPersonName = u ? u.nickName || u.userName || "" : "";
-}
-
-const approverTreeData = ref([]);
-const approverLabelMap = ref({});
-
 function unwrapArray(payload) {
   if (Array.isArray(payload)) return payload;
   if (payload && Array.isArray(payload.data)) return payload.data;
@@ -338,146 +238,10 @@
   return [];
 }
 
-function filterDisabledDept(deptList) {
-  if (!Array.isArray(deptList)) return [];
-  return deptList.filter((dept) => {
-    if (dept.disabled) return false;
-    if (dept.children?.length) {
-      dept.children = filterDisabledDept(dept.children);
-    }
-    return true;
-  });
-}
-
-function getUserDeptId(u) {
-  return u.deptId ?? u.sysDeptId ?? u.dept?.deptId ?? u.dept?.id ?? u.dept_id;
-}
-
-function getDeptNodeKey(node) {
-  const k = node?.id ?? node?.value ?? node?.deptId;
-  if (k == null || k === "") return null;
-  return k;
-}
-
 function isActiveUser(u) {
   if (u.delFlag === "2" || u.delFlag === 2) return false;
   if (u.status == null) return true;
   return String(u.status) === "0";
-}
-
-function userToTreeLeaf(u) {
-  return {
-    id: String(u.userId ?? u.id),
-    label: u.nickName || u.userName || `鐢ㄦ埛${u.userId ?? u.id}`,
-  };
-}
-
-function buildUsersByDeptId(users) {
-  const map = new Map();
-  const unassigned = [];
-  for (const u of users) {
-    if (!isActiveUser(u)) continue;
-    const did = getUserDeptId(u);
-    if (did == null || did === "" || did === 0 || did === "0") {
-      unassigned.push(u);
-      continue;
-    }
-    const k = String(did);
-    if (!map.has(k)) map.set(k, []);
-    map.get(k).push(u);
-  }
-  return { map, unassigned };
-}
-
-function collectUserLabels(nodes, map) {
-  (nodes || []).forEach((n) => {
-    if (n.children?.length) {
-      collectUserLabels(n.children, map);
-    } else if (n.id != null && !String(n.id).startsWith("dept_")) {
-      map[String(n.id)] = n.label;
-    }
-  });
-}
-
-function mergeDeptTreeWithUsers(nodes, usersByDept) {
-  if (!Array.isArray(nodes)) return [];
-  const out = [];
-  for (const node of nodes) {
-    const deptIdRaw = getDeptNodeKey(node);
-    if (deptIdRaw == null) continue;
-    const sub = mergeDeptTreeWithUsers(node.children || [], usersByDept);
-    const usersHere = usersByDept.get(String(deptIdRaw)) || [];
-    const userChildren = usersHere.map(userToTreeLeaf);
-    const children = [...sub, ...userChildren];
-    if (!children.length) continue;
-    out.push({
-      id: `dept_${deptIdRaw}`,
-      label: node.label ?? node.deptName ?? "閮ㄩ棬",
-      disabled: true,
-      children,
-    });
-  }
-  return out;
-}
-
-function buildFlatApproverTree(users) {
-  const list = users.filter(isActiveUser).map(userToTreeLeaf);
-  if (!list.length) return [];
-  return [
-    {
-      id: "dept_all_users",
-      label: "绯荤粺鐢ㄦ埛",
-      disabled: true,
-      children: list,
-    },
-  ];
-}
-
-async function loadApproverTree() {
-  try {
-    const needFetchUsers = !allUsersCache.value.length;
-    const [deptRes, userRes] = await Promise.all([
-      deptTreeSelect(),
-      needFetchUsers ? userListNoPageByTenantId() : Promise.resolve(null),
-    ]);
-    let rawTree = unwrapArray(deptRes);
-    rawTree = rawTree.length ? JSON.parse(JSON.stringify(rawTree)) : [];
-    let deptTree = filterDisabledDept(JSON.parse(JSON.stringify(rawTree)));
-    if (!deptTree.length && rawTree.length) {
-      deptTree = JSON.parse(JSON.stringify(rawTree));
-    }
-    let users = needFetchUsers ? unwrapArray(userRes) : [...allUsersCache.value];
-    if (needFetchUsers && users.length) {
-      allUsersCache.value = users;
-    }
-    const { map: usersByDept, unassigned } = buildUsersByDeptId(users);
-    let merged = mergeDeptTreeWithUsers(deptTree, usersByDept);
-    if (unassigned.length) {
-      merged.push({
-        id: "dept_unassigned",
-        label: "鏈垎閰嶉儴闂�",
-        disabled: true,
-        children: unassigned.map(userToTreeLeaf),
-      });
-    }
-    if (!merged.length && users.length) {
-      merged = buildFlatApproverTree(users);
-    }
-    approverTreeData.value = merged;
-    const map = {};
-    collectUserLabels(merged, map);
-    approverLabelMap.value = map;
-  } catch {
-    approverTreeData.value = [];
-    approverLabelMap.value = {};
-    proxy?.$modal?.msgWarning?.("瀹℃壒浜烘暟鎹姞杞藉け璐ワ紝璇锋鏌ョ綉缁滄垨绋嶅悗閲嶈瘯");
-  }
-}
-
-function resolveApproverNames(ids) {
-  if (!ids?.length) return "";
-  const map = approverLabelMap.value;
-  return ids.map((id) => map[String(id)] || id).join("銆�");
 }
 
 function approvalModeLabel(mode) {
@@ -602,16 +366,11 @@
 });
 const formRef = ref();
 const form = reactive(createEmptyForm());
+const templateBindVisible = ref(false);
+const pendingTemplateBinding = ref(null);
+const { flowUserOptions, loadFlowUsers } = useFlowUserOptions();
 
-const formRules = {
-  applicantId: [{ required: true, message: "璇烽�夋嫨鐢宠浜�", trigger: "change" }],
-  leaveDate: [{ required: true, message: "璇烽�夋嫨绂昏亴鏃ユ湡", trigger: "change" }],
-  handoverStatus: [{ required: true, message: "璇烽�夋嫨浜ゆ帴鐘舵��", trigger: "change" }],
-  handoverType: [{ required: true, message: "璇烽�夋嫨浜ゆ帴绫诲瀷", trigger: "change" }],
-  handoverPersonId: [{ required: true, message: "璇烽�夋嫨浜ゆ帴浜�", trigger: "change" }],
-  approvalMode: [{ required: true, message: "璇烽�夋嫨瀹℃壒鏂瑰紡", trigger: "change" }],
-  approverIds: [{ type: "array", required: true, message: "璇烽�夋嫨瀹℃壒浜�", trigger: "change" }],
-};
+const formRules = computed(() => buildFormPayloadRules(form.formFieldDefs));
 
 const detailDialog = reactive({ visible: false });
 const detailRow = ref({});
@@ -642,31 +401,83 @@
   detailDialog.visible = true;
 }
 
-function ensureUserInOptions(optionsRef, row, idKey, nameKey) {
-  const id = row?.[idKey];
-  if (id == null || id === "") return;
-  const sid = String(id);
-  if (!optionsRef.value.some((u) => String(u.userId ?? u.id) === sid)) {
-    optionsRef.value = [
-      {
-        userId: id,
-        nickName: row[nameKey],
-        userName: row.applicantUserName,
-      },
-      ...optionsRef.value,
-    ];
+function openAddWithTemplate() {
+  formDialog.visible = false;
+  pendingTemplateBinding.value = null;
+  templateBindVisible.value = true;
+}
+
+function onTemplateBound(binding) {
+  pendingTemplateBinding.value = binding;
+}
+
+async function onTemplateBindClosed() {
+  const binding = pendingTemplateBinding.value;
+  if (!binding) return;
+  pendingTemplateBinding.value = null;
+  await openFormWithBinding(binding);
+}
+
+async function openFormWithBinding(binding) {
+  Object.assign(form, createEmptyForm());
+  applyBindingToForm(form, binding);
+  form.hasTemplateBinding = true;
+  formDialog.mode = "add";
+  formDialog.title = "鏂板宸ヤ綔浜ゆ帴";
+  await Promise.all([loadUserPool(), loadFlowUsers()]);
+  await syncHandoverFieldsFromPayload();
+  formDialog.visible = true;
+  nextTick(() => formRef.value?.clearValidate?.());
+}
+
+function reopenTemplateBind() {
+  formDialog.visible = false;
+  pendingTemplateBinding.value = null;
+  templateBindVisible.value = true;
+}
+
+function syncApplicantFromUser(uid) {
+  const u = userById(uid);
+  form.applicantId = uid != null && uid !== "" ? uid : "";
+  form.applicantName = u ? u.nickName || u.userName || "" : "";
+}
+
+function syncHandoverPersonFromUser(uid) {
+  const u = userById(uid);
+  form.handoverPersonId = uid != null && uid !== "" ? uid : "";
+  form.handoverPersonName = u ? u.nickName || u.userName || "" : "";
+}
+
+/** 浠庢ā鏉垮~鎶ラ」鍚屾鍒楄〃灞曠ず瀛楁 */
+async function syncHandoverFieldsFromPayload() {
+  const defs = form.formFieldDefs || [];
+  const payload = form.formPayload || {};
+  for (const f of defs) {
+    const label = String(f.label || "");
+    const val = payload[f.key];
+    if (label.includes("鐢宠浜�") && !label.includes("浜ゆ帴浜�")) {
+      syncApplicantFromUser(val);
+    } else if (label.includes("浜ゆ帴浜�")) {
+      syncHandoverPersonFromUser(val);
+    } else if (label.includes("绂昏亴") && f.type === "date") {
+      form.leaveDate = val || "";
+    } else if (label.includes("浜ゆ帴鐘舵��")) {
+      form.handoverStatus = val != null && val !== "" ? val : form.handoverStatus;
+    } else if (label.includes("浜ゆ帴绫诲瀷")) {
+      form.handoverType = val != null && val !== "" ? val : form.handoverType;
+    }
   }
 }
 
 async function openFormDialog(mode, row) {
+  if (mode === "edit" && row && !row.hasTemplateBinding) {
+    proxy?.$modal?.msgWarning?.("璇ヨ褰曚负鏃х増鏁版嵁锛岃閲嶆柊閫氳繃妯℃澘鍙戣捣鐢宠");
+    return;
+  }
   formDialog.mode = mode;
-  formDialog.title = mode === "add" ? "鏂板宸ヤ綔浜ゆ帴" : "缂栬緫宸ヤ綔浜ゆ帴";
-  loadApproverTree();
+  formDialog.title = "缂栬緫宸ヤ綔浜ゆ帴";
   Object.assign(form, createEmptyForm());
-  await Promise.all([remoteSearchApplicantForm(""), remoteSearchHandoverPerson("")]);
   if (mode === "edit" && row) {
-    ensureUserInOptions(applicantFormOptions, row, "applicantId", "applicantName");
-    ensureUserInOptions(handoverPersonOptions, row, "handoverPersonId", "handoverPersonName");
     Object.assign(form, {
       id: row.id,
       applicantId: row.applicantId,
@@ -676,10 +487,19 @@
       handoverType: row.handoverType,
       handoverPersonId: row.handoverPersonId,
       handoverPersonName: row.handoverPersonName,
-      approvalMode: row.approvalMode,
-      approverIds: (row.approverIds || []).map((id) => String(id)),
-      approverNames: row.approverNames,
+      hasTemplateBinding: true,
+      templateId: row.templateId,
+      templateName: row.templateName,
+      templateSnapshot: row.templateSnapshot,
+      formFieldDefs: row.formFieldDefs || [],
+      formPayload: JSON.parse(JSON.stringify(row.formPayload || {})),
+      flowNodes: JSON.parse(JSON.stringify(row.flowNodes || [])),
+      templateAttachments: JSON.parse(JSON.stringify(row.templateAttachments || [])),
+      storageBlobDTOs: JSON.parse(JSON.stringify(row.storageBlobDTOs || [])),
     });
+    await loadUserPool();
+    await syncHandoverFieldsFromPayload();
+    loadFlowUsers();
   }
   formDialog.visible = true;
   nextTick(() => formRef.value?.clearValidate?.());
@@ -695,7 +515,13 @@
   } catch {
     return;
   }
-  form.approverNames = resolveApproverNames(form.approverIds);
+  const flowCheck = validateTemplateBinding({ flowNodes: form.flowNodes });
+  if (!flowCheck.ok) {
+    proxy?.$modal?.msgWarning?.(flowCheck.message || "璇峰畬鍠勫鎵规祦绋�");
+    return;
+  }
+  form.flowNodes = flowCheck.nodes;
+  await syncHandoverFieldsFromPayload();
   const payload = {
     applicantId: form.applicantId,
     applicantName: form.applicantName,
@@ -704,9 +530,15 @@
     handoverType: form.handoverType,
     handoverPersonId: form.handoverPersonId,
     handoverPersonName: form.handoverPersonName,
-    approvalMode: form.approvalMode,
-    approverIds: [...form.approverIds],
-    approverNames: form.approverNames,
+    hasTemplateBinding: true,
+    templateId: form.templateId,
+    templateName: form.templateName,
+    templateSnapshot: form.templateSnapshot,
+    formFieldDefs: form.formFieldDefs,
+    formPayload: JSON.parse(JSON.stringify(form.formPayload || {})),
+    flowNodes: JSON.parse(JSON.stringify(form.flowNodes || [])),
+    templateAttachments: JSON.parse(JSON.stringify(form.templateAttachments || [])),
+    storageBlobDTOs: JSON.parse(JSON.stringify(form.storageBlobDTOs || [])),
   };
   if (formDialog.mode === "add") {
     const id = `local_${Date.now()}`;
@@ -734,7 +566,7 @@
 
 onMounted(async () => {
   await loadUserPool();
-  loadApproverTree();
+  loadFlowUsers();
   await remoteSearchApplicant("");
 });
 </script>
@@ -763,4 +595,11 @@
 .work-handover-form-dialog :deep(.el-dialog__body) {
   padding-top: 12px;
 }
+.template-name {
+  font-weight: 600;
+  color: var(--el-text-color-primary);
+}
+.ml12 {
+  margin-left: 12px;
+}
 </style>

--
Gitblit v1.9.3