From 3fb80ce105f577fd1ee3afacdabcd4038d970207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Tue, 2 Sep 2025 15:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=93=E8=B4=AD=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=9B=A0=E4=B8=BA=E6=B2=A1=E6=9C=89=E5=9B=A2=E8=B4=AD?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BF=A1=E6=81=AF=E5=AF=BC=E8=87=B4=E5=9B=A0?= =?UTF-8?q?=E4=B8=BAstart=5Ftime=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shop/groupPurchaseSubmit/index.vue | 20 ++++----- packages/shop/index/index.vue | 46 +++++++++++++++++++-- packages/shop/shopCar/index.vue | 20 ++++----- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index b3f80ba7..a28196a2 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -370,8 +370,8 @@ export default { }, decreaseQuantity(item) { const currentTime = new Date().getTime(); - const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (item.count > 0) { if (currentTime >= startTime && currentTime <= endTime) { if (item.count == item.commodity_goods_info.min_order_quantity) { @@ -402,8 +402,8 @@ export default { }, increaseQuantity(item) { const currentTime = new Date().getTime(); - const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { if (item.count == 0) { item.count += item.commodity_goods_info.min_order_quantity @@ -452,8 +452,8 @@ export default { let total = 0; this.orderList1.forEach(goods => { // 团购活动时间判断 - const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight; } else { @@ -466,8 +466,8 @@ export default { let total = 0; this.orderList2.forEach(goods => { // 团购活动时间判断 - const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight; } else { @@ -671,8 +671,8 @@ export default { return false; } const now = new Date(); - const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time); - const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time); + const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time); + const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time); return now >= startTime && now <= endTime; }, } diff --git a/packages/shop/index/index.vue b/packages/shop/index/index.vue index e24b4f6a..42f6baaa 100644 --- a/packages/shop/index/index.vue +++ b/packages/shop/index/index.vue @@ -468,32 +468,72 @@ export default { }, //商品数量变化 handleQuantityChange(val, item) { + // 先在前端直接更新数量,确保页面显示及时变化 + // 注意:这里的val可能是直接的数值,也可能是包含value属性的对象 + // 我们需要先确定正确的值 + const quantity = typeof val === 'object' && val !== null && 'value' in val ? val.value : val; + + // 对于有规格的主商品(绑定到items.commodity_goods_info_list[0].quantity) if ( item.commodity_goods_info_list && item.commodity_goods_info_list.length ) { this.goodsId = item.commodity_goods_info_list[0].id; - } else { - this.goodsId = item.id; + // 使用$set确保响应式更新 + this.$set(item.commodity_goods_info_list[0], 'quantity', quantity); } + // 对于规格列表中的商品(绑定到ite.quantity) + else { + this.goodsId = item.id; + // 使用$set确保响应式更新 + this.$set(item, 'quantity', quantity); + } + const params = { user_id: uni.getStorageSync("userId"), goods_id_and_count: [ { goods_id: this.goodsId, - count: val.value, + count: quantity, }, ], }; + + // 发送请求更新后端数据 request(apiArr.updateCar, "POST", params).then((res) => { console.log(res); + // 先更新购物车数据 this.getShopCarList(); + + // 延迟一小段时间,确保goodsDetail已经更新 + setTimeout(() => { + // 重新同步商品列表中的数量 + this.syncGoodsQuantities(); + }, 100); + uni.showToast({ title: "操作成功!", success() { }, }); }); }, + + // 同步商品列表中的数量 + syncGoodsQuantities() { + // 遍历所有商品,同步数量 + this.tagList.forEach((tagItem) => { + if (tagItem.commodity_info_list) { + tagItem.commodity_info_list.forEach((infoItem) => { + infoItem.commodity_goods_info_list.forEach((param) => { + const goods = this.goodsDetail.find(g => g.goods_id === param.id); + if (goods) { + this.$set(param, 'quantity', goods.count); + } + }); + }); + } + }); + }, getPriceRange(goodsList) { if (!goodsList || goodsList.length === 0) return '¥0'; const prices = goodsList.map(item => Number(item.sales_price)); diff --git a/packages/shop/shopCar/index.vue b/packages/shop/shopCar/index.vue index f4a55c1f..b8313f99 100644 --- a/packages/shop/shopCar/index.vue +++ b/packages/shop/shopCar/index.vue @@ -466,8 +466,8 @@ export default { carItem.commodity_cart_and_goods_model.forEach(goods => { if (goods.checked) { // 团购活动时间判断 - const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { total += goods.commodity_goods_info.group_buy_price * goods.count; } else { @@ -482,8 +482,8 @@ export default { carItem.commodity_cart_and_goods_model.forEach(goods => { if (goods.checked) { // 团购活动时间判断 - const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { total += goods.commodity_goods_info.group_buy_price * goods.count; } else { @@ -549,8 +549,8 @@ export default { // 检查商品是否有团购活动且在活动时间内 const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info && - currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info.start_time).getTime() && - currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info?.start_time).getTime() && + currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (carItem.count > 0) { if (isGroupBuyActive && carItem.count === carItem.commodity_goods_info.min_order_quantity) { @@ -585,8 +585,8 @@ export default { const currentTime = new Date().getTime(); const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info && - currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info.start_time).getTime() && - currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info?.start_time).getTime() && + currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (isGroupBuyActive) { if (carItem.count == 0) { carItem.count = carItem.commodity_goods_info.min_order_quantity @@ -699,8 +699,8 @@ export default { //获取价格 - 该显示团购价还是正常价 getPrice(item) { const currentTime = new Date().getTime(); - const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime(); - const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime(); + const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); + const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); if (currentTime >= startTime && currentTime <= endTime) { return item.commodity_goods_info.group_buy_price; } else {