order-confirm.vue
9.55 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<template>
<view class="page-shell order-confirm-page">
<view class="page-blur"></view>
<view class="page-blur-secondary"></view>
<view class="page-blur-tertiary"></view>
<view class="page-content subpage-content">
<view class="subpage-nav">
<view class="subpage-back" @tap="goBack">‹</view>
<view class="subpage-title-wrap">
<text class="subpage-title">确认订单</text>
<text class="subpage-subtitle">支付后自动生成取件码,到自提门店出示核销即可自提</text>
</view>
</view>
<view class="subpage-card">
<view class="section-head">
<text class="section-title">自提门店</text>
<text class="section-link">到店自提</text>
</view>
<view v-if="stores.length" class="store-row">
<view
v-for="store in stores"
:key="store.id || store.name"
class="store-chip"
:class="{ active: selectedStoreId && selectedStoreId === store.id }"
@tap="selectStore(store)"
>
<text class="store-chip-name">{{ store.name }}</text>
<text class="store-chip-addr">{{ store.address }}</text>
</view>
</view>
<text v-if="storesLoading" class="store-tip">门店加载中…</text>
<text v-else-if="!hasValidStore" class="store-tip">
暂无可自提门店,请稍后重试或联系客服。
</text>
</view>
<view class="product-card glass-card">
<image v-if="product.coverImg" class="product-image" :src="product.coverImg" mode="aspectFill" />
<view class="product-copy">
<text class="product-name">{{ product.productName }}</text>
<text class="product-spec">{{ selectedSku ? selectedSku.skuName : '默认规格' }} · {{ quantity }} 件</text>
<text v-if="product.description" class="product-desc">{{ product.description }}</text>
<text class="product-price">¥{{ unitPrice }}</text>
</view>
</view>
<view class="subpage-card">
<view class="form-item no-border">
<text class="form-label">订单备注</text>
<input v-model="remark" class="form-input" placeholder="可填写备注(选填)" placeholder-class="form-placeholder" />
</view>
</view>
<view class="subpage-card">
<view class="info-list">
<view class="info-row">
<text class="info-label">商品单价</text>
<text class="info-value">¥{{ unitPrice }}</text>
</view>
<view class="info-row">
<text class="info-label">购买数量</text>
<text class="info-value">{{ quantity }}</text>
</view>
<view class="info-row">
<text class="info-label">提货方式</text>
<text class="info-value">到店自提</text>
</view>
<view class="info-row">
<text class="info-label">实付金额</text>
<text class="info-value accent">¥{{ totalAmount }}</text>
</view>
</view>
</view>
<view class="cta-row">
<view class="secondary-button" @tap="goBack">返回商品</view>
<view class="primary-button" :class="{ disabled: submitting }" @tap="submitOrder">提交并支付</view>
</view>
</view>
</view>
</template>
<script>
import { getMallDetail, getPickupStores, createOrder, prepay, mockPay } from '@/api/mall'
import { STORES, DEFAULT_STORE_ID } from '@/utils/config'
export default {
data() {
return {
productId: '',
skuId: '',
quantity: 1,
product: {},
selectedSku: null,
stores: [],
storesLoading: false,
selectedStoreId: DEFAULT_STORE_ID || '',
remark: '',
submitting: false
}
},
computed: {
hasValidStore() {
return this.stores.some(s => s.id)
},
unitPrice() {
return this.selectedSku ? this.selectedSku.price : (this.product.price || 0)
},
totalAmount() {
return (Number(this.unitPrice) * Number(this.quantity)).toFixed(2)
}
},
onLoad(options) {
this.productId = options.productId
this.skuId = options.skuId || ''
this.quantity = Number(options.quantity) || 1
this.loadStores()
this.loadDetail()
},
methods: {
// 拉取真实自提门店;失败时回退到 config.js 占位列表
loadStores() {
this.storesLoading = true
getPickupStores({})
.then((list) => {
const stores = Array.isArray(list) ? list : []
this.stores = stores.length ? stores : STORES
})
.catch(() => {
this.stores = STORES
})
.then(() => {
this.storesLoading = false
if (!this.selectedStoreId) {
const firstValid = this.stores.find(s => s.id)
if (firstValid) this.selectedStoreId = firstValid.id
}
})
},
loadDetail() {
getMallDetail(this.productId)
.then((data) => {
this.product = data || {}
const skus = (data && data.skus) || []
if (this.skuId) {
this.selectedSku = skus.find(s => String(s.id) === String(this.skuId)) || null
}
})
.catch(() => {})
},
selectStore(store) {
if (!store.id) {
uni.showToast({ title: '该门店未配置真实 Id', icon: 'none' })
return
}
this.selectedStoreId = store.id
},
goBack() {
uni.navigateBack({ fail: () => uni.redirectTo({ url: `/packageMall/product-detail/product-detail?id=${this.productId}` }) })
},
submitOrder() {
if (this.submitting) return
if (!this.selectedStoreId) {
uni.showToast({ title: '请选择自提门店', icon: 'none' })
return
}
this.submitting = true
uni.showLoading({ title: '提交中', mask: true })
const item = { ProductId: this.productId, Quantity: this.quantity }
if (this.skuId) item.SkuId = this.skuId
createOrder({
StoreId: this.selectedStoreId,
Remark: this.remark,
Items: [item]
})
.then((order) => {
const orderId = order && order.orderId
if (!orderId) throw new Error('下单失败')
return this.payOrder(orderId)
})
.catch(() => {
uni.hideLoading()
this.submitting = false
})
},
// 预支付后按 mock / 真实两种分支处理
payOrder(orderId) {
return prepay({ OrderId: orderId }).then((pay) => {
if (pay && pay.mock === true) {
// 支付未配置:直接走 MockPay 完成联调
return mockPay({ OrderId: orderId }).then(() => {
uni.hideLoading()
this.submitting = false
this.goSuccess(orderId)
})
}
// 真实环境:使用后端返回的 prepayParams 调起微信支付
const params = (pay && pay.prepayParams) || {}
uni.hideLoading()
uni.requestPayment({
provider: 'wxpay',
timeStamp: params.timeStamp,
nonceStr: params.nonceStr,
package: params.package,
signType: params.signType,
paySign: params.paySign,
success: () => {
// TODO: 微信支付回调(PayNotify)会异步置订单为已支付;
// 这里也可主动查询订单状态确认,再进入成功页。
this.submitting = false
this.goSuccess(orderId)
},
fail: () => {
this.submitting = false
uni.showToast({ title: '支付未完成', icon: 'none' })
}
})
})
},
goSuccess(orderId) {
uni.redirectTo({ url: `/packageMall/payment-success/payment-success?orderId=${orderId}` })
}
}
}
</script>
<style lang="scss" scoped>
@import '@/styles/mixins.scss';
@import '@/styles/subpage.scss';
.store-row {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.store-chip {
flex: 1;
min-width: 30%;
padding: 20rpx 22rpx;
border-radius: 24rpx;
background: rgba(255, 255, 255, 0.82);
border: 1rpx solid rgba(210, 191, 156, 0.16);
transition: transform 240ms ease, background 240ms ease, border-color 240ms ease;
}
.store-chip.active {
background: rgba(100, 140, 118, 0.12);
border-color: rgba(100, 140, 118, 0.4);
}
.store-chip-name,
.store-chip-addr {
display: block;
}
.store-chip-name {
font-size: 26rpx;
font-weight: 600;
color: $text-primary;
}
.store-chip-addr {
margin-top: 8rpx;
font-size: 22rpx;
color: $text-secondary;
}
.store-tip {
display: block;
margin-top: 16rpx;
font-size: 22rpx;
line-height: 1.7;
color: $brand-rose;
}
.product-card {
display: flex;
padding: 28rpx;
margin-bottom: 24rpx;
}
.product-image {
width: 180rpx;
height: 180rpx;
border-radius: 28rpx;
flex-shrink: 0;
}
.product-copy {
flex: 1;
margin-left: 22rpx;
}
.product-name,
.product-spec,
.product-desc,
.product-price {
display: block;
}
.product-name {
font-size: 30rpx;
line-height: 1.5;
font-weight: 700;
}
.product-spec,
.product-desc {
margin-top: 12rpx;
font-size: 24rpx;
line-height: 1.7;
color: $text-secondary;
}
.product-price {
margin-top: 16rpx;
font-size: 36rpx;
font-weight: 700;
color: $brand-primary-deep;
}
.form-item {
padding: 8rpx 0;
}
.form-item.no-border {
border-bottom: 0;
}
.form-label {
display: block;
font-size: 22rpx;
color: $text-tertiary;
letter-spacing: 2rpx;
}
.form-input {
margin-top: 14rpx;
height: 60rpx;
font-size: 28rpx;
color: $text-primary;
}
.form-placeholder {
color: $text-tertiary;
}
.accent {
color: $brand-primary-deep;
}
</style>