beefast-mini-deliveryman/components/listView/index.js
2025-03-20 18:59:30 +08:00

75 lines
1.4 KiB
JavaScript

// components/listView/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
refresherTriggered:{
type:Boolean,
value:false
},
height:{
type:Number,
value:0
},
loadMoreText:{
type:String,
value:'已经到底了'
},
showLoadMore:{
type:Boolean,
value:true
},
loadAll:{
type:Boolean,
value:false
}
},
/**
* 组件的初始数据
*/
data: {
heightStyle:'',
scrollHeight:0
},
lifetimes:{
attached(){
this.createSelectorQuery().select('#scrollView').boundingClientRect((res)=>{
this.data.scrollHeight = res.height;
}).exec();
const windowInfo = wx.getWindowInfo();
}
},
/**
* 组件的方法列表
*/
methods: {
refreshList(){
this.triggerEvent('refresh');
},
scrolling(event){
//scrollTop scrollHeight
const bottomHeight = event.detail.scrollHeight-event.detail.scrollTop-this.data.scrollHeight;
if(bottomHeight<100){
this.triggerEvent('loadMore');
}
}
},
observers:{
height(h){
let heightStyle = '';
if(h){
if(typeof h == 'string'){
heightStyle = `height:${h}`
}else{
heightStyle = `height:${this.properties.height*2}rpx`
}
this.setData({
heightStyle:heightStyle
})
}
}
}
})