hookehuyr

feat(支付): 添加订单状态处理逻辑

在微信支付组件中添加订单状态检查,根据状态决定是否初始化支付流程或直接标记为成功。同时在购物车上下文中返回订单状态,并在结账页面中传递该状态。
...@@ -72,6 +72,10 @@ const props = defineProps({ ...@@ -72,6 +72,10 @@ const props = defineProps({
72 orderId: { 72 orderId: {
73 type: String, 73 type: String,
74 required: true 74 required: true
75 + },
76 + orderStatus: {
77 + type: String,
78 + required: true
75 } 79 }
76 }) 80 })
77 81
...@@ -187,9 +191,15 @@ const handlePayment = async () => { ...@@ -187,9 +191,15 @@ const handlePayment = async () => {
187 } 191 }
188 192
189 onMounted(() => { 193 onMounted(() => {
190 - // 初始化微信支付 194 + if (props.orderStatus === 'NOT_PAY') {
191 - initWxPay() 195 + // 初始化微信支付
192 - // 开始支付流程 196 + initWxPay()
193 - handlePayment() 197 + // 开始支付流程
198 + handlePayment()
199 + }
200 + if (props.orderStatus === 'PAY') {
201 + paymentStatus.value = 'success'
202 + emit('success')
203 + }
194 }) 204 })
195 </script> 205 </script>
......
...@@ -129,6 +129,7 @@ export function provideCart(mode = CartMode.MULTIPLE) { ...@@ -129,6 +129,7 @@ export function provideCart(mode = CartMode.MULTIPLE) {
129 return { 129 return {
130 success: true, 130 success: true,
131 orderId: response.data.id, 131 orderId: response.data.id,
132 + orderStatus: response.data.status,
132 orderData: orderData 133 orderData: orderData
133 } 134 }
134 } 135 }
......
...@@ -251,6 +251,7 @@ ...@@ -251,6 +251,7 @@
251 <WechatPayment 251 <WechatPayment
252 v-if="showPayment && orderId" 252 v-if="showPayment && orderId"
253 :order-id="orderId" 253 :order-id="orderId"
254 + :order-status="orderStatus"
254 @success="handlePaymentSuccess" 255 @success="handlePaymentSuccess"
255 @failed="handlePaymentFailed" 256 @failed="handlePaymentFailed"
256 @processing="handlePaymentProcessing" 257 @processing="handlePaymentProcessing"
...@@ -318,6 +319,7 @@ onMounted(async () => { ...@@ -318,6 +319,7 @@ onMounted(async () => {
318 // 支付相关状态 319 // 支付相关状态
319 const showPayment = ref(false) 320 const showPayment = ref(false)
320 const orderId = ref('') 321 const orderId = ref('')
322 +const orderStatus = ref('')
321 const isProcessing = ref(false) 323 const isProcessing = ref(false)
322 const orderComplete = ref(false) 324 const orderComplete = ref(false)
323 325
...@@ -359,6 +361,8 @@ const handleSubmit = async (e) => { ...@@ -359,6 +361,8 @@ const handleSubmit = async (e) => {
359 } 361 }
360 362
361 orderId.value = result.orderId || '' 363 orderId.value = result.orderId || ''
364 + orderStatus.value = result.orderStatus || ''
365 +
362 if (!orderId.value) { 366 if (!orderId.value) {
363 throw new Error('订单号获取失败,请重试') 367 throw new Error('订单号获取失败,请重试')
364 } 368 }
......