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.

103 lines
2.5 KiB

const app = getApp();
//status:[];
const cateTypes={
description:0,
task:1
}
Page({
data:{
shixun:{},
challenges:[],
list:[
{text:"简介"},{text:"任务"}
],
description:""
},
sendToCourse(){
let {id} = this.data.shixun;
this.setData({shixun_ids: [id], showSendDialog: true});
},
collect(){
let {id, is_collect} = this.data.shixun;
let api_name = is_collect?"collections.cancel":"collections";
app.api(api_name)({container_type:"Shixun", container_id:id})
.then(res=>{
;
this.pullShixun({showLoading: 0});
if(is_collect){
res.message = "已取消收藏";
var icon = "success";
var duration = 1500;
}else{
var icon = "none";
var duration = 3000;
}
wx.showToast({
title: res.message,
icon,
duration
})
}).catch(e=>{
;
app.showError(e);
})
},
enterChallenge(){
wx.showLoading({
title: '开启中',
});
this.setData({loading: 1});
app.api("shixuns.shixun_exec")({ identifier:this.data.identifier})
.then(res=>{
app.navigateTo({ url: "{task}?identifier=" + res.game_identifier});
}).catch(e=>{
app.showError(e);
}).finally(e=>{
wx.hideLoading();
this.setData({loading:false})
});
},
scrollTo({scrollTop}){
wx.pageScrollTo({scrollTop,duration:200})
},
switchNav({detail:{current,source}}){
if(source=="touch")
this.setData({current});
},
apiChallenges: app.api("shixuns.challenges"),
apiShixun:app.api("shixuns"),
async pullChallenges(){
let {description, challenge_list:challenges} = await this.apiChallenges({identifier:this.data.identifier});
this.setData({description, challenges});
},
async pullShixun({showLoading=1}={}){
if(showLoading)
wx.showLoading({
title: '努力加载中'
})
let {identifier} = this.data;
let shixun = await this.apiShixun({identifier});
this.setData({shixun}, res=>{
if(showLoading)
wx.hideLoading()
});
},
onLoad: function (options) {
let {identifier,cate_type} = options;
let current = cateTypes[cate_type];
this.setData({identifier, current});
this.pullChallenges().catch(e=>{
});
this.pullShixun().catch(e=>{
app.showError(e);
});
},
onShareAppMessage: function () {
return app.shareApp({
title:this.data.shixun.name,
imageUrl: global.config.eduImgDir+"avatars/Shixun/"+this.data.shixun.id
})
}
})