merchantTree.vue
4.55 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
<!--
* @Description: 选择层级的树结构
* @Author: huyue
* @Date: 2022-04-28 10:15:34
* @LastEditors: huyue
* @LastEditTime: 2022-05-18 18:06:35
-->
<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.childrenNms || item.entmicroName">{{ item.merchantName }}</el-radio>
<i v-show="item.childrenNms" 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 {
loading: false,
visible: false,
dialogTitle: '选择商户账户',
listHeight: 220,
merchantList: [],
checkObj: {
first: ''
},
// 选中的用来展示面包屑
selectLevel: [],
lastLevel: true, // 是否显示请选择下一级
merchantId: this.$globalState.session.merchantId
}
},
methods: {
// 获取商户账户数据
getMerchantList(depth, id) {
this.loading = true
var params = {}
params.merchantId = id ? id : this.merchantId
params.depth = depth ? depth : 0
this.$apis.baseInfo.getMerchantTree(params).then(res => {
this.$nextTick(() => {
this.merchantList = res
this.loading = false
})
})
},
handleClose() {
this.visible = false
this.selectLevel = []
this.checkObj.first = ''
this.lastLevel = true
},
submit() {
if (!this.checkObj.first) {
this.$message({
message: '请选择商户账户',
type: 'warning'
})
return
}
this.$emit('selectMerchant', 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.childrenNms ? true : false
},
// 跳转下一级,需判断是否有下一级
toNext(item, event) {
if (item.childrenNms) {
this.checkObj.first = ''
this.lastLevel = true
this.getMerchantList(item.depth, item.merchantNo)
this.selectLevel[item.depth - 1] = item
}
},
// 点击页签,返回
backLevel(item) {
this.checkObj.first = ''
this.lastLevel = item.childrenNms ? true : false
this.selectLevel = this.selectLevel.slice(0, item.depth - 1)
this.getMerchantList(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%;
}
}
&-item {
padding: 15px 0 11px;
border-top: 1px solid #e6e6e6;
width: 100%;
display: flex;
justify-content: space-between;
i {
font-size: 12px;
}
}
}
</style>