diff --git a/frontend/src/pages/roster/modals.tsx b/frontend/src/pages/roster/modals.tsx index 6d63023..6bf9523 100644 --- a/frontend/src/pages/roster/modals.tsx +++ b/frontend/src/pages/roster/modals.tsx @@ -110,9 +110,22 @@ export function DeptChangeModal({ employee, onClose, onSubmit, loading, error }: } buildDeptOptions(departments, null, 0) - // 选中新部门后,过滤该部门下的职务(如果职务有 departmentId 关联) + // 选中新部门后,过滤该部门下的职务: + // 1. 通用职务(departmentId 为空)所有部门可用 + // 2. 该部门专属职务 + // 3. 父部门专属职务(子部门继承父部门职务,如铁矿继承项目运营中心的工人/施工员等) + const getDeptAncestorIds = (deptId: string): string[] => { + const ids: string[] = [] + let cur: any = departments.find((d: any) => d.id === deptId) + while (cur) { + ids.push(cur.id) + cur = cur.parentId ? departments.find((d: any) => d.id === cur.parentId) : null + } + return ids + } + const ancestorIds = form.departmentId ? getDeptAncestorIds(form.departmentId) : [] const filteredPositions = form.departmentId - ? positions.filter((p: any) => !p.departmentId || p.departmentId === form.departmentId) + ? positions.filter((p: any) => !p.departmentId || ancestorIds.includes(p.departmentId)) : positions const selectedDept = departments.find((d: any) => d.id === form.departmentId)