|
|
@@ -73,8 +73,8 @@ export default {
|
|
|
where: { ...defaultWhere },
|
|
|
defaultWhere,
|
|
|
legalEntities: [],
|
|
|
- /* 全量组织树:所属部门下拉按所选公司取子树(见 deptTree),不直接整棵展示 */
|
|
|
- fullOrgTree: [],
|
|
|
+ /* 组织平铺列表:所属部门下拉按所选公司向下递归取子树(见 deptTree) */
|
|
|
+ fullOrgList: [],
|
|
|
// 默认公司(当前登录用户所在法人):初始化与重置共用
|
|
|
defaultOrganizationId: '',
|
|
|
statusOptions: TEMPLATE_STATUS_OPTIONS
|
|
|
@@ -88,14 +88,36 @@ export default {
|
|
|
* 所属部门树:只显示**当前所选公司(所属公司)子树**下的组织。
|
|
|
* 复测问题:原来整棵组织树直接进下拉,能看到其他公司(测试公司等)的部门。
|
|
|
* 公司节点自身不进下拉(整个公司 = 清空部门筛选「全部部门」)。
|
|
|
+ * 2026-11-09:getGroupList 返回的组织列表不含公司根节点(只有部门),
|
|
|
+ * 原来按公司 id 在树里找根节点取 children 会落空 → 下拉「无数据」;
|
|
|
+ * 改为按 parentId 从所选公司向下递归收集子树(与转正页 positionCascade 同口径)。
|
|
|
*/
|
|
|
deptTree() {
|
|
|
const companyId = this.where.organizationId;
|
|
|
- if (!companyId) return [];
|
|
|
- const root = (this.fullOrgTree || []).find(
|
|
|
- (node) => String(node.id) === String(companyId)
|
|
|
- );
|
|
|
- return root ? root.children || [] : [];
|
|
|
+ if (!companyId || !this.fullOrgList.length) return [];
|
|
|
+ const byParent = new Map();
|
|
|
+ this.fullOrgList.forEach((item) => {
|
|
|
+ const key = String(item.parentId);
|
|
|
+ if (!byParent.has(key)) byParent.set(key, []);
|
|
|
+ byParent.get(key).push(item);
|
|
|
+ });
|
|
|
+ /* 向下收集公司子树内全部节点 id(防环) */
|
|
|
+ const ids = new Set();
|
|
|
+ const collect = (parentId) => {
|
|
|
+ (byParent.get(String(parentId)) || []).forEach((item) => {
|
|
|
+ if (ids.has(String(item.id))) return;
|
|
|
+ ids.add(String(item.id));
|
|
|
+ collect(item.id);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ collect(companyId);
|
|
|
+ const subtree = this.fullOrgList.filter((item) => ids.has(String(item.id)));
|
|
|
+ const tree = buildOrganizationTree(subtree);
|
|
|
+ /* 公司节点若在返回列表里会成为唯一根:剥掉公司层只留部门 */
|
|
|
+ if (tree.length === 1 && String(tree[0].id) === String(companyId)) {
|
|
|
+ return tree[0].children || [];
|
|
|
+ }
|
|
|
+ return tree;
|
|
|
},
|
|
|
/* 当前公司子树内全部节点 id,用于切换公司时清掉已失效的部门筛选值 */
|
|
|
deptIdsInScope() {
|
|
|
@@ -122,13 +144,13 @@ export default {
|
|
|
this.loadOrgTree();
|
|
|
},
|
|
|
methods: {
|
|
|
- /* 全量组织树(扁平列表 → 树):部门下拉只取其中所选公司的子树 */
|
|
|
+ /* 组织平铺列表(扁平含 parentId):部门下拉按所选公司向下递归取子树 */
|
|
|
async loadOrgTree() {
|
|
|
try {
|
|
|
const list = await listOrganizations();
|
|
|
- this.fullOrgTree = buildOrganizationTree(Array.isArray(list) ? list : []);
|
|
|
+ this.fullOrgList = Array.isArray(list) ? list : [];
|
|
|
} catch (error) {
|
|
|
- this.fullOrgTree = [];
|
|
|
+ this.fullOrgList = [];
|
|
|
}
|
|
|
},
|
|
|
init() {
|