<template>
|
<view class="box">
|
<view class="hezi">
|
<image class="logo" src="/static/images/title_duihuan@2x.png" mode="widthFix"></image>
|
<view class="title">团购自助验券</view>
|
<view class="shuru">
|
<input v-model="code" type="text" placeholder="输入券码" />
|
<image src="/static/icon/ic_saoma@2x.png" mode="widthFix" @click="scanCoupon"></image>
|
</view>
|
<view class="btn" @click="jump">兑换</view>
|
<!-- <view v-if="errorText" class="tips">{{ errorText }}</view> -->
|
</view>
|
</view>
|
</template>
|
|
<script>
|
const VERIFY_PACKAGE_INFO_KEY = 'verifyPackageInfo'
|
|
export default {
|
data() {
|
return {
|
code: '',
|
errorText: '',
|
submitting: false
|
};
|
},
|
methods: {
|
async jump() {
|
const code = this.code.trim()
|
|
if (!code) {
|
this.errorText = '请输入正确的券码'
|
uni.showToast({
|
title: '请输入券码',
|
icon: 'none',
|
duration: 2000
|
})
|
return
|
}
|
|
await this.submitVerify({ code })
|
},
|
async scanCoupon() {
|
if (this.submitting) {
|
return
|
}
|
|
try {
|
const res = await uni.scanCode({
|
scanType: ['qrCode', 'barCode']
|
})
|
|
if (!res.result) {
|
uni.showToast({
|
title: '未识别到券码',
|
icon: 'none',
|
duration: 2000
|
})
|
return
|
}
|
await this.submitVerify({ qrContent: res.result })
|
} catch (error) {
|
if (error && (error.errMsg || '').includes('cancel')) {
|
return
|
}
|
|
uni.showToast({
|
title: '扫码失败,请重试',
|
icon: 'none',
|
duration: 2000
|
})
|
}
|
},
|
async submitVerify(payload) {
|
|
if (this.submitting) {
|
return
|
}
|
|
this.submitting = true
|
|
try {
|
const res = await this.$u.api.scanVerify(payload)
|
|
if (res.code === 200 && res.data && res.data.packageInfo) {
|
uni.setStorageSync(VERIFY_PACKAGE_INFO_KEY, res.data.packageInfo)
|
uni.navigateTo({
|
url: '/pages/success/success'
|
})
|
return
|
}
|
} finally {
|
this.submitting = false
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.box {
|
width: 100%;
|
min-height: 100vh;
|
padding: 20rpx 30rpx;
|
box-sizing: border-box;
|
background-color: #F7F7F7;
|
.hezi {
|
width: 100%;
|
padding: 30rpx;
|
box-sizing: border-box;
|
height: calc(100vh - 40rpx);
|
background: #FFFFFF;
|
border-radius: 8rpx;
|
display: flex;
|
align-items: center;
|
flex-direction: column;
|
.logo {
|
width: 200rpx;
|
margin-top: 140rpx;
|
}
|
.title {
|
font-weight: 600;
|
font-size: 36rpx;
|
color: #222222;
|
margin-top: 40rpx;
|
}
|
.shuru {
|
width: 100%;
|
height: 88rpx;
|
background: #F7F7F7;
|
border-radius: 50rpx;
|
border: 2rpx solid #EEEEEE;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
padding: 0 30rpx;
|
box-sizing: border-box;
|
margin-top: 74rpx;
|
input {
|
flex: 1;
|
text-align: center;
|
height: 100%;
|
font-weight: 400;
|
font-size: 30rpx;
|
color: #999999;
|
}
|
image {
|
flex-shrink: 0;
|
width: 48rpx;
|
height: 48rpx;
|
margin-left: 30rpx;
|
}
|
}
|
.btn {
|
width: 100%;
|
height: 88rpx;
|
line-height: 88rpx;
|
text-align: center;
|
background: #01B6AD;
|
border-radius: 46rpx;
|
font-weight: 500;
|
font-size: 30rpx;
|
color: #FFFFFF;
|
margin-top: 40rpx;
|
}
|
.tips {
|
font-weight: 400;
|
font-size: 26rpx;
|
color: #FC2525;
|
margin-top: 34rpx;
|
}
|
}
|
}
|
</style>
|