payOrder.vue
5.91 KB
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
<template>
<view class="pay-order-container">
<!-- 页面头部 -->
<view class="page-header">
<text class="title">确认并支付</text>
</view>
<!-- 订单核心信息 -->
<view class="order-info">
<view class="info-item">
<text class="label">人数合计:</text>
<text class="value red">{{ formData.all ?? 0 }}人</text>
</view>
<view class="info-item">
<text class="label">新会员合计:</text>
<text class="value red">{{ formData.new ?? 0 }}人</text>
</view>
<view class="info-item">
<text class="label">续费会员合计:</text>
<text class="value red">{{ formData.old ?? 0 }}人</text>
</view>
<view class="info-item total-price">
<text class="label">支付总费用:</text>
<text class="value red">{{ formData.price ?? 0 }}元</text>
</view>
</view>
<!-- 支付方式选择(修复v-model报错 + 默认勾选) -->
<view class="pay-type-section">
<text class="section-title">选择支付方式</text>
<!-- uni-app小程序原生radio-group写法 -->
<radio-group :value="payType" @change="handlePayTypeChange">
<label class="radio-item">
<!-- checked属性实现默认勾选 -->
<radio :checked="payType === '0'" color="#E60012" value="0"/>
<view class="pay-method">
<image :src="config.baseUrl_api + '/fs/static/min.png'" class="icon" mode="widthFix"></image>
<text class="pay-name">民生付</text>
</view>
</label>
</radio-group>
</view>
<!-- 底部支付按钮 -->
<view class="fixed-bottom">
<button :loading="payLoading" class="pay-btn red-bg" @click="handlePay">立即支付</button>
</view>
</view>
</template>
<script setup>
import {
ref
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app';
import * as api from '@/common/api.js'
import config from '@/config.js'
import {minShengPay} from "@/common/pay";
// 核心数据
const formData = ref({}) // 订单统计数据
const rangeId = ref('') // 核心业务ID
const payType = ref('0') // 支付方式(默认0=民生付)
const payLoading = ref(false) // 支付按钮加载状态
// 页面加载接收参数
onLoad(async (options) => {
console.log('订单ID:', options.rangeId)
if (options.rangeId) {
rangeId.value = options.rangeId
await getCount()
}
})
async function getCount() {
try {
const res = await api.getNewCountByRangeId(rangeId.value)
formData.value = res.data || {
all: 0,
new: 0,
old: 0
}
} catch (e) {
formData.value = {
all: 0,
new: 0,
old: 0
}
}
}
// 支付方式切换
function handlePayTypeChange(e) {
payType.value = e.detail.value
}
// 立即支付核心逻辑
async function handlePay() {
// 基础校验
if (!rangeId.value || rangeId.value === '-1') {
return uni.showToast({
title: '订单ID异常',
icon: 'none'
})
}
try {
payLoading.value = true
const res = await api.goPay(rangeId.value, '2')
if (res.data.payResult && res.data.payResult.encryptedData) {
const reason = await minShengPay(res.data.orderId, res.data.payResult.encryptedData)
if (reason == 'OK') {
// // 支付成功,跳转到成功页面
// uni.redirectTo({
// url: `/myCenter/sucPay?orderId=${res.data.orderId}`
// })
uni.showToast({title: '支付成功', icon: 'success'});
setTimeout(() => {
uni.navigateBack();
}, 1500)
}
}
// 跳转到支付成功页
} catch (err) {
const errMsg = err?.data?.msg || err?.message || '支付失败,请稍后重试'
uni.showToast({
title: errMsg,
icon: 'none'
})
} finally {
payLoading.value = false
}
}
</script>
<style lang="scss" scoped>
.pay-order-container {
padding: 30rpx;
background-color: #fff;
min-height: 100vh;
box-sizing: border-box;
}
.icon {
width: 30px;
}
// 页面头部
.page-header {
text-align: center;
padding: 20rpx 0;
border-bottom: 1px solid #eee;
margin-bottom: 40rpx;
.title {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
}
// 订单信息区域
.order-info {
margin-bottom: 60rpx;
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 25rpx 0;
border-bottom: 1px solid #f5f5f5;
font-size: 32rpx;
.label {
color: #666;
}
.value {
font-weight: 600;
font-size: 34rpx;
}
.red {
color: #E60012;
}
}
.total-price {
border-bottom: none;
margin-top: 10rpx;
.label {
font-size: 34rpx;
color: #333;
}
.value {
font-size: 38rpx;
}
}
}
// 支付方式区域
.pay-type-section {
margin-bottom: 80rpx;
.section-title {
font-size: 32rpx;
color: #333;
margin-bottom: 20rpx;
display: block;
}
.radio-item {
display: flex;
align-items: center;
font-size: 32rpx;
padding: 10rpx 0;
.pay-method {
display: flex;
align-items: center;
margin-left: 10rpx;
.pay-name {
font-size: 32rpx;
margin-left: 20rpx;
color: #333;
}
}
}
}
// 底部支付按钮
.fixed-bottom {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 20rpx 30rpx 30rpx;
background-color: #fff;
border-top: 1px solid #eee;
.pay-btn {
width: 100%;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 34rpx;
font-weight: 600;
}
.red-bg {
background-color: #E60012;
color: #fff;
}
}
</style>