移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
<template>
    <view>
        <u-toast ref="uToast" />
        <form v-for="item in payments" :key="item.code" @submit="toPayHandler" report-submit="true" v-if="!(type == 2 && item.code == 'balancepay')">
            <input name="code" :value="item.code" class="hide">
            <button class="u-reset-button coreshop-list menu-avatar  padding-xl radius shadow shadow-lg bg-blue margin-top" form-type="submit">
                <view class="coreshop-list-item">
                    <view class="coreshop-avatar radius">
                        <u--image width="34px" height="34px" :src="item.icon" :lazy-load="false" :fade="false" duration="0"></u--image>
                    </view>
                    <view class="content">
                        <view class="coreshop-text-grey">{{ item.name }}</view>
                        <view class="coreshop-text-gray coreshop-font-sm flex coreshop-text-left">
                            <view class="u-line-1">
                                {{ item.memo }}
                            </view>
                        </view>
                    </view>
                    <view class="action">
                        <u-tag text="选择此支付方式" mode="dark" type="error" shape="circle" />
                    </view>
                </view>
            </button>
        </form>
 
        <view class="payment-pop" v-show="popShow">
            <view class="payment-pop-c">
                <image src="/static/images/payments/wait-pay.png"></image>
                <view class="text">支付中,请稍后...</view>
            </view>
            <view class="payment-pop-b">
                <button class="coreshop-btn coreshop-btn-c" @click="popHide">支付失败</button>
                <button class="coreshop-btn coreshop-btn-o" @click="popHide">支付成功</button>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        props: {
            // 如果是商品订单此参数必须
            orderId: {
                type: String,
                default() {
                    return ''
                }
            },
            // 如果是充值订单此参数必须
            recharge: {
                type: Number,
                default() {
                    return 0
                }
            },
            // 用户id
            uid: {
                type: Number,
                default() {
                    return 0
                }
            },
            // 订单类型
            type: {
                type: Number,
                default() {
                    return 1
                }
            }
        },
        data() {
            return {
                payments: [],
                popShow: false
            }
        },
        mounted() {
            this.getPayments()
        },
        methods: {
            // 获取可用支付方式列表
            getPayments() {
                this.$u.api.paymentList().then(res => {
                    if (res.status) {
                        this.payments = this.formatPayments(res.data)
                    }
                })
            },
            // 支付方式处理
            formatPayments(payments) {
                // 如果是充值订单 过滤余额支付 过滤非线上支付方式
                if (this.type === 2) {
                    payments = payments.filter(item => item.code !== 'balancepay' || item.isOnline === false)
                }
 
                // 设置logo图片
                payments.forEach(item => {
                    this.$set(item, 'icon', '/static/images/payments/' + item.code + '.png')
                })
 
                return payments
            },
            // 用户点击支付方式处理
            toPayHandler(e) {
                this.popShow = true;
                let code = e.target.value.code;
 
                let data = {
                    payment_code: code,
                    payment_type: this.type,
                    params: {
                        trade_type: 'TT'
                    }
                }
                data['ids'] = (this.type == 1 || this.type == 5 || this.type == 6) ? this.orderId : this.uid
 
                // 判断订单支付类型
                if (this.type == 2 && this.recharge) {
                    data['params']['money'] = this.recharge;
                } else if ((this.type == 5 || this.type == 6) && this.recharge) {
                }
                let _this = this
                switch (code) {
                    case 'wechatpay':
                        this.$u.api.pay(data).then(res => {
                            if (res.status) {
                                uni.pay({
                                    provider: 'wxpay',
                                    orderInfo: res.data.tt_order_info,
                                    service: 1,
                                    getOrderStatus: function (es) {
 
                                    },
                                    success: function (e) {
                                        if (e.code == 0) {
                                            _this.$refs.uToast.show({
                                                message: '支付成功', type: 'success', complete: function () {
                                                    _this.$u.route({ type: 'redirectTo', url: '/pages/payment/result/result?id=' + res.data.paymentId });
                                                }
                                            })
                                        } else if (e.code == 1) {
                                            _this.$u.toast('支付超时');
                                            _this.popHide();
                                        } else if (e.code == 2) {
                                            _this.$u.toast('支付失败');
                                            _this.popHide();
                                        } else if (e.code == 3) {
                                            _this.$u.toast('支付关闭');
                                            _this.popHide();
                                        } else if (e.code == 9) {
                                            _this.$u.toast('支付异常,请联系客服处理。');
                                            _this.popHide();
                                        }
                                    },
                                    fail: function (res) {
                                        console.log(res);
                                    }
                                });
                            } else {
                                this.$u.toast(res.msg);
                            }
                        })
                        break
                    case 'alipay':
                        this.$u.api.pay(data).then(res => {
                            if (res.status) {
                                uni.pay({
                                    provider: 'alipay',
                                    orderInfo: res.data.tt_order_info,
                                    service: 1,
                                    getOrderStatus: function (es) {
 
                                    },
                                    success: function (e) {
                                        if (e.code == 0) {
                                            _this.$refs.uToast.show({
                                                message: '支付成功', type: 'success', complete: function () {
                                                    _this.$u.route({ type: 'redirectTo', url: '/pages/payment/result/result?id=' + res.data.paymentId });
                                                }
                                            })
                                        } else if (e.code == 1) {
                                            _this.$u.toast('支付超时');
                                        } else if (e.code == 2) {
                                            _this.$u.toast('支付失败');
                                        } else if (e.code == 3) {
                                            _this.$u.toast('支付关闭');
                                        } else if (e.code == 9) {
                                            _this.$u.toast('支付异常,请联系客服处理。');
                                        }
                                    }
                                });
                            } else {
                                this.$u.toast(res.msg);
                                _this.popHide();
                            }
                        })
                        break
                    case 'balancepay':
                        /**
                         *  用户余额支付
                         *
                         */
                        this.$u.api.pay(data).then(res => {
                            if (res.status) {
                                this.$u.route({ type: 'redirectTo', url: '/pages/payment/result/result?id=' + res.data.paymentId });
                            } else {
                                this.$u.toast(res.msg);
                                _this.popHide();
                            }
                        })
                        break
                    case 'offline':
                        /**
                         * 线下支付
                         */
                        this.$common.modelShow('线下支付说明', '请联系客服进行线下支付', () => { }, false, '取消', '确定')
                        break
                }
 
            },
            // 支付中显示隐藏
            popHide() {
                this.popShow = false
            }
        }
 
    }
</script>
 
<style lang="scss">
    .coreshop-avatar { background: #fff; }
</style>