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.

85 lines
2.1 KiB

const app = getApp();
5 years ago
const typeMap = {
shixun:{current:0, type:"shixun"},
path: {current:1, type:"subject"},
subject:{current:1, type:"subject"},
course:{current:2, type:"course"}
}
Page({
data: {
keyword:"",
list:[
{text:"实训项目", type:"shixun"},
5 years ago
{text:"实践课程", type:"subject"},
{text:"教学课堂", type:"course"}
]
},
onTapNav({detail:{current, source , value}}){
if(source!='touch') return;
this.setData({current});
this.options.type = value.type;
this.search({refresh:1})
.then(()=>{
this.setData({scrollTop:0});
});
},
onSubmit({detail:{value}}){
this.options.keyword = value.keyword;
this.search({refresh:1});
},
onConfirm({detail:{value}}){
this.options.keyword = value;
this.search({refresh:1});
},
search({refresh=0}={}){
5 years ago
;
if(refresh==1)
this.setData({loading:1});
if(refresh){
if(refresh==1){
this.options.page = 1;
var {options} = this;
}else if(refresh==2){
var {page,per_page,type, keyword} = this.options;
var options = {page:1, per_page:page*per_page, type, keyword};
}
}else{
this.options.page++;
var {options} = this;
}
5 years ago
return app.api("search")(options)
.then(res=>{
let {results,count} = res;
if(refresh==1&&results.length==0)
wx.showToast({
title: '没有找到相关内容',icon:"none"
});
if(!refresh)
results = this.data.results.concat(results);
this.setData({count, results, loading:0});
})
.catch(e=>{
this.setData({loading:0});
})
},
onLoad: function (options) {
5 years ago
let {type:_type="shixun", keyword=""} = options;
let {type, current} = typeMap[_type]||typeMap["shixun"];
this.options = {page:1, per_page:20, type, keyword};
this.search({ refresh: 1 });
this.setData({keyword, current});
},
_onReachBottom: function () {
this.search({refresh:0});
},
onShareAppMessage: function () {
let {type="shixun",keyword=""} = this.options;
return app.shareApp({
path: `/pages/search/search?type=${type}&keyword=${keyword}`
})
}
})