HtOrgTree.vue
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<el-scrollbar style="height:100%">
<ht-tree
:data="treeData"
:props="defaultProps"
:highlight-current="highlightCurrent"
:default-expand-all="defaultExpandAll"
node-key="id"
:show-checkbox="showCheckbox"
:render-content="renderContent"
:expand-on-click-node="false"
@node-click="handleNodeClick"
@check="check"
@refresh="loadData"
:support-filter="true"
ref="htTree"
:lazy="lazy"
:load="load"
>
<!-- 作用域插槽:插槽prop -->
<slot slot-scope="{ node, data }" :node="node" :data="data"></slot>
</ht-tree>
</el-scrollbar>
</template>
<script>
import org from "@/api/org.js";
import utils from "@/hotent-ui-util.js";
export default {
name: "ht-org-tree",
props: {
orgId: {
type: String | Number,
required: true
},
supportFilter: {
type: Boolean,
default: false
},
highlightCurrent: {
type: Boolean,
default: false
},
defaultExpandAll: {
type: Boolean,
default: false
},
showCheckbox: {
type: Boolean,
default: false
},
renderContent: {
type: Function
},
lazy: {
type:Boolean,
default: true
}
},
data() {
return {
treeData: [],
defaultProps: {
children: "children",
label: "name"
}
};
},
methods: {
handleNodeClick(node) {
this.$emit("node-click", node);
},
check(data, checkedObj) {
this.$emit("check", data, checkedObj);
},
loadData(cb) {
let param = {
isOrgAuth: "true",
parentId: this.orgId,
deep:true
};
let this_ = this;
org.getByParentAndDem(param).then(data => {
this_.treeData = utils.tile2nest(data);
this_.treeData.forEach(item=>{
if(this_.treeData.some(other=>{
return other.id !== item.id && item.id == other.parentId
})){
item.leaf = false;
item.isParent = true;
}else{
item.isParent = false;
item.leaf = true;
}
})
}).finally(()=>{
cb && cb();
});
},
load(node, resolve){
if (!node.data.id){
org.get(this.orgId).then(data => {
resolve(data);
})
return;
}
org.getChildrenByOrgId(node.data.id).then(data => {
resolve(data);
})
}
},
mounted() {
this.loadData();
}
};
</script>
<style lang="scss" scoped>
>>> .el-tree .el-tree__empty-block {
margin: 20px 20px; width: calc(100% - 40px);
}
>>> .el-tree {
width: 100%;
}
>>> .el-scrollbar__wrap {
overflow-x: hidden;
}
</style>