rk
2 天以前 4f4538356403d620b9bd510fd45729a251291942
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<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>