Files
2026-09-08 19:49:21 +08:00

235 lines
8.9 KiB
HTML

<!--#
layout("/mobile/platform.html"){
#-->
<style>
.van-cell-group--inset {
margin: 10px 16px 0;
overflow: hidden;
border-radius: 8px;
}
.van-cell-group--inset .van-cell {
font-size: 16px;
}
.van-cell-group--inset .group-title {
font-size: 20px;
font-weight: bold;
}
.scanner-wrap {
margin: 20px 16px 0;
overflow: hidden;
border-radius: 8px;
}
</style>
<div id="app" v-cloak>
<van-sticky>
<van-nav-bar title="扫描二维码"
left-arrow
></van-nav-bar>
</van-sticky>
<van-cell-group class="van-cell-group--inset">
<van-cell>
<span slot="title" class="group-title">用户信息</span>
</van-cell>
<van-cell title="姓名" icon="manager" :value="userInfo.username || '--'"></van-cell>
<van-cell title="工号" icon="card" :value="userInfo.loginname || '--'"></van-cell>
<van-cell title="性别" icon="more" :value="userInfo.sex || '--'"></van-cell>
<van-cell title="单位" icon="wap-home" :value="userInfo.unitname || '--'"></van-cell>
<van-cell title="分工会" icon="wap-home" :value="userInfo.unionname || '--'"></van-cell>
</van-cell-group>
<van-cell-group class="van-cell-group--inset" v-if="showSignInfo">
<van-cell>
<span slot="title" class="group-title">签到信息</span>
</van-cell>
<van-cell title="是否签到" icon="more">
<van-tag type="success" size="large" v-if="signInfo.isAttend===true">已签到</van-tag>
<van-tag type="warning" size="large" v-else-if="signInfo.isAttend===false">未签到</van-tag>
<span v-else-if="signInfo.isAttend===null">--</span>
</van-cell>
<van-cell title="签到时间" icon="clock" :value="signInfo.attendTime || '--'"></van-cell>
</van-cell-group>
<van-cell-group class="van-cell-group--inset" v-if="showGiftInfo">
<van-cell>
<span slot="title" class="group-title">礼品发放信息</span>
</van-cell>
<van-cell title="是否发放" icon="more">
<van-tag type="success" size="large" v-if="signInfo.isReceive===true">已发放</van-tag>
<van-tag type="warning" size="large" v-else-if="signInfo.isReceive===false">未发放
</van-tag>
<span v-else-if="signInfo.isReceive===null">--</span>
</van-cell>
<van-cell title="发放时间" icon="clock" :value="signInfo.receiveTime || '--'"></van-cell>
</van-cell-group>
<div class="scanner-wrap">
<van-button @click="scanner" type="primary" color="#1867b0" block icon="scan">扫描用户二维码
</van-button>
</div>
<div class="scanner-wrap" v-if="scannerResult.type===1">
<van-button @click="confirmSign" type="primary" color="#1867b0" block icon="checked"
:disabled="signInfo.isAttend===true">确认签到
</van-button>
</div>
<div class="scanner-wrap" v-if="scannerResult.type===2">
<van-button @click="grantGift" type="primary" color="#1867b0" block icon="point-gift"
:disabled="signInfo.isReceive===true">发放礼品
</van-button>
</div>
</div>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
var vue = new Vue({
el: '#app',
data() {
return {
userInfo: {},
signInfo: {
isAttend: null,
attendTime: null,
isReceive: null,
receiveTime: null
},
activityInfo: {},
scannerResult: {},
scannerResultKeys: ['userId', 'signId', 'activityId', 'activityCourseId', 'isMobileSign', 'signType', 'isReceiveGift', 'giftType']
}
},
computed: {
showSignInfo() {
const {isMobileSign, signType} = this.scannerResult
return isMobileSign === true && signType === 2
},
showGiftInfo() {
const {isReceiveGift, giftType} = this.scannerResult
return isReceiveGift === true && giftType === 1
}
},
methods: {
scanner() {
this.userInfo = {}
this.signInfo = {
isAttend: null,
attendTime: null
}
wxScannerQrCode.scanner().then(res => {
this.checkScannerResult(res)
}).catch(err => {
vant.Dialog.alert({message: err}).then(() => {
})
})
},
checkScannerResult(resultStr) {
const errMsg = '您扫描的信息不符合要求'
if (typeof resultStr === 'string') {
try {
const result = JSON.parse(resultStr)
const validResultKey = this.scannerResultKeys.every(k => {
return result.hasOwnProperty(k)
})
if (validResultKey) {
this.scannerResult = result
const {
userId,
signId,
activityId,
isMobileSign,
signType,
isReceiveGift,
giftType
} = result
if ((isMobileSign === true && signType === 2) || (isReceiveGift === true || giftType === 1)) {
this.qrCodeInfo(userId, signId, activityId)
} else {
vant.Dialog.alert({message: '此活动不支持该方式'})
}
} else {
vant.Dialog.alert({message: errMsg})
}
} catch (err) {
vant.Dialog.alert({message: errMsg})
}
} else {
vant.Dialog.alert({message: errMsg})
}
},
async qrCodeInfo(userId, signId, activityId) {
const toast = this.$toast.loading({
message: '加载中...',
forbidClick: true,
loadingType: 'spinner',
});
const resp = await $.get(loc() + '/qrCodeInfo', {userId, signId, activityId})
setTimeout(() => {
toast.clear()
if (resp.code === 0) {
this.userInfo = resp.data.userInfo
this.signInfo = resp.data.signInfo
this.activityInfo = resp.data.activityInfo
} else {
this.$toast(resp.msg)
}
}, 500)
},
async signInfo() {
const toast = this.$toast.loading({
message: '加载中...',
forbidClick: true,
loadingType: 'spinner',
});
const resp = await $.get(loc() + '/signInfo', {signId: this.scannerResult.signId})
toast.clear()
if (resp.code === 0) {
this.signInfo = resp.data.signInfo
} else {
this.$toast(resp.msg)
}
},
confirmSign() {
vant.Dialog.confirm({title: '提示', message: '您确认该用户已签到吗?',}).then(async () => {
const resp = await $.post(loc() + '/confirmSignByQrCode', {signId: this.scannerResult.signId})
if (resp.code === 0) {
this.signInfo = resp.data
this.$toast.success('签到成功')
} else {
this.$toast(resp.msg)
}
}).catch(() => {
})
},
grantGift() {
vant.Dialog.confirm({title: '提示', message: '您确认该用户已领取礼品吗?',}).then(async () => {
const resp = await $.post(loc() + '/grantGiftByQrCode', {signId: this.scannerResult.signId})
if (resp.code === 0) {
this.signInfo = resp.data
this.$toast.success('发放成功')
// await this.signInfo()
} else {
this.$toast(resp.msg)
}
}).catch(() => {
})
}
},
async mounted() {
await wxScannerQrCode.initWxConfig(window.location.href)
}
})
</script>
<!--#
}
#-->