Ver código fonte

部门下拉统一改「按 parentId 向下递归取子树」+ 岗位管理部门筛选换 ele-tree-select:考勤统计页部门下拉只展示当前账号所属公司子树下的部门(新增 getCurrentOrgId),getGroupList 不返回公司根节点,原来的「建树找根再取 children」会整批落空导致无数据,改为按 parentId 从当前机构向下递归收集(带环保护);薪资人员搜索 user-search 同一问题同改法(fullOrgTree 改 fullOrgList 平铺列表,递归收集子树后建树,公司根节点在返回列表里时剥掉该层只留部门);岗位管理筛选条部门级联由 el-cascader 换成与薪资模板筛选条同款的 ele-tree-select,filterDeptTreeSelect 剥离机构根节点层,只留一级→二级→三级部门

lihaiting 2 semanas atrás
pai
commit
f7501b2643

+ 23 - 5
src/views/attendance/report/index.vue

@@ -89,7 +89,7 @@
 <script>
 import * as echarts from 'echarts';
 import { listOrganizations } from '@/api/organization';
-import { flattenOrganizationTree, buildOrganizationTree } from '@/utils/organization-tree';
+import { getCurrentOrgId } from '@/utils/current-org';
 import {
   getDepartmentAttendanceReport,
   getAttendanceExceptionReport,
@@ -172,10 +172,28 @@ export default {
     async loadDepartments() {
       try {
         const list = await listOrganizations();
-        const flat = flattenOrganizationTree(buildOrganizationTree(list || []));
-        this.departmentOptions = [{ value: '', label: '全部部门' }].concat(
-          flat.map((item) => ({ value: item.id, label: item.name }))
-        );
+        /* 只展示当前账号所属公司子树下的部门(2026-11-09 用户要求):
+           按 parentId 从当前机构向下递归收集;getGroupList 不含公司根节点,
+           不能用「建树找根取 children」的写法(会整批落空 → 无数据)。 */
+        const orgId = getCurrentOrgId();
+        const byParent = new Map();
+        (list || []).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({ value: item.id, label: item.name });
+            walk(item.id);
+          });
+        };
+        walk(orgId);
+        this.departmentOptions = [{ value: '', label: '全部部门' }].concat(options);
       } catch (error) {
         this.departmentOptions = [{ value: '', label: '全部部门' }];
       }

+ 23 - 12
src/views/position/positionManagement/index.vue

@@ -72,9 +72,10 @@
               </el-select>
             </el-form-item>
             <el-form-item label="部门">
-              <!-- 树形:部门有二级三级,扁平下拉只剩一级 → 用级联树 + 可搜索 + 允许选父级 -->
-              <el-cascader v-model="deptFilter" :options="filterDepartmentTree" :props="departmentCascaderProps"
-                clearable filterable popper-class="position-dept-cascader" placeholder="请选择" style="width: 100%" />
+              <!-- 2026-11-09:与薪资模板筛选条同款 ele-tree-select,直接展示部门树(不带公司层,保留 二级/三级 部门层级) -->
+              <ele-tree-select v-model="deptFilter" :data="filterDeptTreeSelect" value-key="id" label-key="name"
+                children-key="children" clearable filterable default-expand-all placeholder="请选择"
+                style="width: 100%" />
             </el-form-item>
             <el-form-item label="状态" class="status-item">
               <el-select v-model="statusFilter" clearable placeholder="请选择">
@@ -262,15 +263,6 @@ export default {
       /* 所属机构筛选:默认带出登录机构列表第一个(左侧序列与岗位列表共用) */
       legalFilter: getCurrentOrgId() || "",
       deptFilter: "",
-      /* 部门级联:按 id 取值(emitPath: false 直接拿部门 id);checkStrictly 允许只选父级部门 */
-      departmentCascaderProps: {
-        value: "id",
-        label: "name",
-        children: "children",
-        emitPath: false,
-        checkStrictly: true,
-        expandTrigger: "hover",
-      },
       statusFilter: "",
       /* 更换 cacheKey 使旧的本体列顺序缓存(含拖拽/显隐记录)失效,让代码列顺序生效 */
       cacheKeyUrl: "fc7bccc0-hr-pc-position-management-v3",
@@ -526,6 +518,25 @@ export default {
         }, []);
       return prune(this.departmentTree || []);
     },
+    /**
+     * 部门筛选树(ele-tree-select 直接展示):剥离机构根节点层,
+     * 只留 一级 → 二级 → 三级 部门(2026-11-09 用户要求与薪资模板筛选条同款)。
+     */
+    filterDeptTreeSelect() {
+      const strip = (nodes) =>
+        (nodes || []).flatMap((node) => {
+          const isLegal = this.legalEntities.some(
+            (item) => String(item.id) === String(node.id),
+          );
+          if (isLegal) return strip(node.children);
+          const next = { id: node.id, name: node.name };
+          if (node.children && node.children.length) {
+            next.children = strip(node.children);
+          }
+          return [next];
+        });
+      return strip(this.filterDepartmentTree);
+    },
   },
   created() {
     this.loadData();

+ 32 - 10
src/views/salary/components/user-search.vue

@@ -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() {