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.
148 lines
3.8 KiB
148 lines
3.8 KiB
|
|
const app = getApp();
|
|
Component({
|
|
properties: {
|
|
|
|
},
|
|
|
|
data: {
|
|
shixun_list:[]
|
|
},
|
|
pageLifetimes:{
|
|
show(){
|
|
/*
|
|
let {status} = this.data;
|
|
console.log("show",status);
|
|
if(status<0)
|
|
this.pullShixuns({refresh:2 ,showError:0});
|
|
//limit param somehow don't work!
|
|
*/
|
|
}
|
|
},
|
|
attached(){
|
|
this.options = {page:1, limit: 10};
|
|
let key = "cache-shixun_list"
|
|
let cache_shixun_list = wx.getStorageSync(key);
|
|
if(cache_shixun_list)
|
|
this.setData({shixun_list: cache_shixun_list});
|
|
else
|
|
wx.showLoading({title: '努力加载中'});
|
|
this.pullShixuns({refresh:1, showError: !cache_shixun_list})
|
|
.then(res=>{
|
|
if(res.shixun_list)
|
|
wx.setStorageSync(key, res.shixun_list);
|
|
})
|
|
this.selects = {};
|
|
},
|
|
methods: {
|
|
clear(){
|
|
this.setData({keyword:"", showClear:0});
|
|
this.options.keyword = "";
|
|
this.pullShixuns({refresh:1, showError: 0});
|
|
},
|
|
onInput(e){
|
|
let {detail:{value}} = e;
|
|
if(this.data.showClear&&!value){
|
|
this.clear();
|
|
}else if(!this.data.showClear&&value){
|
|
this.setData({showClear:1});
|
|
}
|
|
},
|
|
onSelect(e){
|
|
let {detail} = e;
|
|
this.selects[detail.name] = detail.value;
|
|
if(detail.value&&!this.data.select)
|
|
this.setData({select: true});
|
|
else if(!detail.value&&!this.data.select){
|
|
console.error("something unexpected happens");
|
|
}
|
|
else if(detail.from=='radio'){
|
|
let length = 0;
|
|
for(var i in this.selects){
|
|
if(this.selects[i])
|
|
length++;
|
|
}
|
|
if(length==0){
|
|
this.setData({select: false});
|
|
this.selects = {};
|
|
}
|
|
}
|
|
},
|
|
reset(e){
|
|
this.setData({select:false});
|
|
this.selects = {}
|
|
},
|
|
onSubmit(e){
|
|
if(!this.data.select)
|
|
this.setData({select: true});
|
|
else{
|
|
let shixun_ids = [];
|
|
for(var i in this.selects){
|
|
if(this.selects[i])
|
|
shixun_ids.push(parseInt(i));
|
|
}
|
|
if(shixun_ids.length==0){
|
|
wx.showToast({
|
|
title: '请选择实训',icon:"none"
|
|
})
|
|
}else{
|
|
this.setData({shixun_ids});
|
|
this.setData({showSendDialog: true});
|
|
}
|
|
}
|
|
},
|
|
search(e){
|
|
let {detail:{value}} = e;
|
|
if(this.options.keyword!=value){
|
|
this.options.keyword = value;
|
|
this.pullShixuns({refresh:1});
|
|
}
|
|
},
|
|
onPullDownRefresh(){
|
|
this.pullShixuns({refresh:1});
|
|
},
|
|
onReachBottom(){
|
|
let {status} = this.data;
|
|
if(status!=205&&status!=204)
|
|
this.pullShixuns();
|
|
},
|
|
pullShixuns({refresh=0, showError=1}={}){
|
|
if(refresh){
|
|
if(refresh==1){
|
|
this.options.page = 1;
|
|
var { options } = this;
|
|
}else if(refresh==2){
|
|
var {page, limit} = this.options;
|
|
var options = {...this.options,page:1, limit: page*limit};
|
|
}
|
|
}else{
|
|
this.options.page++;
|
|
var {options} = this;
|
|
}
|
|
wx.showNavigationBarLoading();
|
|
return app.api("shixun_lists")(options).then(res=>{
|
|
let {shixun_list} = res;
|
|
let length = shixun_list.length;
|
|
if (!refresh){
|
|
shixun_list = this.data.shixun_list.concat(shixun_list);
|
|
var status = length>0?200:204;
|
|
}else{
|
|
this.selects = {};
|
|
this.setData({select: false});
|
|
var status = length>0?200:205;
|
|
}
|
|
this.setData({ shixun_list, status}, wx.hideNavigationBarLoading);
|
|
wx.hideLoading();
|
|
return res;
|
|
}).catch(e=>{
|
|
console.log("error!!!!",e, showError)
|
|
this.setData({status:e.code}, wx.hideNavigationBarLoading);
|
|
wx.hideLoading();
|
|
if(showError)
|
|
app.showError(e);
|
|
return e;
|
|
})
|
|
}
|
|
}
|
|
})
|