You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

const app = getApp();
Component({
properties: {
},
data: {
shixuns:[]
},
5 years ago
pageLifetimes: {
show(){
this.refresh();
5 years ago
}
},
attached(){
5 years ago
this.options = {page:1, per_page:16};
this.refresh();
},
methods: {
refresh(){
app.syncUser()
.then(res => {
if (res.user.user_id != this.user_id) {
if(res.user_id==2)
this.setData({shixuns:[]})
else
this.pullShixuns({ refresh: 1 })
this.user_id = res.user.user_id;
}
})
},
pullShixuns({refresh=0}={}){
if(refresh){
if(refresh==1){
this.options.page = 1;
var { options } = this;
}else if(refresh==2){
var {page, per_page} = this.options;
var options = {page:1, per_page: page*per_page};
}
}else{
this.options.page++;
var {options} = this;
}
return app.api("users.shixuns")(options).then(({shixuns})=>{
if (!refresh)
shixuns = this.data.shixuns.concat(shixuns);
this.setData({ shixuns });
}).catch(e=>{
this.setData({shixuns:[]});
})
},
onPullDownRefresh(){
this.pullShixuns({refresh:2});
},
onReachBottom(){
this.pullShixuns({refresh:0});
}
}
})