Просмотр исходного кода

fix:调整部门设置部门树的数据获取接口逻辑

liujiayin 2 лет назад
Родитель
Сommit
abdc86c47e
2 измененных файлов с 78 добавлено и 37 удалено
  1. 23 3
      src/components/ibps-tree/index.vue
  2. 55 34
      src/views/platform/org/position/manage.vue

+ 23 - 3
src/components/ibps-tree/index.vue

@@ -74,6 +74,7 @@
                 wrap-class="ibps-tree-wrapper"
                 wrap-class="ibps-tree-wrapper"
             >
             >
                 <el-tree
                 <el-tree
+                    v-if="!lazy ? (treeData && treeData.length>0) : lazy "
                     ref="elTree"
                     ref="elTree"
                     v-loading="loading"
                     v-loading="loading"
                     :data="!lazy ? treeData : null"
                     :data="!lazy ? treeData : null"
@@ -275,8 +276,21 @@ export default {
             this.zIndex = val
             this.zIndex = val
         },
         },
         treeData (val) {
         treeData (val) {
-            if (val && val[0] && val[0].children) {
-                this.treeExpandData.push(val[0].children[0].id)
+            // if (val && val[0] && val[0].children) {
+            //     this.treeExpandData.push(val[0].children[0].id)
+            // }
+            // 如果是部门管理里只显示一个医院的,那么就展开所有的节点
+            if (val[0] && val[0].children.length === 1 &&
+                this.title === '部门管理') {
+                return
+            }
+            if (val[0] && val[0].children.length && val[0].children.length !== 1) {
+                // 默认打开第三层
+                for (const i of val[0].children) {
+                    this.treeExpandData.push(
+                        i.children.length ? i.children[0].id : i.id
+                    )
+                }
             }
             }
         }
         }
     },
     },
@@ -291,7 +305,13 @@ export default {
          * 判斷tree是否展开
          * 判斷tree是否展开
          */
          */
         judgeTitle () {
         judgeTitle () {
-            if (this.title === '业务对象管理' || this.title == undefined) {
+            if (this.title === '业务对象管理' ||
+                this.title === undefined ||
+                (
+                    this.treeData[0] && this.treeData[0].children.length === 1 &&
+                    this.title === '部门管理'
+                )
+            ) {
                 return true
                 return true
             }
             }
             return this.lazy
             return this.lazy

+ 55 - 34
src/views/platform/org/position/manage.vue

@@ -3,12 +3,11 @@
         <div slot="west">
         <div slot="west">
             <ibps-tree
             <ibps-tree
                 ref="tree"
                 ref="tree"
+                :data="treeData"
                 :width="width"
                 :width="width"
                 :height="height"
                 :height="height"
                 :options="orgTreeoptions"
                 :options="orgTreeoptions"
                 :contextmenus="orgTreeContextmenus"
                 :contextmenus="orgTreeContextmenus"
-                :load="loadNode"
-                lazy
                 title="部门管理"
                 title="部门管理"
                 @action-event="handleTreeAction"
                 @action-event="handleTreeAction"
                 @node-click="handleNodeClick"
                 @node-click="handleNodeClick"
@@ -67,7 +66,7 @@
 </template>
 </template>
 <script>
 <script>
 import { remove } from '@/api/platform/org/position'
 import { remove } from '@/api/platform/org/position'
-import { findTreeData as getTreeData } from '@/api/platform/org/position'
+import { findTreeData as getTreeData, findAllPosition } from '@/api/platform/org/position'
 import TreeUtils from '@/utils/tree'
 import TreeUtils from '@/utils/tree'
 import ActionUtils from '@/utils/action'
 import ActionUtils from '@/utils/action'
 import FixHeight from '@/mixins/height'
 import FixHeight from '@/mixins/height'
@@ -118,41 +117,63 @@ export default {
                 { type: 'divided' },
                 { type: 'divided' },
                 { icon: 'sort', label: '节点排序', value: 'nodeSort' }
                 { icon: 'sort', label: '节点排序', value: 'nodeSort' }
             ],
             ],
-            orgTreeData: []
+            orgTreeData: [],
+            treeData: []
         }
         }
     },
     },
-    methods: {
-        loadNode (node, resolve) {
-            this.loading = true
-            const first = this.$store.getters.level.first
-            const isSuper = this.$store.getters.isSuper
-            getTreeData({
-                type: 1,
-                posId: node.level === 0 ? null : node.data.id
-            }).then(res => {
-                const data = res.data
-                // 岗位树改成部门树
-                data.forEach((item) => {
-                    if (item.name === '岗位树') {
-                        item.name = '部门树'
-                    }
-                })
-                // 数据过滤 - 过滤本部门
-                const show = data.some(item => item.id === first)
-                let showData = []
-                if (show && !isSuper) {
-                    showData = data.filter(item => item.id === first)
-                } else {
-                    showData = data
-                }
-
-                this.loading = false
-                resolve(this.toTree(showData))
+    mounted () {
+        /**
+        *  判断是否是超级管理员isSuper账号,目前以该账户为系统最大的管理权限
+        *  如果是测试账号,则获取全部数据
+        *  否则,获取当前用户所在医院的数据
+        */
+        getTreeData({
+            type: 1
+        }).then(res => {
+            const firstData = res.data || []
+            if (firstData.length) {
+                firstData[0].name = '部门树'
+            }
+            findAllPosition().then(res => {
+                const nextData = res.data || []
+                this.treeData = this.toTree([...firstData, ...nextData])
+                console.log('137 this.treeData', this.treeData)
             }).catch(res => {
             }).catch(res => {
-                this.loading = false
-                resolve([])
             })
             })
-        },
+        })
+    },
+    methods: {
+        // loadNode (node, resolve) {
+        //     this.loading = true
+        //     const first = this.$store.getters.level.first
+        //     const isSuper = this.$store.getters.isSuper
+        //     getTreeData({
+        //         type: 1,
+        //         posId: node.level === 0 ? null : node.data.id
+        //     }).then(res => {
+        //         const data = res.data
+        //         // 岗位树改成部门树
+        //         data.forEach((item) => {
+        //             if (item.name === '岗位树') {
+        //                 item.name = '部门树'
+        //             }
+        //         })
+        //         // 数据过滤 - 过滤本部门
+        //         const show = data.some(item => item.id === first)
+        //         let showData = []
+        //         if (show && !isSuper) {
+        //             showData = data.filter(item => item.id === first)
+        //         } else {
+        //             showData = data
+        //         }
+
+        //         this.loading = false
+        //         resolve(this.toTree(showData))
+        //     }).catch(res => {
+        //         this.loading = false
+        //         resolve([])
+        //     })
+        // },
         toTree (data) {
         toTree (data) {
             return TreeUtils.transformToTreeFormat(data, {
             return TreeUtils.transformToTreeFormat(data, {
                 idKey: 'id',
                 idKey: 'id',