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.

121 lines
3.0 KiB

const app = getApp();
const actions = {
"置顶":{
cb:"sticky",
cd:{"sticky":[false]}
},
"取消置顶":{
cb:"cancelSticky",
cd:{"sticky":[true]}
},
"邀请成员":{
cb:"share",
cd:{"course_identity":[2]}
},
"停用邀请码":{
cb: "set_invite_code_halt",
cd: { "invite_code_halt": [0], "course_identity": [2]}
},
"启用邀请码":{
cb:"set_invite_code_halt",
cd: { "invite_code_halt": [1], "course_identity": [2]}
},
"退出课堂":{
cb:"exit_course",
cd:{"course_identity":[5]}
}
}
Component({
properties: {
data:Object,
category:String
},
data: {
eduImgDir:global.config.eduImgDir
},
methods: {
showAction(){
let itemList = this.getActions();
console.log(itemList);
let course = this.data.data;
wx.showActionSheet({
itemList,
success:res=>{
let action = itemList[res.tapIndex];
let cb = actions[action].cb;
this[cb]();
}
})
},
getActions(){
var _actions = [];
for(var name in actions){
var flag = true;
var action = actions[name];
for(var cdt in action.cd){
console.log(action.cd[cdt],this.data.data[cdt])
if(action.cd[cdt].indexOf(this.data.data[cdt])==-1){
flag=false;
break;
}
}
if(flag)
_actions.push(name);
}
return _actions;
},
sticky(){
let course_id = this.data.data.id;
let category = this.data.category;
app.api("weapps.course_stickies")({course_id, category})
.then(res=>{
this.triggerRefresh();
})
.catch(app.showError)
},
share(){
app.navigateTo({url:"{course_invite}?course_id="+this.data.data.id});
},
set_invite_code_halt(){
app.api("courses.set_invite_code_halt")({ course_id: this.data.data.id })
.then(res => {
res.message="操作成功";
app.showMsg(res);
this.triggerRefresh();
})
},
cancelSticky(){
let course_id = this.data.data.id;
let category = this.data.category;
app.api("weapps.course_stickies.cancel_sticky")({ course_id, category })
.then(res => {
this.triggerRefresh();
})
.catch(app.showError)
},
exit_course(){
wx.showModal({
title: '提示',
content: '退出后您将不再是本课题的成员,作品将全部被删除,\n确定要退出该课堂吗',
success:res=>{
if(res.confirm){
app.api("courses.exit_course")({course_id:this.data.data.id})
.then(res=>{
app.showMsg(res);
this.triggerRefresh();
})
.catch(app.showError)
}
}
})
},
edit() {
return;
app.navigateTo({ url: "{course_setting}?course_id" + this.data.data.id });
},
triggerRefresh() {
this.triggerEvent("refresh", {}, { bubbles: true })
},
}
})