|
|
|
|
|
|
|
const app = getApp();
|
|
|
|
Component({
|
|
|
|
properties: {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
data: {
|
|
|
|
shixun_list:[]
|
|
|
|
},
|
|
|
|
attached(){
|
|
|
|
this.options = {page:1, limit: 10};
|
|
|
|
this.pullShixuns({refresh:1});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
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);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|