| | |
| | | <image class="logo" src="/static/images/title_duihuan@2x.png" mode="widthFix"></image> |
| | | <view class="title">团购自助验券</view> |
| | | <view class="shuru"> |
| | | <input type="text" placeholder="输入券码" /> |
| | | <image src="/static/icon/ic_saoma@2x.png" mode="widthFix"></image> |
| | | <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 class="tips">请输入正确的券码</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: { |
| | | jump() { |
| | | uni.navigateTo({ |
| | | url: '/pages/success/success' |
| | | }) |
| | | 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 |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | </style> |
| | | </style> |