diff --git a/src/router/index.js b/src/router/index.js
index 61f8a05..e7f424d 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -264,10 +264,10 @@ const routes = [
meta: { title: '地址管理', requiresAuth: true }
},
{
- path: '/payfailed',
- name: 'PayFailed',
- component: () => import('../views/PayFailed.vue'),
- meta: { title: '支付失败' },
+ path: '/payloading',
+ name: 'PayLoading',
+ component: () => import('../views/PayLoading.vue'),
+ meta: { title: '支付确认' },
props: route => ({ cartId: route.query.cartId })
},
{
diff --git a/src/views/BuyDetails.vue b/src/views/BuyDetails.vue
index 6500a0f..5b6bb47 100644
--- a/src/views/BuyDetails.vue
+++ b/src/views/BuyDetails.vue
@@ -19,49 +19,7 @@
-
-
-
-
-
-
-
-
- {{ address.recipientName }} {{ address.recipientPhone }}
- 默认
-
-
{{ address.province }}{{ address.city }}{{ address.district }}{{ address.detailAddress }}
-
-
-
-
- 暂无收货地址
-
- 立即添加
-
-
-
-
+
@@ -159,7 +117,6 @@ import { ElMessage } from 'element-plus'
import {
ArrowLeft,
Close,
- Location,
Edit,
Coin,
ArrowRight
@@ -175,9 +132,6 @@ const product = ref(null)
const quantity = ref(1)
const specGroups = ref({}) // 动态规格组
const selectedSpecs = ref({}) // 选中的规格值
-const addresses = ref([])
-const selectedAddressId = ref('')
-const selectedAddress = ref(null)
const orderNote = ref('')
const showNoteEdit = ref(false)
const availableSpecs = ref({}) // 存储每个规格选项的可选状态
@@ -404,11 +358,6 @@ const handlePurchase = async () => {
}
}
- if (!selectedAddress.value) {
- ElMessage.error('请选择收货地址')
- return
- }
-
// 获取选中规格对应的规格规则ID
const specificationId = getSelectedSpecificationId()
if (!specificationId) {
@@ -417,34 +366,31 @@ const handlePurchase = async () => {
}
try {
- // 创建单独的购买订单
- const orderData = {
- productId: product.value.id, // 商品ID
- quantity: quantity.value, // 购买数量
- specificationId: specificationId, // 规格规则ID
- points: product.value.points, // 商品积分价格
- name: product.value.name, // 商品名称
- image: product.value.image, // 商品图片
- stock: product.value.stock, // 商品库存
- addressId: selectedAddress.value.id, // 收货地址ID
- orderNote: orderNote.value // 订单备注
+ // 构建商品数据,直接跳转到Pay页面
+ const purchaseData = {
+ items: [{
+ id: product.value.id,
+ productId: product.value.id,
+ name: product.value.name,
+ image: product.value.image,
+ points: product.value.points,
+ quantity: quantity.value,
+ specificationId: specificationId,
+ specs: Object.keys(selectedSpecs.value).map(specName =>
+ `${specName}: ${selectedSpecs.value[specName].name}`
+ ).join(', '),
+ orderNote: orderNote.value
+ }]
}
-
- const response = await api.post('/cart/buy-now', orderData)//立即购买
- if (response.data.success) {
- const cartId = response.data.data.cartId
-
- // 跳转到支付页面
- router.push({
- path: '/pay',
- query: {
- cartId: cartId
- }
- })
- } else {
- throw new Error(response.data.message || '创建订单失败')
- }
+ // 跳转到Pay页面,传递商品数据
+ router.push({
+ path: '/pay',
+ query: {
+ from: 'buydetails',
+ cartData: JSON.stringify(purchaseData)
+ }
+ })
} catch (error) {
ElMessage.error(error.message || '操作失败,请重试')
}
@@ -483,8 +429,8 @@ const handleAddToCart = async () => {
if (response.data.success) {
ElMessage.success('商品已加入购物车!')
- // 可以选择返回上一页或跳转到购物车页面
- router.go(-1)
+ // 成功添加后留在当前页面,让用户可以继续操作
+ router.push('/cart')
} else {
throw new Error(response.data.message || '添加到购物车失败')
}
@@ -493,51 +439,7 @@ const handleAddToCart = async () => {
}
}
-// 获取用户地址列表
-const getAddressList = async () => {
- try {
- const response = await api.get('/addresses')
- console.log('获取地址列表响应:', response)
- if (response.data.success) {
- // 根据接口文档转换数据格式,与Address.vue保持一致
- const addressList = response.data.data || []
- addresses.value = addressList.map(addr => ({
- id: addr.id,
- recipientName: addr.receiver_name,
- recipientPhone: addr.receiver_phone,
- province: addr.province_name,
- city: addr.city_name,
- district: addr.district_name,
- detailAddress: addr.detailed_address,
- isDefault: addr.is_default,
- labelName: addr.label_name,
- labelColor: addr.label_color
- }))
-
- // 如果有默认地址,自动选中
- const defaultAddress = addresses.value.find(addr => addr.isDefault)
- if (defaultAddress) {
- selectedAddressId.value = defaultAddress.id
- selectedAddress.value = defaultAddress
- }
- } else {
- throw new Error(response.data.message || '获取地址列表失败')
- }
- } catch (error) {
- console.error('获取地址列表失败:', error)
- ElMessage.error(error.message || '获取地址列表失败')
- }
-}
-// 处理地址选择变化
-const handleAddressChange = (addressId) => {
- selectedAddress.value = addresses.value.find(addr => addr.id === addressId)
-}
-
-// 跳转到地址管理页面
-const goToAddressManage = () => {
- router.push('/address')
-}
// 生命周期
onMounted(() => {
@@ -548,7 +450,6 @@ onMounted(() => {
}
getProductInfo() // 商品信息中已包含规格信息,无需单独获取颜色分类和尺寸
- getAddressList()
})
@@ -585,27 +486,7 @@ onMounted(() => {
padding: 0;
}
-.address-section {
- background: white;
- padding: 16px;
- margin-bottom: 8px;
-}
-.address-header {
- display: flex;
- align-items: center;
- gap: 8px;
- margin-bottom: 8px;
-}
-
-.address-label {
- font-weight: 500;
-}
-
-.edit-icon {
- margin-left: auto;
- color: #666;
-}
@@ -746,68 +627,7 @@ onMounted(() => {
color: #999;
}
-.address-select {
- width: 100%;
- margin-top: 10px;
-}
-.manage-address-btn {
- color: #409eff;
- font-size: 14px;
- margin-left: auto;
-}
-
-.manage-address-btn:hover {
- color: #66b1ff;
-}
-
-.address-option {
- padding: 8px 0;
-}
-
-.address-info {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 4px;
-}
-
-.recipient-info {
- font-weight: 500;
- color: #303133;
-}
-
-.default-tag {
- margin-left: 8px;
-}
-
-.address-detail {
- color: #606266;
- font-size: 12px;
- line-height: 1.4;
-}
-
-.no-address {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20px;
- color: #909399;
- font-size: 14px;
-}
-
-.no-address-text {
- margin-right: 8px;
-}
-
-.add-address-btn {
- color: #409eff;
- font-size: 14px;
-}
-
-.add-address-btn:hover {
- color: #66b1ff;
-}
.note-input {
flex: 1;
diff --git a/src/views/Cart.vue b/src/views/Cart.vue
index a5f2388..d92443d 100644
--- a/src/views/Cart.vue
+++ b/src/views/Cart.vue
@@ -163,7 +163,9 @@ const selectedCount = computed(() => {
const totalPrice = computed(() => {
return selectedItems.value.reduce((total, item) => {
- return total + (item.points * item.quantity)
+ const points = parseFloat(item.product?.points_price) || 0
+ const quantity = parseInt(item.quantity) || 0
+ return total + (points * quantity)
}, 0)
})
@@ -177,6 +179,7 @@ const loadCartData = async () => {
if (response.data.success) {
cartItems.value = response.data.data.items.map(item => ({
...item,
+ quantity: parseInt(item.quantity) || 1,
selected: false
}))
console.log(cartItems)
@@ -285,30 +288,17 @@ const checkout = async () => {
}
try {
- const cartData = {
- items: selectedItems.value.map(item => ({
- productId: item.productId || item.id,
- quantity: item.quantity,
- points: item.points,
- name: item.name,
- image: item.image,
- categoryId: item.categoryId,
- sizeId: item.sizeId
- }))
- }
+ // 只发送选中商品的id数组
+ const selectedIds = selectedItems.value.map(item => item.id)
- const response = await api.post('/cart/checkout', cartData)
+ // 向后端发送选中商品的id数组创建订单
+ const response = await api.post('/order/create-from-cart', {
+ cart_item_ids: selectedIds
+ })
if (response.data.success) {
- const cartId = response.data.data.cartId
-
- // 跳转到支付页面
- router.push({
- path: '/pay',
- query: {
- cartId: cartId
- }
- })
+ // 直接跳转到支付页面,不传递任何参数
+ router.push('/pay')
} else {
throw new Error(response.data.message || '创建订单失败')
}
@@ -326,48 +316,61 @@ onMounted(() => {
\ No newline at end of file
diff --git a/src/views/MyLogin.vue b/src/views/MyLogin.vue
index ed5a5e2..0873de5 100644
--- a/src/views/MyLogin.vue
+++ b/src/views/MyLogin.vue
@@ -103,6 +103,22 @@
-->
+
+
+