SelectMember.vue
7.33 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
<div>
<div>
<el-form ref="form" :model="company" label-width="154px"></el-form>
</div>
<div class="member-wrapper">
<div class="member-left">
<div class="member-content">
<div class="member-content-head">
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
</div>
<div class="table-content">
<el-input size="medium" v-model="filterText" suffix-icon="el-icon-search" clearable placeholder="请输入搜索关键字"></el-input>
<el-tree :data="departmentList" :default-expanded-keys="expandedKeys" show-checkbox ref="tree" node-key="id" :props="defaultProps" @check="handleNodeClick" :filter-node-method="filterNode"></el-tree>
</div>
</div>
</div>
<div class="member-right">
<div class="member-name member-content-head">
<div>已选名称</div>
<div class="blue" @click="clear">清空</div>
</div>
<div class="input-tag-wrapper">
<div class="tag-box">
<el-tag v-for="(label, idx) in userList" :key="idx" type="info" closable :disable-transitions="false" @close="remove(idx)">
{{ label.name }}
</el-tag>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
newArr: [],
filterText: '',
userList: [],
isIndeterminate: false,
checkAll: false,
ids: [],
selectIds: [],
expandedKeys: [],
defaultIds: [],
departmentList: [],
defaultProps: {
children: 'children',
label: 'name'
}
}
},
props: {
merchantId: {
type: String,
default: ''
},
selectlist: {
type: Array,
default: () => []
}
},
created() {
this.getDepartmentTree()
},
watch: {
filterText(val) {
console.log(val)
this.$refs.tree.filter(val)
},
selectlist(val) {
this.defaultData()
}
},
methods: {
clear() {
this.userList = []
this.$refs.tree.setCheckedKeys([])
this.handleNodeClick()
},
handleCheckAllChange(val) {
// console.log(this.ids)
val ? this.$refs.tree.setCheckedKeys(this.ids) : this.$refs.tree.setCheckedKeys([])
this.handleNodeClick()
this.isIndeterminate = false
},
defaultData() {
this.defaultIds = this.selectlist.map(item => item.staffId)
this.$refs.tree.setCheckedKeys(this.defaultIds)
this.handleNodeClick()
},
getMerchantList() {
this.$apis.battle.getMerchantList({}).then(res => {
this.merchantList = res
this.merchantId = this.merchantList[0].merchantId
this.merchantName = this.merchantList[0].merchantName
})
},
async getDepartmentTree() {
let params = { addChildrensFlag: true, queryMerchantId: this.merchantId }
// let params = { addChildrensFlag: true, queryMerchantId: '44210895' }
let data = await this.$apis.battle.getlistDepartmentTree(params)
this.ids = []
this.departmentList = data
await this.initData(this.departmentList)
this.expandedKeys = [this.departmentList[0].id]
this.$nextTick(() => {
if (this.selectlist.length > 0) {
this.defaultData()
}
})
},
initData(data) {
data.forEach((item, index) => {
this.$set(item, 'name', item.staffName ? item.staffName : item.departmentName)
let entmicroStaffResponses = this.$common.utils.deepClone(item.entmicroStaffResponses) || []
entmicroStaffResponses = entmicroStaffResponses.filter((staff, idx) => {
if (staff.staffName) {
this.$set(staff, 'name', staff.staffName)
} else {
this.$set(staff, 'name', staff.departmentName)
}
if (staff.staffId && !this.ids.includes(staff.staffId)) {
this.ids.push(staff.staffId)
return true
} else if (staff.staffId && this.ids.includes(staff.staffId)) {
return false
}
})
let child = this.$common.utils.deepClone(item.children) || []
child = child.filter((staff, idx) => {
if (staff.staffName) {
this.$set(staff, 'name', staff.staffName)
} else {
this.$set(staff, 'name', staff.departmentName)
}
if (staff.staffId && !this.ids.includes(staff.staffId)) {
this.ids.push(staff.staffId)
return true
} else if (staff.staffId && this.ids.includes(staff.staffId)) {
return false
} else if (staff.entmicroStaffResponses) {
staff.staffId = staff.id
return true
}
})
const children = [...child, ...entmicroStaffResponses]
item.children = children
//清除没有员工的部门
if (!item.staffName && item.entmicroStaffResponses === null) {
data.splice(index, 1)
}
children.length && this.initData(children)
})
},
filterNode(value, data) {
if (!value) return true
return data.name.indexOf(value) !== -1
},
search() {},
handleNodeClick() {
this.userList = this.$refs.tree.getCheckedNodes().filter(item => item.children && item.children.length == 0)
this.isIndeterminate = this.userList.length > 0 && this.userList.length < this.ids.length
this.checkAll = this.userList.length === this.ids.length
},
remove(index) {
this.userList.splice(index, 1)
let ids = this.userList.map(item => item.staffId)
this.$refs.tree.setCheckedKeys(ids)
this.isIndeterminate = ids.length < this.ids.length
}
}
}
</script>
<style scoped lang="scss">
.member-wrapper {
display: flex;
.member-left {
width: 400px;
.member-content {
border: 1px solid #eee;
.member-content-head {
height: 44px;
line-height: 44px;
padding: 0 16px;
}
.member-form {
padding: 10px 20px;
}
.table-content {
max-height: 456px;
overflow: auto;
border: 1px solid #eee;
.el-input {
margin: 20px 20px 6px 20px;
width: 360px;
height: 36px;
box-sizing: border-box;
}
}
}
.member-checked {
text-align: right;
margin-top: 10px;
}
}
.member-right {
width: 264px;
margin-left: 14px;
.member-name {
font-size: 14px;
color: #333;
line-height: 44px;
height: 44px;
border: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
.blue {
color: #5850ff;
cursor: pointer;
}
}
}
}
.table-content {
max-height: 456px;
overflow: auto;
border: 1px solid #eee;
}
.table-content .el-tree {
margin: 0 20px 20px;
}
.member-right {
width: 300px;
margin-left: 14px;
}
.member-name {
font-size: 14px;
color: #333;
line-height: 60px;
height: 60px;
padding: 0 20px;
border: 1px solid #eee;
}
.input-tag-wrapper {
max-height: 456px;
overflow: scroll;
}
.tag-box {
margin: 12px 8px;
.el-tag {
margin-right: 4px;
margin-bottom: 4px;
background-color: #fff !important;
font-weight: 400;
font-size: 14px;
color: #666666;
line-height: 20px;
padding: 3px 8px;
height: auto;
}
}
</style>