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(); }, methods: { onCateChange({detail:{value}}){ ; this.options.category = value.value this.pullPaths({refresh:1}); }, refresh(){ app.syncUser() .then(res => { if (res.user.user_id != this.user_id) { if(res.user_id==2) this.setData({shixuns:[]}) else this.pullPaths({ refresh: 1 }) this.user_id = res.user.user_id; }else if(this.data.status==200){ this.pullPaths({refresh:2}); } }) }, setStatus(status){ this.setData({status}); }, pullPaths({refresh=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.subjects")(options).then(({subjects})=>{ let length = subjects.length; if (!refresh){ subjects = this.data.subjects.concat(subjects); var status = length>0?200:204; }else{ var status = length>0?200:205; } this.setData({ subjects, status}); }).catch(e=>{ this.setData({subjects:[], status:e.code}); }) }, onPullDownRefresh(){ this.pullPaths({refresh:2}); }, onReachBottom(){ if(this.data.status==200) this.pullPaths({refresh:0}); } } })