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.

55 lines
1.2 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) {
this.pullShixuns({ refresh: 1 });
this.user_id = res.user.user_id;
}
})
},
async 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;
}let {shixuns} = await app.api("users.shixuns")(options);
if(!refresh)
shixuns = this.data.shixuns.concat(shixuns);
this.setData({shixuns});
return shixuns;
},
onPullDownRefresh(){
this.pullShixuns({refresh:2});
},
onReachBottom(){
this.pullShixuns({refresh:0});
}
}
})