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.

132 lines
3.2 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});
this.selects = {};
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});
}
},
onChange(e){
5 years ago
;
},
onSelect(e){
let {detail} = e;
5 years ago
;
this.selects[detail.name] = detail.value;
if(detail.value&&!this.data.select)
this.setData({select: true});
else if(!detail.value&&!this.data.select){
5 years ago
console.error("something unexpected happens");
}
else if(detail.from=='radio'){
let length = 0;
for(var i in this.selects){
if(this.selects[i])
length++;
}
5 years ago
;
if(length==0){
this.setData({select: false});
this.selects = {};
}
}
},
onReset(e){
5 years ago
;
this.setData({select:false});
this.selects = {}
},
5 years ago
onSubmit(e){
5 years ago
;
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(i);
}
5 years ago
;
if(shixun_ids.length==0){
wx.showToast({
title: '请选择实训',icon:"none"
})
}else{
this.select_shixun_ids = shixun_ids;
this.setData({showSendDialog: true});
}
}
},
search(e){
5 years ago
5 years ago
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{
5 years ago
this.selects = {};
this.setData({select: false});
5 years ago
var status = length>0?200:205;
}
this.setData({ shixun_list, status}, wx.hideNavigationBarLoading);
}).catch(e=>{
if(refresh)
this.setData({ shixun_list:[], status:e.code}, wx.hideNavigationBarLoading);
else
this.setData({status:e.code}, wx.hideNavigationBarLoading);
5 years ago
})
}
5 years ago
}
})