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.

74 lines
1.8 KiB

5 years ago
const app = getApp();
5 years ago
Component({
properties: {
},
data: {
5 years ago
shixun_list:[]
},
attached(){
this.options = {page:1, limit: 10};
this.pullShixuns({refresh:1});
5 years ago
},
methods: {
5 years ago
clear(){
this.setData({keyword:"", showClear:0});
this.options.keyword = "";
this.pullShixuns({refresh:1});
},
onInput(e){
let {detail:{value}} = e;
if(this.data.showClear&&!value){
this.clear();
}else if(!this.data.showClear&&value){
this.setData({showClear:1});
}
},
onSubmit(e){
console.log(e)
let {detail:{value}} = e;
if(this.options.keyword!=value){
this.options.keyword = value;
this.pullShixuns({refresh:1});
}
},
onPullDownRefresh(){
this.pullShixuns({refresh:1});
},
onReachBottom(){
if(this.data.status==200)
this.pullShixuns();
},
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 = {...this.options,page:1, per_page: page*per_page};
}
}else{
this.options.page++;
var {options} = this;
}
wx.showNavigationBarLoading();
return app.api("shixun_lists")(options).then(({shixun_list})=>{
let length = shixun_list.length;
if (!refresh){
shixun_list = this.data.shixun_list.concat(shixun_list);
var status = length>0?200:204;
}else{
var status = length>0?200:205;
}
this.setData({ shixun_list, status}, wx.hideNavigationBarLoading);
}).catch(e=>{
this.setData({ shixun_list:[], status:e.code}, wx.hideNavigationBarLoading);
})
}
5 years ago
}
})