From 790510b4f1a623b5120dfcc83ced78f18b262b11 Mon Sep 17 00:00:00 2001 From: chenkainan Date: Mon, 22 Sep 2025 16:29:21 +0800 Subject: [PATCH] 1 --- src/views/Order/Index.vue | 42 ++- src/views/User/OrderList.vue | 2 +- src/views/User/ShoppingCart.vue | 455 ++++++++++++++++++-------------- 3 files changed, 298 insertions(+), 201 deletions(-) diff --git a/src/views/Order/Index.vue b/src/views/Order/Index.vue index 13fa574..2a25c57 100644 --- a/src/views/Order/Index.vue +++ b/src/views/Order/Index.vue @@ -318,6 +318,7 @@ export default { }, // 格式化商品数据(统一价格单位、计算小计等) formatItems(items) { + console.log(items, 13213); return items.map((item) => ({ id: item.sku.id, productId: item.product.id, @@ -328,6 +329,7 @@ export default { quantity: item.quantity, freight: "0.00", // 暂固定,实际项目可从接口获取 deliveryType: "邮寄", + type: item.product.type, // 原逻辑:仅计算商品金额 // subtotal: ((item.sku.price / 100) * item.quantity).toFixed(2), @@ -401,7 +403,7 @@ export default { let total = 0; this.orderGroups.forEach((group) => { group.items.forEach((item) => { - console.log(item) + console.log(item); total += parseFloat(item.freight); }); }); @@ -421,10 +423,12 @@ export default { this.totalGoodsCount = totalCount; this.totalGoodsAmount = totalAmount.toFixed(2); + + this.totalPayAmount = totalAmount.toFixed(2); // 使用最新计算的总运费 - this.totalPayAmount = ( - totalAmount + parseFloat(this.totalFreight) - ).toFixed(2); + // this.totalPayAmount = ( + // totalAmount + parseFloat(this.totalFreight) + // ).toFixed(2); }, // 处理保存地址 handleSaveAddress(formData) { @@ -477,9 +481,33 @@ export default { this.$message.warning("请先选择收货地址"); return; } - this.$message.success("订单提交成功!"); - // 实际项目中可跳转至订单详情页 - // this.$router.push('/order/detail'); + + let goods = []; + this.orderGroups.forEach((group, groupIndex) => { + group.items.forEach((item, itemIndex) => { + console.log(item); + goods.push({ + type: item.type, + product_id: item.productId, + sku_id: item.id, + product_num: item.quantity, + post: this.selectedAddress.id, + remark: group.remark || "", + }); + }); + }); + console.log(goods); + this.post( + { + data: JSON.stringify({ product_list: goods }), + }, + "/api/order/create" + ).then((res) => { + if (res.code == 1) { + this.$message.success("订单提交成功!"); + this.$router.push("/User/OrderList"); + } + }); }, }, }; diff --git a/src/views/User/OrderList.vue b/src/views/User/OrderList.vue index ef8aed7..74030c2 100644 --- a/src/views/User/OrderList.vue +++ b/src/views/User/OrderList.vue @@ -190,7 +190,7 @@ export default { getList() { this.post({ ...this.filterForm, - offset:this.filterForm.currentPage*this.filterForm.limit, + offset:(this.filterForm.currentPage-1)*this.filterForm.limit, customBaseURL:"/api", },'/api/order/list').then(res=>{ this.orders = res.data.list diff --git a/src/views/User/ShoppingCart.vue b/src/views/User/ShoppingCart.vue index 73207ad..ef0540f 100644 --- a/src/views/User/ShoppingCart.vue +++ b/src/views/User/ShoppingCart.vue @@ -1,67 +1,89 @@