search.vue
7.72 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
<!--
* @Description: 搜索下拉组件
* @Author: huyue
* @Date: 2022-04-27 10:28:50
* @LastEditors: huyue
* @LastEditTime: 2022-05-20 09:44:47
-->
<template>
<div>
<el-popover :popper-class="'search-popper'" placement="bottom-start" width="280" trigger="manual" v-model="visible">
<ul v-if="name == 'merchant'" class="el-scrollbar__view el-cascader__suggestion-list" v-infinite-scroll="load" style="overflow: auto">
<template v-if="searchList.length">
<template v-for="item in searchList">
<li :key="item.id" v-if="!item.childrenNums" class="el-cascader__suggestion-item" :class="item.departmentName == searchKey.departmentName" @click="selectMerchantItem(item)">
<div>{{ item.merchantName }}</div>
<div class="parent-merchant">{{ item.parentMerchantName }}</div>
</li>
</template>
</template>
<template v-else>
<li>无数据</li>
</template>
</ul>
<ul v-else class="el-scrollbar__view el-cascader__suggestion-list" v-infinite-scroll="load" style="overflow: auto">
<template v-if="searchList.length">
<li class="el-cascader__suggestion-item" :class="item.departmentName == searchKey.departmentName" v-for="item in searchList" :key="item.id" @click="selectItem(item)">
<div>{{ item.departmentName }}</div>
<div class="parent-merchant">{{ item.entmicroParentName }}</div>
</li>
</template>
<template v-else>
<li>无数据</li>
</template>
</ul>
<el-input slot="reference" debounce style="width: 320px" v-model="searchKey.departmentName" :size="size" @input="handleInput" @focus="handleFocus" @blur="handleBlur" :placeholder="type">
<template slot="append">
<div class="input_append" @click.stop="arrowClick()">
<img src="@/assets/add_merchant.png" alt="" />
</div>
</template>
</el-input>
</el-popover>
<DepartmentTree ref="departmentTree" @select="select"></DepartmentTree>
<MerchantTree ref="merchantTree" @selectMerchant="selectMerchant"></MerchantTree>
</div>
</template>
<script>
import { utils } from 'glsx-common'
import DepartmentTree from './departmentTree.vue'
import MerchantTree from './merchantTree.vue'
export default {
name: 'SearchSelect',
components: {
DepartmentTree,
MerchantTree
},
props: {
name: {
type: String,
default: ''
}
},
data() {
return {
loading: false,
searchKey: {
id: '',
departmentName: ''
}, // 绑定input的值
// isOpen: false,
visible: false,
isCheck: false,
departmentList: [], // 接口返回数据
searchValue: '', // 搜索值
searchList: [], // 搜索结果
list: [],
count: 0,
pageParams: {
pageNum: 1,
pageSize: 10
}
}
},
methods: {
arrowClick() {
this.isOpen = true
this.visible = false
if (this.isOpen) {
if (this.name === 'merchant') {
this.$refs.merchantTree.visible = true
this.$refs.merchantTree.getMerchantList()
return
}
this.$refs.departmentTree.visible = true
this.$refs.departmentTree.getDepartmentList()
}
},
// 获取搜索框输入值
handleInput: utils.debounce(function(val) {
this.searchValue = val
this.pageParams.pageNum = 1
// 判断是商户账户调用还是企业微信调用
if (this.name === 'merchant') {
this.getMerchantSearchList(val)
return
}
this.getSearchList(val)
}, 20),
// 根据输入内容搜索企微门店数据
getSearchList(val) {
// this.searchList = []
if (!val) {
this.visible = false
this.$emit('getCurDepartment')
return
}
var params = JSON.parse(JSON.stringify(this.pageParams))
params.departmentName = val
// if (params.departmentName) {
this.$apis.baseInfo.findDepartmentList(params).then(res => {
if (res.data.length) {
this.count = res.count
if (res.pageNum == 1) {
this.searchList = res.data
} else {
this.searchList = this.searchList.concat(res.data)
}
}
})
this.visible = true
},
// 根据输入内容搜索商户账户数据
getMerchantSearchList(val) {
if (!val) {
this.visible = false
this.$emit('getCurMerchant')
return
}
var params = JSON.parse(JSON.stringify(this.pageParams))
params.merchantName = val
// supRangeMerchantNo-商户ID
params.parentMerchantNo = this.$globalState.session.merchantId
this.$apis.baseInfo.findMerchantTreeList(params).then(res => {
if (res.data.length) {
this.count = res.count
if (res.pageNum == 1) {
this.searchList = res.data
} else {
this.searchList = this.searchList.concat(res.data)
}
}
})
this.visible = true
},
// 下拉选择商户账户
selectMerchantItem(val) {
// this.searchList = []
this.searchKey.id = val.merchantNo
this.searchKey.departmentName = val.merchantName
this.visible = false
this.$emit('getCurMerchant', val)
},
// 下拉选择门店
selectItem(val) {
// this.searchList = []
this.searchKey = val
this.$emit('getCurDepartment', val)
this.visible = false
},
// 选择企微门店
select(val) {
this.searchKey.id = val.first.departmentId + ''
this.searchKey.departmentName = val.first.departmentName
this.$emit('getCurDepartment', val.first)
},
// 选择商户账户
selectMerchant(val) {
this.searchKey.id = val.first.merchantNo + ''
this.searchKey.departmentName = val.first.merchantName
this.$emit('getCurMerchant', val.first)
},
// 输入框失去焦点调用
handleBlur() {
this.visible = false
// this.searchList = []
},
// 输入框获取焦点
handleFocus() {
this.pageParams = {
pageNum: 1,
pageSize: 10
}
// 判断输入框是否有值
if (this.searchKey.departmentName) {
if (this.name === 'merchant') {
this.getMerchantSearchList(this.searchKey.departmentName)
return
}
this.getSearchList(this.searchKey.departmentName)
}
},
// 下拉框触底获取下一页数据
load() {
this.pageParams.pageNum++
if (this.searchList.length < this.count) {
if (this.name === 'merchant') {
this.getMerchantSearchList()
return
}
this.getSearchList(this.searchValue)
}
}
}
}
</script>
<style lang="scss" scoped>
// .el-select {
// .el-select__caret:first-child::before {
// content: '\e6e1';
// }
// .is-focus {
// .el-select__caret:first-child {
// transform: rotateZ(0deg);
// }
// }
// }
.is-focus.el-icon-arrow-down:first-child {
transform: rotateZ(180deg);
}
.el-cascader__suggestion-item {
position: relative;
flex-direction: column;
align-items: flex-start;
padding: 12px 16px;
.parent-merchant {
padding-top: 4px;
font-size: 10px;
color: #666666;
}
}
.el-cascader__suggestion-item::after {
content: '';
position: absolute;
bottom: 0;
border-bottom: 1px solid #eee;
width: calc(100% - 32px);
}
.el-cascader__suggestion-item.is-checked {
color: #5850ff;
}
.el-cascader__suggestion-list {
overflow: auto;
width: 100%;
}
/deep/.el-input-group__append {
padding: 0;
background-color: #5850ff;
border: 1px solid #5850ff;
}
.input_append {
width: 38px;
height: 30px;
}
</style>
<style>
.search-popper {
padding: 0 !important;
height: 220px;
}
</style>