merchantTree.vue
9.8 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!--
* @Description: 选择层级的树结构
* @Author: huyue
* @Date: 2022-04-28 10:15:34
* @LastEditors: huyue
* @LastEditTime: 2022-05-05 18:32:18
-->
<template>
<div>
<GLDialog class="tree-dialog" :visible="visible" @close="handleClose" :title="dialogTitle" :showClose="true">
<div>
<div class="el-breadcrumb">
<span class="el-breadcrumb__item">
<span class="el-breadcrumb__inner" style="cursor: context-menu">{{ $globalState.session.merchantName }}</span>
<i class="el-breadcrumb__separator el-icon-arrow-right"></i>
</span>
<span class="el-breadcrumb__item" v-for="item in selectLevel" :key="item.merchantId" @click="backLevel(item)">
<span class="el-breadcrumb__inner">{{ item.merchantName }}</span>
<i class="el-breadcrumb__separator el-icon-arrow-right"></i>
</span>
<span class="el-breadcrumb__item last-level" v-if="lastLevel">
<span class="el-breadcrumb__inner">请选择下级组织结构</span>
<i class="el-breadcrumb__separator el-icon-arrow-right"></i>
</span>
</div>
<div>
<div class="tree-list" :style="{ height: listHeight + 'px' }">
<el-radio-group v-model="checkObj.first" @change="selectChange">
<div class="tree-item" v-for="item in merchantList" :key="item.merchantId" @click.self="toNext(item, $event)">
<el-radio :label="item" :disabled="item.disabled || item.children">{{ item.departmentName }}</el-radio>
<i v-show="item.hasChildren" class="el-icon-arrow-right"></i>
</div>
</el-radio-group>
</div>
</div>
</div>
<div slot="footer">
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="submit">提交</el-button>
</div>
</GLDialog>
</div>
</template>
<script>
export default {
name: 'MerchantTree',
data() {
return {
visible: false,
dialogTitle: '选择商户账户',
listHeight: 220,
merchantList: [],
parentMerchantList: [
{
merchantId: 1,
merchantName: '测试10001',
parentMerchantName: '',
hasChildren: false,
level: 1,
disabled: true
},
{
merchantId: 2,
merchantName: '嘀加智慧平台-公共商户',
parentMerchantName: '嘀加公共市代商户',
hasChildren: true,
level: 1,
disabled: true
},
{
merchantId: 3,
merchantName: '深圳南山崇文园区奥迪4S店',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 4,
merchantName: '南山智园崇文园区',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 5,
merchantName: '深圳世界之窗',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 6,
merchantName: '大众进口商务车中心',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 7,
merchantName: '深圳保利汽车',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 8,
merchantName: 'hz',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 9,
merchantName: '嘀嘀虎测试园区店',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 10,
merchantName: '广丰美富特测试号xk',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 11,
merchantName: '侧ad的121',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 12,
merchantName: '明明广联嘀加省代',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: false
},
{
merchantId: 13,
merchantName: '智慧门店下级商户',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 14,
merchantName: 'YY测试4S店',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 15,
merchantName: 'xp_测试商户001',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
},
{
merchantId: 16,
merchantName: '测试测试测试',
parentMerchantName: '嘀加公共市代商户',
level: 1,
hasChildren: true
}
],
subMerchantList: [
{
merchantId: 100,
merchantName: '嘀加公共市代商户',
parentMerchantName: '嘀加智慧平台-公共商户',
level: 2,
hasChildren: true
}
],
subSubMerchantList: [
{
merchantId: 1000,
merchantName: '尚城大众',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1001,
merchantName: '供应商的账号',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1002,
merchantName: '颗粒的供应商',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1003,
merchantName: '颗粒的4s店',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1004,
merchantName: '颗粒的综合汽贸店',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1005,
merchantName: '颗粒的综合后服务门店',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
},
{
merchantId: 1006,
merchantName: '求门店关注我',
parentMerchantName: '嘀加公共市代商户',
level: 3,
hasChildren: false
}
],
checkObj: {
first: ''
},
// 选中的用来展示面包屑
selectLevel: [
// {
// merchantId: this.$globalState.session.merchantId,
// merchantName: this.$globalState.session.merchantName,
// level: 0
// }
],
lastLevel: true // 是否显示请选择
}
},
mounted() {
// this.merchantList = this.parentMerchantList
this.getDepartmentList()
},
methods: {
// 获取门店数据
getDepartmentList() {
this.$apis.baseInfo.getDepartment({}).then(res => {
// this.departmentList = this.traverse(1, res, 'relevanceMerchant')
console.log(res[0], '==')
this.merchantList = res[0].children
})
},
handleClose() {
this.visible = false
},
submit() {
console.log(this.checkObj)
if (!this.checkObj) {
this.$message({
message: '请选择门店',
type: 'warning'
})
return
}
this.$emit('select', this.checkObj)
this.visible = false
},
// 选中时触发
selectChange(val) {
console.log(val)
this.$set(this.selectLevel, val.level - 1, val)
this.lastLevel = false
// this.lastLevel = val.hasChildren
},
// 跳转下一级,需判断是否有下一级
toNext(item, event) {
console.log(item, this.checkObj, event)
if (item.hasChildren) {
this.checkObj.first = ''
this.lastLevel = true
}
if (item.hasChildren) {
this.lastLevel = true
this.selectLevel[item.level - 1] = item
if (item.level == 1) {
this.merchantList = this.subMerchantList
} else {
this.merchantList = this.subSubMerchantList
}
}
},
// 点击页签,返回
backLevel(item) {
console.log(item)
this.checkObj.first = ''
this.lastLevel = item.hasChildren
if (item.level == 2) {
this.merchantList = this.subMerchantList
} else if (item.level == 1) {
this.merchantList = this.parentMerchantList
} else {
this.merchantList = this.parentMerchantList
}
this.selectLevel = this.selectLevel.slice(0, item.level)
}
}
}
</script>
<style lang="scss" scoped>
.el-breadcrumb {
line-height: 28px;
}
.el-radio__label {
color: #333;
}
.tree-dialog {
/deep/ {
.last-level {
.el-breadcrumb__inner {
color: #5850ff;
}
}
.el-breadcrumb__inner {
font-weight: normal;
cursor: pointer;
}
.el-dialog__body {
padding: 20px;
}
}
}
.tree {
&-list {
margin-top: 10px;
overflow: auto;
.el-radio-group {
width: 100%;
}
}
&-item {
padding: 15px 0 11px;
border-top: 1px solid #e6e6e6;
width: 100%;
display: flex;
justify-content: space-between;
i {
font-size: 12px;
}
}
}
</style>