From 53d506c08455553a86b38abbb0bfe5bbf755a61e Mon Sep 17 00:00:00 2001 From: qiaojiale Date: Thu, 17 Jul 2025 18:31:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=B0=83=E7=94=A8=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=20=E9=BB=98=E8=AE=A4=E5=9C=B0=E5=9D=80=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=20=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/shop.js | 3 +- packages/shop/goods/index.vue | 73 +++++++++++++--- packages/shop/shopCar/index.vue | 53 ++++++++++-- packages/shop/submitOrder/index.css | 20 +++++ packages/shop/submitOrder/index.vue | 86 +++++++++++++++---- .../.sourcemap/mp-weixin/common/vendor.js.map | 2 +- .../dev/mp-weixin/project.private.config.json | 11 ++- 7 files changed, 202 insertions(+), 46 deletions(-) diff --git a/api/shop.js b/api/shop.js index 192cd1ce..9a1c0db4 100644 --- a/api/shop.js +++ b/api/shop.js @@ -6,5 +6,6 @@ export const apiArr = { getCarCount:"/api/v2/wechat/commodity/cart/all_count",//购物车数量 addCar:"/api/v2/wechat/commodity/cart/add",//添加购物车 deleteCar:"/api/v2/wechat/commodity/cart/delete",//删除购物车 - updateCar:"/api/v2/wechat/commodity/cart/update", + updateCar:"/api/v2/wechat/commodity/cart/update",//更新购物车信息 + getUserDefAddress:"/api/v2/wechat/commodity/receiving_address/get_default",//获取用户默认地址 } \ No newline at end of file diff --git a/packages/shop/goods/index.vue b/packages/shop/goods/index.vue index 569dbf94..5d7cf613 100644 --- a/packages/shop/goods/index.vue +++ b/packages/shop/goods/index.vue @@ -327,25 +327,67 @@ export default { }, addCar() { - console.log(this.info); - - this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {count:1} - - let carNum = 0 + + let that = this + //如果没有当前商品 直接添加一个 + let goods_id_and_count = [] + this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 } this.info.commodity_goods_info_list.forEach(item => { - carNum += item.cart_count.count + console.log(item); + + goods_id_and_count.push({ + goods_id: item.id, + count: item.cart_count.count + }) }) - this.carNum = carNum + + request(apiArr.updateCar, "POST", { + goods_id_and_count + }).then(res => { + that.getShopCar() + that.getShopCarList() + }) + // let flag = false + // this.carOrderList.forEach(item => { + // if (item.goods_id == this.info.commodity_goods_info_list[this.currentGGIndex].id) { + // flag = true + // } + // }) + // console.log(flag); + + // if (flag) { + + // this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 } + // let carNum = 0 + // this.info.commodity_goods_info_list.forEach(item => { + // carNum += item.cart_count.count + // }) + // this.carNum = carNum + // } else { + + // } + }, changeCar(newValue) { this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value - let carNum = 0 - this.info.commodity_goods_info_list.forEach(item => { - if (item.cart_count) { - carNum += item.cart_count.count + + this.carOrderList.forEach(item=>{ + if(item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id){ + console.log(item,'item'); + item.count = newValue.value } }) + let carNum = 0 + this.carOrderList.forEach(item=>{ + carNum += item.count + }) + // let carNum = 0 + // this.info.commodity_goods_info_list.forEach(item => { + // if (item.cart_count) { + // carNum += item.cart_count.count + // } + // }) this.carNum = carNum }, @@ -357,12 +399,15 @@ export default { this.localHeight = meun.height; this.id = options.id - this.getGoodsInfo() - this.getShopCar() - this.getShopCarList() + }, onReachBottom() { + }, + onShow() { + this.getGoodsInfo() + this.getShopCar() + this.getShopCarList() }, onHide() { diff --git a/packages/shop/shopCar/index.vue b/packages/shop/shopCar/index.vue index 1b379e6f..20a581c6 100644 --- a/packages/shop/shopCar/index.vue +++ b/packages/shop/shopCar/index.vue @@ -31,19 +31,21 @@
{{ item.commodity_goods_info.goods_name }}
-
{{ item.commodity_goods_info.goods_intro }}
+
{{ item.commodity_goods_info.goods_intro }} +
- {{ item.commodity_goods_info.sales_price }} /{{ item.commodity_goods_info.goods_unit }} + {{ item.commodity_goods_info.sales_price }} /{{ + item.commodity_goods_info.goods_unit }}
- - + + {{ item.count }} - + @@ -118,7 +120,15 @@ export default { NavgateTo("1") }, submitOrder() { - NavgateTo("../submitOrder/index") + + let arr = [] + this.shopCarList.forEach(item => { + if (item.checked) { + arr.push(item) + } + }) + + NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`) }, getShopCar() { @@ -126,7 +136,6 @@ export default { res.commodity_cart_list.forEach(item => { item.checked = false }); - console.log(res.commodity_cart_list); this.shopCarTotal = res.total this.shopCarList = res.commodity_cart_list }) @@ -156,8 +165,11 @@ export default { }, // 计算金额 calcTotal() { + let total = 0 this.shopCarList.forEach(item => { + console.log(item); + if (item.checked) { total += item.commodity_goods_info.sales_price * item.count } @@ -165,6 +177,25 @@ export default { this.shopMoney = total }, + minus(item, index) { + let that = this + if (item.count === 1) { + request(apiArr.deleteCar, "POST", { + ids: [item.id] + }).then(res => { + that.shopCarList.splice(index, 1) + that.calcTotal() + }) + } + this.shopCarList[index].count = this.shopCarList[index].count - 1 + this.calcTotal() + }, + add(item, index) { + this.shopCarList[index].count = this.shopCarList[index].count + 1 + this.calcTotal() + }, + + deleteItem() { let that = this uni.showModal({ @@ -174,18 +205,22 @@ export default { if (res.confirm) { let ids = [] that.shopCarList.forEach(item => { - if(item.checked){ + if (item.checked) { ids.push(item.id) + item.checked = false } }) request(apiArr.deleteCar, "POST", { ids - }).then(res=>{ + }).then(res => { uni.showToast({ title: '删除成功', duration: 2000 }); that.getShopCar() + that.calcTotal() + }).catch(err => { + console.log(err); }) } else if (res.cancel) { console.log('用户点击取消'); diff --git a/packages/shop/submitOrder/index.css b/packages/shop/submitOrder/index.css index a4fc681d..14ac1307 100644 --- a/packages/shop/submitOrder/index.css +++ b/packages/shop/submitOrder/index.css @@ -176,4 +176,24 @@ display: flex; align-items: center; justify-content: center; +} + +.address_Info_btn { + background: linear-gradient(91deg, #FF7658 0%, #FF370B 100%); + border-radius: 100rpx 100rpx 100rpx 100rpx; + height: 90rpx; + width: 600rpx; + font-size: 36rpx; + color: #FFFFFF; + display: flex; + align-items: center; + justify-content: center; + margin: 0 auto; +} + +.noneDef{ + display: flex; + align-items: center; + justify-content: center; + width: 100%; } \ No newline at end of file diff --git a/packages/shop/submitOrder/index.vue b/packages/shop/submitOrder/index.vue index cd4f1698..4ee69da8 100644 --- a/packages/shop/submitOrder/index.vue +++ b/packages/shop/submitOrder/index.vue @@ -4,42 +4,49 @@
-
+
收货地址
李佳 15901518415
北京北京市朝阳区珠江绿洲文化广场
-
- -
+ +
+
+
添加收货地址
+
+ +
+
-
-
+
+
- +
-
泰国金枕榴莲
-
商品介绍商品介绍
+
{{ items.commodity_goods_info.goods_name }}
+
{{ items.commodity_goods_info.goods_intro }}
- 125.9 /个 + {{ items.commodity_goods_info.sales_price }} + /{{ items.commodity_goods_info.goods_unit }}
- + - {{ - value }} - + + {{ items.count }} + + @@ -52,10 +59,10 @@
- + @@ -64,7 +71,7 @@