flowTree.vue
5.3 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
<div class="flow-tree">
<ht-tree
ref="tree"
class="ht-tree"
:tree-data="treeData"
node-key="id"
default-expand-all
:expand-on-click-node="expandOnClickNode"
highlight-current
:props="defaultProps"
:filter-node-method="filterNode"
@node-click="nodeClick"
>
<span slot-scope="{ node, data }" class="span-ellipsis">
<span :title="node.label">
{{ node.label }}
<i v-if="data.count" class="tree-item-count">({{ data.count }})</i>
</span>
</span>
</ht-tree>
<div class="tree-bottom__wrap">
<span class="bottom-text">
默认{{
isExpand
? $t('flowTree.defaultExpand')
: $t('flowTree.defaultCollapse')
}}
</span>
<el-switch v-model="isExpand" @change="handleValChange"></el-switch>
</div>
</div>
</template>
<script>
import {
getFlowTree,
getTodoProcessClassifyCount,
getLeaderTodoProcessClassifyCount,
getLeaderDoneProcessClassifyCount,
getDoneProcessClassifyCount,
getDelegateProcessClassifyCount,
getNewProcessClassifyCount,
getCollectionProcessClassifyCount,
getDraftProcessClassifyCount,
getCirculatedProcessClassifyCount,
getReceivedProcessClassifyCount,
getRequestProcessClassifyCount,
} from '@/api/process'
const MATTER_COUNT_API = {
//我的任务获取各事项流程分类数量
todo: getTodoProcessClassifyCount,
leaderTodo: getLeaderTodoProcessClassifyCount,
done: getDoneProcessClassifyCount,
leaderDone: getLeaderDoneProcessClassifyCount,
myDelegate: getDelegateProcessClassifyCount,
//新建流程
processOverview: getNewProcessClassifyCount,
myCollection: getCollectionProcessClassifyCount,
myDraft: getDraftProcessClassifyCount,
//传阅事项
ciculated: getCirculatedProcessClassifyCount,
received: getReceivedProcessClassifyCount,
//我的申请
myRequest: getRequestProcessClassifyCount,
}
export default {
name: 'FlowTree',
props: {
isShowAside: {
type: Boolean,
default: false,
},
tabActiveName: {
type: String,
default: '',
},
},
data() {
return {
isExpand: false,
filterText: '',
expandOnClickNode: false,
defaultProps: {
children: 'children',
label: 'name',
},
treeData: [],
}
},
watch: {
filterText(val) {
this.$refs.tree.filter(val)
},
tabActiveName(name) {
this.getFlowTree()
},
},
created() {
this.isExpand = this.isShowAside
this.getFlowTree()
},
methods: {
//流程分类默认展开收起事件
handleValChange(isExpand) {
this.$emit('switch-change', isExpand)
},
nodeClick(node, i, e) {
this.$emit('node-click', node)
},
getFlowTree() {
getFlowTree().then((response) => {
this.treeData = response
const params = {}
MATTER_COUNT_API[this.tabActiveName]?.(params)?.then((data) => {
let map = this.getCountMap(data)
this.fillCountIntoTree(this.treeData[0], map)
this.treeData[0].count = this.getTotal(data)
})
})
},
//过滤函数
filterNode(value, data) {
if (!value) return true
return data.name.indexOf(value) !== -1
},
cancelCheck() {
this.$refs.tree.setCurrentKey(null)
},
getCountMap(array) {
let map = {}
array.forEach((item) => {
if (item.typeId === null) {
map[''] = item.count
} else {
map[item.typeId] = item.count
}
})
return map
},
fillCountIntoTree(tree, map) {
tree.count = map[tree.id] ? map[tree.id] : 0
tree.name += ' '
if (tree.children == null) {
return tree.count
}
for (let i = 0; i < tree.children.length; i++) {
let child = tree.children[i]
let count = this.fillCountIntoTree(child, map)
tree.count += count
if (count === 0) {
tree.children.remove(child)
i--
}
}
return tree.count
},
getTotal(data) {
let total = 0
data.forEach((item) => {
total += item.count
})
return total
},
},
}
</script>
<style lang="scss" scoped>
.flow-tree {
display: flex;
flex-direction: column;
height: 100%;
padding: 0 12px;
.ht-tree {
height: calc(100% - 50px);
overflow: auto;
.tree-item-count {
font-style: normal;
}
}
.tree-bottom__wrap {
height: 30px;
line-height: 30px;
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
.bottom-text {
font-size: $base-font-size-small;
}
}
}
.common {
width: 100%;
margin-top: 6px;
}
.flows {
display: block;
margin-left: 24px;
font-size: 14px;
color: $base-color-blue;
text-decoration: none;
}
::v-deep.el-input__inner {
height: 36px;
}
.span-ellipsis {
display: block;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>