Procházet zdrojové kódy

录用审批「入职部门」下拉修复无数据:原来先把组织平铺列表按父链回溯算出每个部门的归属机构(legalId)再按 form.deptId 过滤,父链断裂时部门会被误判成根节点整批滤掉,下拉空白(2026-11-09 用户反馈);改为与转正页 positionCascade 同口径的向下递归——以所选机构为根按 parentId 遍历整棵子树收集选项(带环保护),allDepartments 只保留组织原始平铺列表;提交兜底改为 orgRootOf(deptId) 按 parentId 向上回溯根节点反推所属机构

lihaiting před 2 týdny
rodič
revize
e1c2118784

+ 43 - 30
src/views/hiring/hiringApproval/components/ApprovalFormDrawer.vue

@@ -397,12 +397,29 @@ export default {
       return window.innerWidth < 720 ? "96%" : "960px";
     },
     departmentOptions() {
-      if (this.form.deptId == null || this.form.deptId === "") {
-        return [];
-      }
-      return this.allDepartments.filter(
-        (item) => String(item.legalId) === String(this.form.deptId),
-      );
+      /* 入职部门:从所选机构往下递归收集整棵子树(与转正页 positionCascade mixin 同口径)。
+         旧实现按 parentId 向上回溯找根再过滤,父链断裂时部门会被误判成根节点整批滤掉,
+         表现为下拉「无数据」(2026-11-09 用户反馈),改为向下遍历规避。 */
+      const rootId = this.form.deptId;
+      if (rootId == null || rootId === "") return [];
+      const byParent = new Map();
+      this.allDepartments.forEach((item) => {
+        const key = String(item.parentId);
+        if (!byParent.has(key)) byParent.set(key, []);
+        byParent.get(key).push(item);
+      });
+      const options = [];
+      const seen = new Set();
+      const walk = (parentId) => {
+        (byParent.get(String(parentId)) || []).forEach((item) => {
+          if (seen.has(String(item.id))) return;
+          seen.add(String(item.id));
+          options.push({ id: item.id, name: item.name });
+          walk(item.id);
+        });
+      };
+      walk(rootId);
+      return options;
     },
   },
   watch: {
@@ -657,36 +674,15 @@ export default {
       try {
         /* 所属机构选项:登录缓存 loginChangeGroupVOList */
         this.legalEntities = getOrgOptions();
-        /* 部门选项仍需组织列表回溯归属机构 */
+        /* 部门选项:组织平铺列表(入职部门下拉按 parentId 向下遍历,见 departmentOptions) */
         const list = await listOrganizations().catch(() => []);
-        const records = (Array.isArray(list) ? list : asList(list))
+        this.allDepartments = (Array.isArray(list) ? list : asList(list))
           .map((item) => ({
             id: item.id,
             name: item.name || item.orgName || item.groupName || "",
             parentId: item.parentId,
           }))
           .filter((item) => item.id != null && item.name);
-        const byId = new Map(records.map((item) => [String(item.id), item]));
-        this.allDepartments = records
-          .map((item) => {
-            let current = item;
-            const seen = new Set();
-            while (
-              current &&
-              byId.has(String(current.parentId)) &&
-              !seen.has(String(current.id))
-            ) {
-              seen.add(String(current.id));
-              current = byId.get(String(current.parentId));
-            }
-            return {
-              id: item.id,
-              name: item.name,
-              legalId: current?.id,
-            };
-          })
-          /* 公司根节点(上级链顶到自己)不是部门,不进入职部门下拉 */
-          .filter((item) => String(item.id) !== String(item.legalId));
       } catch (error) {
         /* 机构选项来自登录缓存,不因组织列表接口失败而清空 */
         this.allDepartments = [];
@@ -770,12 +766,29 @@ export default {
         null
       );
     },
+    /** 按组织 parentId 向上回溯根节点(仅提交兜底用:deptId 为空时反推所属机构) */
+    orgRootOf(id) {
+      const byId = new Map(
+        this.allDepartments.map((item) => [String(item.id), item]),
+      );
+      let current = this.findDept(id);
+      const seen = new Set();
+      while (
+        current &&
+        byId.has(String(current.parentId)) &&
+        !seen.has(String(current.id))
+      ) {
+        seen.add(String(current.id));
+        current = byId.get(String(current.parentId));
+      }
+      return current?.id ?? null;
+    },
     /** 提交前把入职部门 / 所属机构的 id、名称同步到接口字段 */
     syncOrgAndDeptFields() {
       const departmentId =
         this.form.departmentId ?? this.form.hiringDeptId ?? null;
       const dept = this.findDept(departmentId);
-      const orgId = this.form.deptId ?? dept?.legalId ?? null;
+      const orgId = this.form.deptId ?? this.orgRootOf(departmentId) ?? null;
       const org = this.findOrg(orgId);
       this.form.deptId = orgId;
       this.form.deptName = org?.name || this.form.deptName || "";