|
|
|
import { getWXACodeUrl} from "../../../js/utils";
|
|
|
|
const app = getApp();
|
|
|
|
Component({
|
|
|
|
properties: {
|
|
|
|
course_id:Number,
|
|
|
|
course_identity:Number,
|
|
|
|
attendance_id:Number,
|
|
|
|
mode:String,
|
|
|
|
code:String
|
|
|
|
},
|
|
|
|
data:{
|
|
|
|
attachDir:global.config.attachDir
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
onShow(){
|
|
|
|
if(this.data.status!=200)
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
onLoad(options){
|
|
|
|
if(options.scene){
|
|
|
|
;
|
|
|
|
let scene = decodeURIComponent(options.scene);
|
|
|
|
let [attendance_id, mode, code] = scene.split("-");
|
|
|
|
this.setData({attendance_id, mode, code,course_identity:5});
|
|
|
|
}
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
previewQrCode(){
|
|
|
|
let {code_url} = this.data;
|
|
|
|
wx.previewImage({
|
|
|
|
urls: [code_url]
|
|
|
|
});
|
|
|
|
},
|
|
|
|
copyCode(){
|
|
|
|
let {name, start_time,end_time, code} = this.data;
|
|
|
|
let data = `签到名称:${name}\n签到时间:${start_time}-${end_time}\n签到码:${code}`;
|
|
|
|
wx.setClipboardData({data});
|
|
|
|
},
|
|
|
|
onCodeLoadError(e) {
|
|
|
|
;
|
|
|
|
let page = this.route;
|
|
|
|
let scene = this.getScene();
|
|
|
|
;
|
|
|
|
wx.cloud.callFunction({ name: "openapi", data: { action: "getWXACodeUnlimited", name:"wxacode.getUnlimited", page, scene , data:{page, scene}} })
|
|
|
|
.then(res => {
|
|
|
|
this.setData({ code_url: "" });
|
|
|
|
this.setData({ code_url: res.result.fileID||res.result });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
navBack(){
|
|
|
|
if(getCurrentPages().length<=1){
|
|
|
|
let {course_identity, course_id} = this.data;
|
|
|
|
let {code,message} = this.data;
|
|
|
|
if(code!=200&&message)
|
|
|
|
return app.reLaunch({url:"{main}"});//@todo
|
|
|
|
app.redirectTo({
|
|
|
|
url: `{attendance}?course_identity=${course_identity}&course_id=${course_id}`
|
|
|
|
});
|
|
|
|
}else
|
|
|
|
wx.navigateBack({
|
|
|
|
delta:1
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onSubmit(e){
|
|
|
|
let { detail: { value } } = e;
|
|
|
|
let { scaned_code, mode } = this.data;
|
|
|
|
;
|
|
|
|
if(!value.code&&mode!="QUICK") return;
|
|
|
|
value.attendance_mode = mode;
|
|
|
|
if(mode=='QRCODE'){
|
|
|
|
if(value.code!=scaned_code){
|
|
|
|
value.attendance_mode="NUMBER";
|
|
|
|
return wx.showToast({
|
|
|
|
title: '只支持扫二维码签到',icon:"none"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mode=="QUICK")
|
|
|
|
delete value.code;
|
|
|
|
if(this.data.code&&this.data.code!='undefined'&&value.code!=this.data.code&&mode!="QUICK")
|
|
|
|
return wx.showToast({
|
|
|
|
title: '签到码不正确', icon: "none"
|
|
|
|
});
|
|
|
|
app.api("weapps.course_member_attendances")(value)
|
|
|
|
.then(res => {
|
|
|
|
res.message = "签到成功";
|
|
|
|
app.showMsg(res);
|
|
|
|
setTimeout(()=>{
|
|
|
|
this.navBack();
|
|
|
|
},800);
|
|
|
|
}).catch(e => {
|
|
|
|
app.showError(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
scanCode(){
|
|
|
|
wx.scanCode({
|
|
|
|
success:res=>{
|
|
|
|
var fail = false;
|
|
|
|
if (res.scanType == "QR_CODE")
|
|
|
|
this.setData({ scaned_code: res.result});
|
|
|
|
else if (res.scanType == "WX_CODE" && res.path) {
|
|
|
|
var match = res.path.match(/attendance_detail\?(.*)$/)
|
|
|
|
;
|
|
|
|
var options = {}
|
|
|
|
match[1].split("&").map(i => {
|
|
|
|
var index = i.indexOf("=");
|
|
|
|
var k = i.slice(0, index);
|
|
|
|
var v = i.slice(index + 1);
|
|
|
|
options[k] = v
|
|
|
|
})
|
|
|
|
;
|
|
|
|
if(options.scene){
|
|
|
|
let [attendance_id, mode, scaned_code] = decodeURIComponent(options.scene).split("-");
|
|
|
|
if(scaned_code)
|
|
|
|
this.setData({scaned_code});
|
|
|
|
else
|
|
|
|
fail = false;
|
|
|
|
}else{
|
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
if (fail)
|
|
|
|
wx.showToast({title: "识别失败", icon: "none"})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
refresh(){
|
|
|
|
let {course_identity} = this.data;
|
|
|
|
if(course_identity){
|
|
|
|
let {attendance_id} = this.data;
|
|
|
|
app.api("weapps.attendances")({attendance_id})
|
|
|
|
.then(res=>{
|
|
|
|
this.setData(res);
|
|
|
|
this.setData({status:200, message:""});
|
|
|
|
if(course_identity<5&&res.mode=="QRCODE"){
|
|
|
|
let code_url = getWXACodeUrl({url: this.route, scene: this.getScene()});
|
|
|
|
this.setData({code_url});
|
|
|
|
}
|
|
|
|
}).catch(e=>{
|
|
|
|
if(e.code==402)
|
|
|
|
e.message = "你没有访问权限";
|
|
|
|
app.showError(e);
|
|
|
|
this.setData({status: e.code, message:e.message});
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
this.refreshIdentity()
|
|
|
|
.then(res=>{
|
|
|
|
if(this.data.course_identity)
|
|
|
|
this.refresh();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getScene(){
|
|
|
|
let {mode, code, attendance_id} = this.data;
|
|
|
|
return attendance_id+"-"+mode+"-"+code;
|
|
|
|
},
|
|
|
|
refreshIdentity(){
|
|
|
|
let {course_id} = this.data;
|
|
|
|
return app.api("courses.top_banner")({course_id})
|
|
|
|
.then(res=>{
|
|
|
|
;
|
|
|
|
let {course_identity} = res;
|
|
|
|
this.setData({course_identity});
|
|
|
|
})
|
|
|
|
},
|
|
|
|
analyseWxaCode(){
|
|
|
|
|
|
|
|
},
|
|
|
|
onShareAppMessage(){
|
|
|
|
let {attendance_id, mode, code, course_id} = this.data;
|
|
|
|
return app.shareApp({
|
|
|
|
imageUrl: global.config.attachDir + "753481",
|
|
|
|
path:"/" + this.route+`?course_identity=5&attendance_id=${attendance_id}&code=${code||''}&mode=${mode}&course_id=${course_id}`,
|
|
|
|
title:"课堂签到-"+this.data.name
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|