|
|
@@ -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 || "";
|