const app = getApp(); Page({ data: { course:{ name:"**课堂邀请", teacher_name:"点击最下方按钮", teacher_school:"登陆后查看" }, user:{}, status:0, eduImgDir:global.config.eduImgDir }, onImgError(e){ console.log("onImgError", e); let path = this.getPageUrl(); wx.cloud.callFunction({ name: "openapi", data: { action:"getWXACode", path}}) .then(res=>{ this.setData({invite_code_url:""}); this.setData({invite_code_url: res.result}) }); }, login:function(){ app.navigateTo({ url: '{login}', }); }, onTapCode(){ let data = this.data.course.invite_code || this.data.options.invite_code; wx.setClipboardData({ data }) }, preview(){ wx.previewImage({ urls: [this.data.invite_code_url], }) }, joinCourse: function(event) { //@todo 助教加入.. let invite_code = this.data.course.invite_code||this.data.options.invite_code; let data = { invite_code, student: 1}; if (this.data.course.code_halt){ wx.showToast({ title: '>︿<\n邀请码已经停用了', icon:"none" }); return; } app.api("courses.apply_to_join_course")({ ...data }) .then(res => { app.showMsg(res); wx.redirectTo({ url: "../course/course?course_id=" + res.course_id }); }) .catch(app.showError) }, getPageUrl(){ let { course_id, _invite_code } = this.data.options; let {invite_code=_invite_code} = this.data.course; return app.getPageUrl(`{course_invite}?course_id=${course_id}&invite_code=${invite_code}`); }, getWxaCodeUrl(){ let url = this.getPageUrl(); return global.config.imgDir+"wxacode/"+ url.replace(/[\/?&]/g, "_")+".jpeg"; }, pull_course(){ app.api("weapps.courses.basic_info")({ course_id:this.options.course_id }) .then(({course}) => { this.setData({ course, status: 200}); }).catch(e=>{ app.showError(e); this.setData({status:-1}) }); }, onLoad: function (options) { this.setData({options}); this.setData({status:1}); this.pull_course(); let invite_code_url = this.getWxaCodeUrl(); this.setData({ invite_code_url}); }, onShow:function(){ app.syncUser() .then(({user})=>{ this.setData({user}); }) if(this.data.status==-1) this.pull_course() }, onShareAppMessage(){ } })