index.vue
3.21 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
<template>
<el-select ref="selectRef" clearable filterable remote :remote-method="remoteMethod" v-el-select-loadmore="loadmore" v-model="inputVal" placeholder="请选择门店" @change="selectChange">
<el-option v-for="(item, i) in dataItems" :key="i" :label="item[label]" :value="item[value]"></el-option>
</el-select>
</template>
<script>
import { getStoreList } from './api'
export default {
name: 'SearchDropDown',
props: ['inputBoxSearchValue', 'label', 'value'],
data() {
return {
searchContentStorage: '',
inputVal: '',
dataItems: [],
arrBack:[],
totalNum:'',
pageData: {
//懒加载相关参数,这里代表从第一条数据开始加载,一次加载40项
pageNum: 1,
pageSize: 10
}
}
},
directives: {
/** 下拉框懒加载 */
'el-select-loadmore': {
bind(el, binding) {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight
if (condition) {
binding.value()
}
})
}
}
},
mounted() {
this.loadUpData(this.pageData)
},
watch: {
// 'inputVal'(newVal, oldVal) {
// console.log(newVal,oldVal)
// // if (oldVal !== newVal) {
// // this.dataItems = []
// // this.loadUpData({
// // pageNum: 1,
// // pageSize: 10
// // },newVal)
// // }
// }
'inputVal': {
handler(val) {
console.log(val)
if (!val) {
this.dataItems = []
this.loadUpData({
pageNum: 1,
pageSize: 10
})
}
}
}
},
methods: {
async loadUpData(pageData, searchVal) {
let params = {
...pageData,
merchantName: searchVal
}
await this.$apis.wechatGroup.getStoreList(params).then(res => {
this.totalNum = res.count
this.arrBack = res.data
})
this.dataItems = [...this.dataItems,...this.arrBack]
},
loadmore() {
this.pageData.pageNum++
let acquireCount = this.pageData.pageNum * this.pageData.pageSize
if (acquireCount - this.totalNum >= this.pageData.pageSize){
return
}
if (this.searchContentStorage) {
this.loadUpData(this.pageData, this.searchContentStorage)
} else {
this.loadUpData(this.pageData, '') //类似于分页查询
}
},
// 远程搜索
async remoteMethod(searchValue) {
console.log(this.inputVal)
if (searchValue !== '') {
this.searchContentStorage = searchValue
this.dataItems = []
this.timer = setTimeout(() => {
this.loadUpData(this.pageData, searchValue)
}, 300)
} else {
this.dataItems = []
this.loadUpData({
pageNum: 1,
pageSize: 10
},'')
}
},
// 根据所选商户获取品牌和地址
async selectChange(label) {
if (label) {
let obj = this.dataItems.filter(el => {
return el['incomingDisplayLabel'] == label
})
}
}
}
}
</script>
<style scoped></style>