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