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.

110 lines
2.8 KiB

import { getWXACodeUrl} from '../../../js/utils';
const app = getApp();
/**
* status:[404,-1]
*/
Page({
data: {
course:{
name:"**课堂邀请",
teacher_name:"点击最下方按钮",
teacher_school:"登录后查看更多",
invite_code:"登录后查看"
},
imgDir:global.config.imgDir,
user:{},
status:0,
eduImgDir:global.config.eduImgDir
},
onImgLoad(e){
console.log("img_loaded",e);
this.setData({code_loaded:1});
},
onImgError(e){
console.log("onImgError", e);
let page = this.getPageUrl();
let scene = this.getScene();
wx.cloud.callFunction({ name: "openapi", data: { action:"getWXACodeUnlimited", page, scene}})
.then(res=>{
this.setData({invite_code_url:""});
this.setData({invite_code_url: res.result})
});
},
login:function(){
app.navigateTo({
url: '{account}',
});
},
onTapCode(){
if(this.data.course.code_halt)
return;
let data = this.data.course.invite_code || this.data.scene.invite_code;
wx.setClipboardData({
data
})
},
preview(){
if(this.data.course.code_halt)
return;
wx.previewImage({
urls: [this.data.invite_code_url],
})
},
joinCourse: function(event) {
if (this.data.course.code_halt||!this.data.course.invite_code)
return wx.showToast({
title: '>︿<\n邀请码已经停用了',
icon:"none"
});
this.setData({show_join_modal:1});
},
getPageUrl(){
return app.getPageUrl(`{course_invite}`,"");
},
getScene(){
let { course_id} = this.data;
return `course_id=${course_id}`
},
pull_course(){
app.api("weapps.courses.basic_info")({ course_id:this.data.course_id })
.then(({course}) => {
this.setData({ course, status: 200});
}).catch(e=>{
app.showError(e);
this.setData({status:-1})
});
},
onLoad: function (options) {
console.log("onLoad", options);
var course_id;
if(options.course_id)
course_id= options.course_id;
else if(options.scene){
var scene = {};
for (var item of decodeURIComponent(options.scene).split("&")){
var [k,v] = item.split("=")
scene[k]=v;
}
course_id = scene.course_id;
}else{
this.setData({status: 404});
return;
}
this.setData({ course_id, status: 1});
let invite_code_url = getWXACodeUrl({url: this.getPageUrl(), scene:this.getScene()});
this.pull_course();
this.setData({ invite_code_url});
},
onShow:function(options){
console.log("onShow", options)
app.syncUser()
.then(({user})=>{
this.setData({user});
})
if(this.data.status==-1)
this.pull_course()
},
onShareAppMessage(){
}
})