<el-autocomplete
ref="autocomplete"
value-key="label"
v-scrollLoad="load"
v-loading="loading"
v-model="state2"
:fetch-suggestions="querySearch"
placeholder="供应商名称/编码"
:trigger-on-focus="false"
@select="handleSelect"
></el-autocomplete>
js部分
export default {
components: { Pagination },
// directives: { waves },
data() {
return {
restaurants: [],
state2: '',
loading:false,
suppilerListTotal,
suppilerListQuery: {
pageNumber: 1,
pageSize: 10,
},
}
},
directives:{
scrollLoad:{
bind(el, binding, vnode){
var that =this
let wrapDom = el.querySelector(".el-autocomplete-suggestion__wrap")
let listDom = el.querySelector(".el-autocomplete-suggestion__wrap .el-autocomplete-suggestion__list")
wrapDom.addEventListener("scroll",(e)=>{
let condition = wrapDom.offsetHeight + wrapDom.scrollTop + 10 - listDom.offsetHeight
if(condition > 0 && !vnode.context.loading){
//滚动到底部则执行滚动方法load,binding.value就是v-scrollLoad绑定的值,加()表示执行绑定的方法
binding.value()
}
},false)
}
}
},
methods:{
//滚到底部执行的方法
load(e){
if(this.suppilerListTotal<this.suppilerListQuery.pageSize){
return false
}
this.loading = true
this.suppilerListQuery.pageSize += 10
//XXX -滚动到底部后请求的列表
XXX(this.suppilerListQuery,this.state2).then(res=>{
this.suppilerListTotal = res.data.total
this.$refs['autocomplete'].$data.suggestions = res.data.records
this.loading = false
})
},
querySearch(queryString, cb) {
this.suppilerListQuery.pageSize = 10
//XXX -第一次请求的列表
XXX(this.suppilerListQuery,queryString).then(res=>{
this.suppilerListTotal = res.data.total
cb(res.data.records)
})
},
handleSelect(item) {
this.listQuery.tenantCode = item.id
},
}
}