diff --git a/src/router/index.js b/src/router/index.js
index abc46fe..b8e94f2 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -233,11 +233,23 @@ const routes = [
{
path: '/productsummary/:id',
name: 'productSummary',
- component: () => import('@/views/productSummary.vue'),
+ component: () => import('@/views/ProductSummary.vue'),
meta: {
title: '商品汇总'
}
},
+ {
+ path: '/buydetail',
+ name: 'BuyDetail',
+ component: () => import('../views/BuyDetails.vue'),
+ meta: { title: '确认订单' }
+ },
+ {
+ path: '/pay',
+ name: 'Pay',
+ component: () => import('../views/Pay.vue'),
+ meta: { title: '确认支付' }
+ },
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
diff --git a/src/views/BuyDetails.vue b/src/views/BuyDetails.vue
new file mode 100644
index 0000000..fb36e08
--- /dev/null
+++ b/src/views/BuyDetails.vue
@@ -0,0 +1,647 @@
+
+
+
+
+
+
+
+
+
+
+
{{ shippingAddress }}
+
+
+
+
+
+
+
+
+
![商品主图]()
+
+
+
+ 实付
+
+ {{ totalPrice }}
+
+
+ -
+ {{ quantity }}
+ +
+
+
+
+
+
+
+
+
颜色分类 ({{ categories.length }})
+
+
+
+
![]()
+
+
+
{{ category.name }}
+
{{ category.description }}
+
+
+
+
+
+
+
+
尺寸
+
+
+
{{ size.label }}
+
{{ size.range }}
+
+
+
+
+
+
+
订单备注
+
+
无备注
+
{{ orderNote }}
+
+
+
+
+
+
+
+
+
+
+
+ 加入购物车
+
+
+ 立即购买
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/views/Pay.vue b/src/views/Pay.vue
new file mode 100644
index 0000000..52de885
--- /dev/null
+++ b/src/views/Pay.vue
@@ -0,0 +1,566 @@
+
+
+
+
+
+
+
+
+
+
+
+ {{ formatTime(minutes) }}
+ 分
+
+
:
+
+ {{ formatTime(seconds) }}
+ 秒
+
+
+
+ 请在规定时间内完成支付
+ 支付超时,请重新下单
+
+
+
+
+
+
支付金额
+
+
+ ¥
+ {{ paymentData.totalAmount || 0 }}
+
+
+
+
+ 积分:{{ paymentData.pointsAmount }}
+
+
+
+ 融豆:{{ paymentData.beansAmount }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 实付:
+ ¥{{ paymentData.totalAmount || 0 }}
+
+
+
+ {{ timeLeft <= 0 ? '支付超时' : paying ? '支付中...' : '确认支付' }}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/views/ProductDetail.vue b/src/views/ProductDetail.vue
index e572bef..d2bfdf6 100644
--- a/src/views/ProductDetail.vue
+++ b/src/views/ProductDetail.vue
@@ -104,7 +104,7 @@

-
商品材质||
+ {{product.material}}||
{{ tag }}
- ||品牌||产地
+ ||{{product.brand}}||{{product.origin}}
@@ -432,7 +432,7 @@ const getProductDetail = async () => {
}
}
-const addToCart = async () => {
+const addToCart = () => {
if (!product.value) {
ElMessage.error('商品信息加载中,请稍后再试')
return
@@ -443,51 +443,14 @@ const addToCart = async () => {
return
}
- if (quantity.value <= 0) {
- ElMessage.error('请选择有效数量')
- return
- }
-
- // 检查是否已存在该商品
- const existingItemIndex = cartItems.value.findIndex(item => item.id === product.value.id)
-
- if (existingItemIndex !== -1) {
- // 商品已存在,增加数量
- const existingItem = cartItems.value[existingItemIndex]
- const newQuantity = existingItem.quantity + quantity.value
-
- if (newQuantity > product.value.stock) {
- ElMessage.error(`库存不足,最多只能添加 ${product.value.stock - existingItem.quantity} 个`)
- return
+ // 跳转到BuyDetails页面进行确认订单
+ router.push({
+ path: '/buydetail',
+ query: {
+ productId: product.value.id,
+ quantity: quantity.value
}
-
- existingItem.quantity = newQuantity
- ElMessage.success(`已将 ${quantity.value} 个商品添加到购物车`)
- } else {
- // 新商品,直接添加
- if (quantity.value > product.value.stock) {
- ElMessage.error(`库存不足,最多只能添加 ${product.value.stock} 个`)
- return
- }
-
- const cartItem = {
- id: product.value.id,
- name: product.value.name,
- image: product.value.images?.[0] || product.value.image,
- points: product.value.points,
- quantity: quantity.value,
- stock: product.value.stock
- }
-
- cartItems.value.push(cartItem)
- ElMessage.success(`已将 ${quantity.value} 个商品添加到购物车`)
- }
-
- // 重置数量选择器
- quantity.value = 1
-
- // 同步购物车数据到后端
- await syncCartToBackend()
+ })
}
// 购物车商品管理方法
@@ -625,34 +588,46 @@ const checkoutCart = async () => {
}
const buyNow = async () => {
+ if (!product.value) {
+ ElMessage.error('商品信息加载中,请稍后再试')
+ return
+ }
+
+ if (product.value.stock === 0) {
+ ElMessage.error('商品已售罄')
+ return
+ }
+
try {
- await ElMessageBox.confirm(
- `确定要花费 ${totalPoints.value} 积分兑换 ${quantity.value} 个 ${product.value.name} 吗?`,
- '确认兑换',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }
- )
-
- const orderData = {
- items: [{
- productId: product.value.id,
- quantity: quantity.value,
- points: product.value.points
- }],
- totalPoints: totalPoints.value
+ // 先将商品添加到购物车
+ const cartItem = {
+ productId: product.value.id,
+ quantity: quantity.value,
+ categoryId: selectedCategory.value?.id || null,
+ sizeId: selectedSize.value?.id || null,
+ points: product.value.points,
+ name: product.value.name,
+ image: product.value.images?.[0] || '',
+ stock: product.value.stock
}
+
+ const response = await api.post('/cart/add', cartItem)
- await api.post('/orders', orderData)
-
- ElMessage.success('兑换成功!')
- router.push('/orders')
+ if (response.data.success) {
+ const cartId = response.data.data.cartId
+
+ // 跳转到支付页面
+ router.push({
+ path: '/pay',
+ query: {
+ cartId: cartId
+ }
+ })
+ } else {
+ throw new Error(response.data.message || '添加到购物车失败')
+ }
} catch (error) {
- if (error !== 'cancel') {
- ElMessage.error('兑换失败,请重试')
- }
+ ElMessage.error(error.message || '操作失败,请重试')
}
}