Files
income_payments_applet/pages/scanSign/scanSign.js
T

286 lines
7.1 KiB
JavaScript

import UserApi from '../../assets/js/http/userApi'
import {baseUrl, URL_CONFIG} from '../../assets/js/project.config.js'
import {
isLogin,
isLoginSignIn
} from '../../assets/js/common'
Page({
/**
* 页面的初始数据
*/
data: {
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
form: {},
isSigned: 1, // 是否报名
fileId: '', // 图片id
src: null ,// 签名之后,保存签名的图片地址
meetingTypeText:""
},
goBack(){
wx.switchTab({
url: '../home/home',
})
},
/*
* 会议类型
* */
initMeetingType(typeObj) {
let val = typeObj.meetingType
console.log(val);
if (val) {
switch (val +'') {
case '1':
return '工作组会议'
case '2':
switch (typeObj.tbMeetingType + '') {
case '1':
return '标协会议-标准宣贯'
case '2':
return '标协会议-培训会'
case '3':
return '标协会议-信息交流会'
}
break
case '3':
return '国际研讨会'
case '4':
return '其他会议'
case '5':
return '分标委会议'
case '6':
return '理事会会议'
}
} else {
return ''
}
},
// 去签到页
scanSign(){
wx.navigateTo({
url: '../writtenSign/writtenSign',
})
},
// 确定签到
sureSign(){
let params = {
fileId: this.data.fileId,
meetingId: this.data.form.meetingId
}
UserApi.scanSure(params).then(res=>{
if(res.success){
this.setData({
'form.checkIn': 1
})
}else{
this.setData({
'form.checkIn': 0
})
if(res.message == '签到图片'){
wx.showToast({
title: '请手动签到',
icon: "none",
duration: 2000
})
}else{
wx.showToast({
title: res.message,
icon: "none",
duration: 2000
})
}
}
}).catch(err => {
wx.showToast({
title: '加载失败',
icon: 'none',
duration: 2000
})
})
},
// 去报名
goSignUp(){
// 国际研讨会去国际研讨会的报名
if(this.data.form.meetingType !== 3){
wx.navigateTo({
url: `../signUpPage/signUpPage?meetingId=${this.data.form.meetingId}`,
})
}else{
wx.navigateTo({
url: `../signUpPageGuoji/signUpPageGuoji?meetingId=${this.data.form.meetingId}`,
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const that = this
// 这里是 微信扫码进入的逻辑
// 微信扫码 判断是否登录
if(options.q || true) {
let url = decodeURIComponent(options.q)
let meetingId = url.split('=')[1]
// 登录过的就直接签到 否则跳转登录页
isLoginSignIn( () => {
// 通过会议id 获取签到信息
UserApi.scanCode({
meetingId
}).then(res => {
if (res.success) {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
let src
if(res.result.checkFile){ // 签到名回显
src = baseUrl + URL_CONFIG + 'sys/common/download/' + res.result.checkFile
}else{
src = ''
}
this.setData({
isSigned: 1,
src
})
// wx.navigateTo({ // 已报名
// url: `../scanSign/scanSign?signed=1&meeting=${result}`,
// })
} else {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
// 未查到报名信息
that.setData({
isSigned: 0,
})
}
}).catch(err => {})
},meetingId)
}
// 这里是会议详情的跳转签到
if(options.type === 'meetingDetail'){
let meetingId = options.meetingId
UserApi.scanCode({
meetingId
}).then(res => {
// wx.showToast({
// title: '获取签到信息...',
// icon: 'loading'
// })
if (res.success) {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
let src
if(res.result.checkFile){ // 签到名回显
src = baseUrl + URL_CONFIG + 'sys/common/download/' + res.result.checkFile
}else{
src = ''
}
this.setData({
isSigned: 1,
src
})
// wx.navigateTo({ // 已报名
// url: `../scanSign/scanSign?signed=1&meeting=${result}`,
// })
} else {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
// wx.showToast({
// title: '未查到报名信息...',
// icon: 'loading'
// })
// 未查到报名信息
that.setData({
isSigned: 0,
})
}
}).catch(err => {})
}
// 这里是小程序内部的扫码签到
if(options.meeting){
let meeting = JSON.parse(options.meeting)
let src
if(meeting.checkFile){ // 签到名回显
src = baseUrl + URL_CONFIG + 'sys/common/download/' + meeting.checkFile
}else{
src = ''
}
this.setData({
isSigned: options.signed,
src
})
let form = JSON.parse(options.meeting)
this.setData({
form,
meetingTypeText:that.initMeetingType(form)
})
}
// 这里是微信扫描失败 重新登录后 跳转签到页面执行的逻辑 isLoginSignIn是会议id
if(options.isLoginSignIn){
//请出缓存中的 isLoginSignIn 防止下次登录出现问题
wx.removeStorage({
key: 'isLoginSignIn',
})
let meetingId = options.isLoginSignIn
UserApi.scanCode({
meetingId
}).then(res => {
if (res.success) {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
let src
if(res.result.checkFile){ // 签到名回显
src = baseUrl + URL_CONFIG + 'sys/common/download/' + res.result.checkFile
}else{
src = ''
}
this.setData({
isSigned: 1,
src
})
// wx.navigateTo({ // 已报名
// url: `../scanSign/scanSign?signed=1&meeting=${result}`,
// })
} else {
that.setData({
form:res.result,
meetingTypeText:this.initMeetingType(res.result)
})
// 未查到报名信息
that.setData({
isSigned: 0,
})
}
}).catch(err => {})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
}
})