From a139ec38c907e6d246d9b2a0a53fc87fec425150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Fri, 24 Oct 2025 16:11:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=9A=84=E8=AF=A6=E6=83=85=E9=A1=B5=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=8C=89=E9=92=AE=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shop/goods/index.css | 5 +++ packages/shop/goods/index.vue | 77 +++++++++++++++++------------------ 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/packages/shop/goods/index.css b/packages/shop/goods/index.css index 97d5a318..05c65f12 100644 --- a/packages/shop/goods/index.css +++ b/packages/shop/goods/index.css @@ -284,6 +284,11 @@ image { margin-top: 26rpx; } +.car_right_disabled { + background: #CCCCCC; + color: #FFFFFF; +} + .cars { display: flex; flex-direction: column; diff --git a/packages/shop/goods/index.vue b/packages/shop/goods/index.vue index d6ce0c60..efa34eac 100644 --- a/packages/shop/goods/index.vue +++ b/packages/shop/goods/index.vue @@ -175,30 +175,22 @@ 加入购物车 - - - - - - - - - {{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }} - - - - - - + + 加入购物车 + + + + 已售罄 @@ -576,32 +568,39 @@ export default { }, // 购物车更改 - changeCar(newValue) { - // // 修改当前商品在购物车中的数量 - // this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value - // // 修改购物车列表中的数量 - // this.carOrderList.forEach(item => { - // if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) { - // item.count = newValue.value - // } - // }) - // // 计算购物车数量 - // let carNum = 0 - // this.carOrderList.forEach(item => { - // carNum += item.count - // }) - // this.carNum = carNum - //商品数量变化 + changeCar() { + // 直接增加商品数量,与addCar逻辑类似 + const currentGoods = this.info.commodity_goods_info_list[this.currentGGIndex]; + const currentQuantity = currentGoods.cart_count ? currentGoods.cart_count.count : 0; + const stockQuantity = currentGoods.stock_quantity || 0; + + // 检查库存是否充足 + if (currentQuantity >= stockQuantity) { + uni.showToast({ + title: "库存不足", + icon: "none", + duration: 2000 + }); + return; + } + + // 增加商品数量 + currentGoods.cart_count = { + count: currentQuantity + 1, + }; + const params = { user_id: uni.getStorageSync("userId"), goods_id_and_count: [{ - goods_id: this.info.commodity_goods_info_list[this.currentGGIndex].id, - count: newValue.value, - },], + goods_id: currentGoods.id, + count: currentGoods.cart_count.count, + }], }; + request(apiArr.updateCar, "POST", params).then((res) => { console.log(res); this.getShopCarList(); + this.getShopCar(); uni.showToast({ title: "操作成功!", success() { },