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.

91 lines
2.3 KiB

const app = getApp();
5 years ago
// status:[0, 204, 205, 200]
Component({
properties: {
},
data: {
5 years ago
shixuns:[],
status:0,
cates:[
{text:'全部',value:""},
{text:'我学习的',value:"study"},
{text:'我管理的',value:"manage"},
{text:"我收藏的",value:"collect"}
]
},
5 years ago
pageLifetimes: {
show(){
this.refresh();
5 years ago
}
},
attached(){
5 years ago
this.options = {page:1, per_page:16};
this.refresh({showError: 1});
},
methods: {
5 years ago
onCateChange({detail:{value}}){
this.options.category = value.value
this.pullShixuns({refresh:1,showError:1});
5 years ago
},
refresh({showError=0}={}){
app.syncUser()
.then(res => {
if (res.user.user_id != this.user_id) {
if(res.user.user_id==2)
this.setData({shixuns:[]})
else
this.pullShixuns({ refresh: 1, showError })
this.user_id = res.user.user_id;
5 years ago
}else if(this.data.status==200){
this.pullShixuns({refresh:2, showError});
}
}).catch(e=>{
if(showError)
app.showError(e);
})
},
5 years ago
setStatus(status){
this.setData({status});
},
pullShixuns({refresh=0, showError= 0}={}){
if(refresh){
if(refresh==1){
this.options.page = 1;
var { options } = this;
}else if(refresh==2){
5 years ago
var {page, per_page, category=""} = this.options;
var options = {page:1, per_page: page*per_page, category};
}
5 years ago
//this.setStatus(1);
}else{
this.options.page++;
var {options} = this;
5 years ago
//this.setStatus(100);
}
return app.api("users.shixuns")(options).then(({shixuns})=>{
5 years ago
let length = shixuns.length;
if (!refresh){
shixuns = this.data.shixuns.concat(shixuns);
5 years ago
var status = length>0?200:204;
}else{
var status = length>0?200:205;
}
this.setData({ shixuns, status});
}).catch(e=>{
if(showError)
app.showError(e);
5 years ago
this.setData({shixuns:[], status:e.code});
})
},
onPullDownRefresh(){
this.pullShixuns({refresh:2, showError: 1});
},
onReachBottom(){
5 years ago
if(this.data.status==200)
this.pullShixuns({refresh:0, showError:1});
}
}
})