departmentTree.vue
4.85 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
<!--
* @Description: 选择层级的树结构
* @Author: huyue
* @Date: 2022-04-28 10:15:34
* @LastEditors: huyue
* @LastEditTime: 2022-08-23 15:47:23
-->
<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.departmentId" @click="backLevel(item)">
<span class="el-breadcrumb__inner">{{ item.departmentName }}</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 v-loading="loading">
<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 departmentList" :key="item.departmentId" @click.self="toNext(item, $event)">
<el-radio :label="item" :disabled="item.relevanceMerchant">{{ item.departmentName }}</el-radio>
<i v-show="item.childrenNum" class="el-icon-arrow-right" @click="toNext(item, $event)"></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 {
loading: false,
visible: false,
dialogTitle: '选择企业微信',
listHeight: 220,
departmentList: [],
parentMerchantList: [],
subSubMerchantList: [],
checkObj: {
first: ''
},
// 选中的用来展示面包屑
selectLevel: [],
lastLevel: true // 是否显示请选择
}
},
methods: {
// 获取门店数据
getDepartmentList(depth, id) {
this.loading = true
var params = {}
params.depth = depth ? depth : 0
if (id) {
params.departmentId = id
}
this.$apis.baseInfo.getDepartment(params).then(res => {
this.departmentList = res
this.loading = false
})
},
handleClose() {
console.log(11212)
this.visible = false
this.selectLevel = []
this.checkObj.first = ''
this.lastLevel = true
},
submit() {
if (!this.checkObj.first) {
this.$message({
message: '请选择门店',
type: 'warning'
})
return
}
this.$emit('select', this.checkObj)
this.visible = false
this.selectLevel = []
this.checkObj.first = ''
this.lastLevel = true
},
// 选中时触发
selectChange(val) {
this.$set(this.selectLevel, val.depth - 1, val)
this.lastLevel = val.childrenNum ? true : false
},
// 跳转下一级,需判断是否有下一级
toNext(item, event) {
if (item.childrenNum) {
this.checkObj.first = ''
this.lastLevel = true
this.getDepartmentList(item.depth, item.id)
this.selectLevel[item.depth - 1] = item
}
},
// 点击页签,返回
backLevel(item) {
this.checkObj.first = ''
this.lastLevel = item.childrenNum ? true : false
console.log(this.lastLevel)
this.selectLevel = this.selectLevel.slice(0, item.depth - 1)
this.getDepartmentList(item.depth - 1)
}
}
}
</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%;
.el-radio {
margin-right: 0;
// width: 100%;
padding: 15px 0 11px;
}
.el-icon-arrow-right {
position: absolute;
top: 56%;
right: 0;
transform: translateY(-50%);
}
}
}
&-item {
position: relative;
// padding: 15px 0 11px;
border-top: 1px solid #e6e6e6;
width: 100%;
display: flex;
justify-content: space-between;
i {
font-size: 12px;
}
}
}
</style>