石广澎
2025-11-17 8771da2ccf6f7c3fd2a8c89a1a0e230c6386db7f
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<template>
    <view>
        <view class="u-relative">
            <view class="u-p-30 u-flex">
                <image :src="info.logo_image||'/static/imgs/store-logo.png'" class="avg-img"></image>
                <view class="u-font-32 font-bold color-333 u-m-l-20">{{ info.shop_name }}</view>
            </view>
            <view class="pay-box bg-fff">
                <view class="u-font-24 color-666">金额</view>
                <view class="u-p-v-20 u-flex u-border-bottom-f5 u-relative">
                    <view class="money-icon color-333">¥</view>
                    <view class="u-flex-1 u-flex u-m-l-10" style="height: 80rpx;">
                        <view v-if="money" class="u-font-40">{{money}}</view>
                        <view v-if="!money&&bordShow" class="cursor"></view>
                        <view v-if="!money" class="u-font-32 color-999">请输入金额</view>
                        <view v-if="money&&bordShow" class="cursor"></view>
                    </view>
                    <!-- <u-input placeholder="请输入金额" v-model="money" border="none" disabled disabledColor="#FFFFFF"
                        placeholderStyle="color: #c0c4cc" fontSize="40rpx" color="#333"></u-input> -->
                    <view class="mask" @click="showBord"></view>
                </view>
                <view class="u-font-24 color-666 u-p-v-20">选择支付方式</view>
                <view>
                    <u-radio-group v-model="payType" placement="column">
 
                        <view v-if="platform == 0 || platform == 2"
                            class="u-border-bottom-f5 u-p-v-20 u-flex u-row-between">
                            <view class="flex-1 u-flex">
                                <image src="@/static/imgs/pay-wx.png" class="pay-icon"></image>
                                <view class="u-font-30 color-333 u-m-l-10">微信</view>
                            </view>
                            <u-radio :name="0" activeColor="#D41F28" :customStyle="{ marginLeft: '30rpx' }"></u-radio>
                        </view>
                        <view v-if="platform == 1 || platform == 2"
                            class="u-border-bottom-f5 u-p-v-20 u-flex u-row-between">
                            <view class="flex-1 u-flex">
                                <image src="@/static/imgs/pay-zfb.png" class="pay-icon"></image>
                                <view class="u-font-30 color-333 u-m-l-10">支付宝</view>
                            </view>
                            <u-radio :name="1" activeColor="#D41F28" :customStyle="{ marginLeft: '30rpx' }"></u-radio>
                        </view>
                        <view class="u-border-bottom-f5 u-p-v-20 u-flex u-row-between">
                            <view class="flex-1 u-flex">
                                <image src="@/static/imgs/pay-jyk.png" class="pay-icon"></image>
                                <view class="u-m-l-10 flex-1 u-flex u-row-between">
                                    <view>
                                        <view class="u-font-30 color-333">金燕卡(8646)</view>
                                        <view class="u-font-24 color-999">
                                            可用
                                            <text class="color-red">15</text>
                                            积分
                                            <text class="color-red">满40-20</text>
                                            优惠券
                                        </view>
                                    </view>
                                    <u-tag text="享8折优惠" type="error" plain size="mini"></u-tag>
                                </view>
                            </view>
                            <u-radio :name="2" activeColor="#D41F28" :customStyle="{ marginLeft: '30rpx' }"></u-radio>
                        </view>
                    </u-radio-group>
                </view>
                <button class="pay-it" @click="pay">确定支付</button>
            </view>
 
        </view>
 
        <navigator class="reg-btn" :url="'/pages/pay/register?cid='+cid">
            <image src="/static/register-btn.png" mode=""></image>
        </navigator>
        <u-popup :show="bordShow" :overlay="false" @close="close" @open="open">
            <key-bord @changeMoney="changeMoney" :num.sync="money" @close="close" @pay="pay"></key-bord>
        </u-popup>
    </view>
</template>
 
<script>
    import {
        config
    } from '@/common/config.js';
    import {
        queryShop,
        getWechatInfo,
        getWechatConfigInfo,
        saveWxOrder
    } from '@/common/api/index'
    import wx from 'weixin-js-sdk'; // 使用js-sdk
    export default {
        data() {
            return {
        platform: this.$utils.getPlat(),
                cid: '',
                info: {
                    shop_name: '',
                    scan_flag: '',
                    use_score_flag: '',
                    user_coupon_flag: ''
                },
                hasNum: false, // 是否输入金额
                money: '', // 金额
                transStyles: {
                    position: 'fixed',
                    bottom: 0,
                    left: 0,
                    width: '100%',
                    backgroundColor: '#FFFFFF',
                    zIndex: 1001
                },
                payType: this.$utils.getPlat(), // 支付方式
                bordShow: false // 显示键盘
            };
        },
        onLoad(opt) {
            this.cid = opt.cid
            uni.showLoading()
            queryShop({
                params: opt
            }).then(res => {
                if (res.logo_image) {
                    try {
                        let arr = JSON.parse(res.logo_image)
                        res.logo_image = config.sftpURL + arr[0].path
                    } catch (e) {
                        //TODO handle the exception
                        res.logo_image = ''
                    }
                }
                this.info = res
                this.registerSDK()
            }).catch(() => {
                uni.hideLoading()
            })
        },
        methods: {
            registerSDK() {
                const uri = encodeURIComponent(window.location)
                getWechatConfigInfo({
                    url: uri
                }).then(res => {
                    uni.hideLoading()
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。
                        appId: res.appId, // 必填,公众号的唯一标识
                        timestamp: res.timestamp, // 必填,生成签名的时间戳
                        nonceStr: res.nonceStr, // 必填,生成签名的随机串
                        signature: res.signature, // 必填,签名
                        jsApiList: ['chooseWXPay'] // 必填,需要使用的 JS 接口列表
                    });
                }).catch(() => {
                    uni.hideLoading()
                })
            },
            // 更新金额
            changeMoney(str) {
                this.money = str;
            },
            // 展示键盘
            showBord() {
                this.bordShow = true;
            },
            // 关闭键盘
            close() {
                this.bordShow = false;
            },
            pay() {
                if (!this.money) {
                    uni.showToast({
                        icon: 'none',
                        title: '请输入金额'
                    });
                    return;
                }
                uni.showLoading()
                saveWxOrder({
                    cusid: this.info.cusid,
                    c: this.info.c,
                    money: parseInt(this.money * 100)
                }).then(res => {
                    uni.hideLoading()
                    setTimeout(() => {
                        wx.chooseWXPay({
                            timestamp: res.timeStamp, // 支付签名时间戳
                            nonceStr: res.nonceStr, // 支付签名随机串,不长于 32 位
                            package: res.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
                            signType: res.signType, // 微信支付V3的传入 RSA ,微信支付V2的传入格式与V2统一下单的签名格式保持一致
                            paySign: res.paySign, // 支付签名
                            success: function(ret) {
                                // 支付成功后的回调函数
                                uni.navigateTo({
                                    url: '/pages/pay/paySuccess?youHuiInfo=' + JSON
                                        .stringify(res.youHuiInfo)
                                })
                            }
                        });
                    }, 200)
 
                }).catch(() => {
                    uni.hideLoading()
                })
            }
        }
    };
</script>
 
<style scoped lang="scss">
    .avg-img {
        width: 80rpx;
        height: 80rpx;
    }
 
    .reg-btn {
        display: block;
        margin: 80rpx auto 0;
        width: 686rpx;
        height: 198rpx;
 
        image {
            width: 100%;
            height: 100%;
        }
    }
 
    .pay-box {
        padding: 40rpx 20rpx;
        border-radius: 10rpx;
        margin: 0 30rpx;
    }
 
    .money-icon {
        font-size: 50rpx;
        font-weight: bold;
        margin-right: 20rpx;
    }
 
    .money-num {
        font-size: 50rpx;
        font-weight: bold;
    }
 
    .pay-icon {
        width: 48rpx;
        height: 48rpx;
    }
 
    .mask {
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        bottom: 0;
        z-index: 101;
        background-color: rgba(0, 0, 0, 0);
    }
 
    .pay-it {
        border-radius: 50rpx;
        font-size: 34rpx;
        color: #ffffff;
        background-color: #de2d35;
        width: 90%;
        margin-top: 20rpx;
    }
 
    @keyframes cursor-blinks {
        0% {
            opacity: 1;
            display: block;
        }
 
        50% {
            opacity: 0;
            display: none;
        }
 
        100% {
            opacity: 1;
            display: block;
        }
    }
 
    .cursor {
        border-left: 1px solid #333;
        margin-left: 2px;
        height: 40rpx;
        animation: cursor-blinks 1s infinite steps(1, start)
    }
 
    .cursor-act {
        border-left-color: transparent;
        animation: cursor-blinks 1s infinite steps(1, start);
    }
</style>