|
|
@@ -9,7 +9,7 @@
|
|
|
<!-- 左侧:大图区域 -->
|
|
|
<div class="goods-cover">
|
|
|
<div class="cover-image">
|
|
|
- <img v-if="goodsInfo.product?.cover" :src="goodsInfo.product.cover" alt="商品封面">
|
|
|
+ <img v-if="goodsInfo.image" :src="goodsInfo.image" alt="商品封面">
|
|
|
<div v-else class="no-image">暂无图片</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -143,7 +143,7 @@
|
|
|
|
|
|
<script setup>
|
|
|
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'
|
|
|
-import { useRoute } from 'vue-router'
|
|
|
+import { useRoute, useRouter } from 'vue-router'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { ChatDotRound ,Coin} from '@element-plus/icons-vue'
|
|
|
import Header from './components/header.vue'
|
|
|
@@ -155,6 +155,7 @@ import { createOrder, createQrCode, checkOrderStatus } from '/@/api/frontend/ord
|
|
|
defineOptions({ name: 'ClientOrder' })
|
|
|
|
|
|
const route = useRoute()
|
|
|
+const router = useRouter()
|
|
|
|
|
|
const goodsId = ref(null)
|
|
|
const goodsInfo = ref({})
|
|
|
@@ -276,21 +277,40 @@ const createOrderAndQrCode = async () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (!qrCodeRes.data.code_url) {
|
|
|
+ // 根据接口返回数据结构,使用 qr_code_url 或 qr_code_content
|
|
|
+ const qrCodeValue = qrCodeRes.data.qr_code_url || qrCodeRes.data.qr_code_content
|
|
|
+ if (!qrCodeValue) {
|
|
|
ElMessage.error(qrCodeRes.data.msg || '二维码生成失败,请重试')
|
|
|
qrCodeLoading.value = false
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- qrCodeUrl.value = qrCodeRes.data.code_url
|
|
|
+ // 更新订单信息,使用接口返回的数据
|
|
|
+ if (qrCodeRes.data.order_no) {
|
|
|
+ currentOrderInfo.value.order_no = qrCodeRes.data.order_no
|
|
|
+ }
|
|
|
+ if (qrCodeRes.data.pay_amount) {
|
|
|
+ currentOrderInfo.value.total_amount = qrCodeRes.data.pay_amount
|
|
|
+ currentOrderInfo.value.amount = qrCodeRes.data.pay_amount
|
|
|
+ currentOrderInfo.value.total_price = qrCodeRes.data.pay_amount
|
|
|
+ }
|
|
|
+ if (qrCodeRes.data.payment_id) {
|
|
|
+ currentOrderInfo.value.payment_id = qrCodeRes.data.payment_id
|
|
|
+ }
|
|
|
+ if (qrCodeRes.data.expire_time) {
|
|
|
+ currentOrderInfo.value.expire_time = qrCodeRes.data.expire_time
|
|
|
+ }
|
|
|
+
|
|
|
+ qrCodeUrl.value = qrCodeValue
|
|
|
qrCodeLoading.value = false
|
|
|
payStatus.value = ''
|
|
|
|
|
|
// 3. 显示支付弹窗
|
|
|
payDialogVisible.value = true
|
|
|
|
|
|
- // 4. 开始轮询支付状态
|
|
|
- startPayStatusPolling(orderId, orderRes.data.order_no)
|
|
|
+ // 4. 开始轮询支付状态(使用接口返回的 order_no,如果没有则使用原来的)
|
|
|
+ const orderNo = qrCodeRes.data.order_no || orderRes.data.order_no
|
|
|
+ startPayStatusPolling(orderId, orderNo)
|
|
|
} catch (error) {
|
|
|
console.error('下单失败:', error)
|
|
|
ElMessage.error(error?.message || '下单失败,请重试')
|
|
|
@@ -328,8 +348,7 @@ const startPayStatusPolling = (orderId, orderNo) => {
|
|
|
const res = await checkOrderStatus(checkData)
|
|
|
|
|
|
// 支付状态判断:1-已支付,0-待支付,2-支付失败,3-已取消
|
|
|
- // 兼容不同的数据结构(可能返回 pay_status 或 status 字段)
|
|
|
- const status = res.data?.pay_status ?? res.data?.status ?? res.data?.order?.pay_status
|
|
|
+ const status = res.data?.order.pay_status
|
|
|
|
|
|
if (status == '1') {
|
|
|
// 支付成功
|
|
|
@@ -349,7 +368,7 @@ const startPayStatusPolling = (orderId, orderNo) => {
|
|
|
setTimeout(() => {
|
|
|
handlePaySuccess()
|
|
|
}, 3000)
|
|
|
- } else if (status === 2 || status === 3 || status === 'failed' || status === 'cancelled' || status === '2' || status === '3') {
|
|
|
+ } else if (status === '2' || status == '3') {
|
|
|
// 支付失败或已取消
|
|
|
payStatus.value = 'failed'
|
|
|
stopPayStatusPolling()
|
|
|
@@ -362,6 +381,7 @@ const startPayStatusPolling = (orderId, orderNo) => {
|
|
|
// 查询失败不中断轮询,继续尝试(除非超过最大次数)
|
|
|
if (payCheckCount.value > MAX_PAY_CHECK_COUNT) {
|
|
|
stopPayStatusPolling()
|
|
|
+ router.push({ name: 'success', params: { id: currentOrderInfo.value.id } })
|
|
|
}
|
|
|
}
|
|
|
}, 3000)
|
|
|
@@ -393,7 +413,7 @@ const handlePaySuccess = () => {
|
|
|
ElMessage.success('支付成功!')
|
|
|
|
|
|
// 可以在这里跳转到订单详情页或订单列表页
|
|
|
- // router.push({ name: 'OrderDetail', params: { id: currentOrderInfo.value.id } })
|
|
|
+ router.push({ name: 'success', params: { id: currentOrderInfo.value.id } })
|
|
|
|
|
|
// 重置状态
|
|
|
qrCodeUrl.value = ''
|
|
|
@@ -477,7 +497,7 @@ onBeforeUnmount(() => {
|
|
|
border-radius: 14px;
|
|
|
overflow: hidden;
|
|
|
background: #f2f6fc;
|
|
|
- min-height: 300px;
|
|
|
+ min-height: 200px;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|