From 3ecdf95c2407cb5f73d81d78eb70c6b242b6e170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Tue, 26 Aug 2025 18:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=A2=E8=B4=AD=E9=83=A8?= =?UTF-8?q?=E5=88=86bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shop/groupPurchase/index.vue | 20 ++- packages/shop/groupPurchaseDetail/index.vue | 142 ++++++++++++-------- packages/shop/groupPurchaseSubmit/index.vue | 38 +++++- packages/shop/shopCar/index.vue | 100 ++++++++------ packages/shop/ztLocation/index.vue | 5 +- 5 files changed, 195 insertions(+), 110 deletions(-) diff --git a/packages/shop/groupPurchase/index.vue b/packages/shop/groupPurchase/index.vue index f1e24f63..2527f10b 100644 --- a/packages/shop/groupPurchase/index.vue +++ b/packages/shop/groupPurchase/index.vue @@ -165,7 +165,6 @@ export default { group_buy_goods_list } }) - console.log("🚀 ~ getGoodsList ~ list:", list) this.goodsList = list return res; }) @@ -217,8 +216,14 @@ export default { }, // 增加货品数量 increaseQuantity(goodsIndex, skuIndex) { - this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity++; - this.carNum++; + if (this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity == 0) { + this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity += this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].min_order_quantity + this.carNum += this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].min_order_quantity + + } else { + this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity++; + this.carNum++; + } const params = { goods_id_and_count: [ { @@ -233,8 +238,13 @@ export default { // 减少货品数量 decreaseQuantity(goodsIndex, skuIndex) { if (this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity > 0) { - this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity--; - this.carNum--; + if(this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity == this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].min_order_quantity){ + this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity = 0 + this.carNum = 0 + }else{ + this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity--; + this.carNum--; + } const params = { goods_id_and_count: [ diff --git a/packages/shop/groupPurchaseDetail/index.vue b/packages/shop/groupPurchaseDetail/index.vue index 1fe6fa80..b3ac1fb0 100644 --- a/packages/shop/groupPurchaseDetail/index.vue +++ b/packages/shop/groupPurchaseDetail/index.vue @@ -82,7 +82,7 @@ - 共{{ info.commodity_goods_info_list.length }}款 + 共{{ info.commodity_goods_info_list.length }}款 @@ -185,24 +185,11 @@ 加入购物车 - - - - - - - {{ - info.commodity_goods_info_list[currentGGIndex].cart_count.count - }} - - - - + 加入购物车 @@ -337,6 +324,8 @@ import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils"; export default { data() { return { + itemObj: {}, + picUrl, top: "", localHeight: "", @@ -506,9 +495,9 @@ export default { }).then((res) => { // 分割图片 res.commodity_goods_info_list.forEach((item) => { - item.goods_detail_pic = item.goods_detail_pic.split(","); - item.goods_carousel = item.goods_carousel.split(","); - item.commodity_pic = item.commodity_pic.split(","); + item.goods_detail_pic = item.goods_detail_pic ? item.goods_detail_pic.split(",") : []; + item.goods_carousel = item.goods_carousel ? item.goods_carousel.split(",") : []; + item.commodity_pic = item.commodity_pic ? item.commodity_pic.split(",") : []; }); //根据购物车列表 和 当前商品列表 来更新当前商品列表在购物车中的数量 @@ -522,13 +511,45 @@ export default { }); }); } - this.info = res; - this.currentGG = res.commodity_goods_info_list[0]; - this.currentGGIndex = 0; - this.changeImg = this.currentGG.commodity_pic[0] - this.changeName = this.currentGG.goods_alias - this.changePrice = this.currentGG.sales_price + // 过滤掉group_buy_activity_info为空的数据 + if (res.commodity_goods_info_list && Array.isArray(res.commodity_goods_info_list)) { + res.commodity_goods_info_list = res.commodity_goods_info_list.filter(item => { + return item.group_buy_activity_info !== null + }); + } + + this.info = res; + + // 确保商品列表不为空 + if (this.itemObj) { + // 对 itemObj 进行图片分割处理 + this.itemObj.goods_detail_pic = this.itemObj.goods_detail_pic ? this.itemObj.goods_detail_pic.split(",") : []; + this.itemObj.goods_carousel = this.itemObj.goods_carousel ? this.itemObj.goods_carousel.split(",") : []; + this.itemObj.commodity_pic = this.itemObj.commodity_pic ? this.itemObj.commodity_pic.split(",") : []; + + this.currentGG = this.itemObj; + // 根据itemObj在商品列表中找到对应的索引 + this.currentGGIndex = this.info && this.info.commodity_goods_info_list + ? this.info.commodity_goods_info_list.findIndex(item => item.id === this.itemObj.id) + : 0; + + // 如果没找到匹配项,默认为0 + if (this.currentGGIndex === -1) { + this.currentGGIndex = 0; + } + + this.changeImg = this.currentGG.commodity_pic[0]; + this.changeName = this.currentGG.goods_alias; + this.changePrice = this.currentGG.sales_price; + } else { + // 商品列表为空时的处理 + this.currentGG = null; + this.currentGGIndex = 0; + this.changeImg = ''; + this.changeName = ''; + this.changePrice = ''; + } }); }, @@ -581,50 +602,59 @@ export default { addCar() { let that = this; - //如果没有当前商品 直接添加一个 - let goods_id_and_count = []; this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { - count: 1, + count: this.info.commodity_goods_info_list[this.currentGGIndex].min_order_quantity, }; - this.info.commodity_goods_info_list.forEach((item) => { - console.log(item.cart_count); - goods_id_and_count.push({ - goods_id: item.id, - count: item.cart_count ? item.cart_count.count : 0, - }); - }); + // this.info.commodity_goods_info_list.forEach((item) => { + // console.log(item.cart_count); + // goods_id_and_count.push({ + // goods_id: item.id, + // count: item.cart_count ? item.cart_count.count : 0, + // }); + // }); - console.log(goods_id_and_count); - //因为是当前商品没有 调用update就是增加商品。增加商品之后再获取购物车数量 - request(apiArr.updateCar, "POST", { - goods_id_and_count, - }).then((res) => { + let countVal = this.info.commodity_goods_info_list[this.currentGGIndex].min_order_quantity + + const params = { + goods_id_and_count: [ + { + goods_id: + this.info.commodity_goods_info_list[this.currentGGIndex].id, + count: countVal, + }, + ], + } + request(apiArr.updateCar, "POST", params).then((res) => { that.getShopCar(); that.getShopCarList(); }); }, // 购物车更改 - changeCar(newValue) { - //商品数量变化 + changeCar() { + // 获取当前商品的购物车数量,如果不存在则设为0 + const currentCount = this.info.commodity_goods_info_list[this.currentGGIndex].cart_count?.count; + // 新的数量为当前数量加一 + const newCount = currentCount + 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: this.info.commodity_goods_info_list[this.currentGGIndex].id, + count: newCount, }, ], }; + request(apiArr.updateCar, "POST", params).then((res) => { - console.log(res); this.getShopCarList(); uni.showToast({ title: "操作成功!", success() { }, }); this.getShopCar(); + this.getGoodsInfo(); }); }, @@ -694,15 +724,15 @@ export default { } }, onLoad(options) { - const itemObj = JSON.parse(decodeURIComponent(options.item)); + this.itemObj = JSON.parse(decodeURIComponent(options.item)); const meun = menuButtonInfo(); this.top = meun.top; this.localHeight = meun.height; - this.id = itemObj.commodity_id ? itemObj.commodity_id : itemObj.id; - if (itemObj.commodity_id) { - this.endTime = itemObj.group_buy_activity_info.end_time + this.id = this.itemObj.commodity_id ? this.itemObj.commodity_id : this.itemObj.id; + if (this.itemObj.commodity_id) { + this.endTime = this.itemObj.group_buy_activity_info.end_time } else { - this.endTime = itemObj.group_buy_goods_list[0].group_buy_activity_info.end_time + this.endTime = this.itemObj.group_buy_goods_list[0].group_buy_activity_info.end_time } this.getBuyRecord() this.getEndTheCountdown(this.endTime) @@ -737,11 +767,11 @@ export default { }); }); - request(apiArr.updateCar, "POST", { - goods_id_and_count, - }).then((res) => { - console.log("Cart updated on hide"); - }); + // request(apiArr.updateCar, "POST", { + // goods_id_and_count, + // }).then((res) => { + // console.log("Cart updated on hide"); + // }); return; }, }; diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index 7510e08b..24d78299 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -467,10 +467,8 @@ export default { }) } - console.log("🚀 ~ submitPayment ~ params:", params) request(apiArr.createOrder, "POST", params).then(res => { - console.log("🚀 ~ submitPayment ~ res:", res) // 根据平台设置不同的trans_type值 // 小程序: 71, App: 51 const systemInfo = uni.getSystemInfoSync(); @@ -495,9 +493,41 @@ export default { user_id: uni.getStorageSync('userId'), trans_type: trans_type } - console.log("🚀 ~ submitPayment ~ param:", param) request(apiArr.mergePreorder, "POST", param).then(res => { - console.log("🚀 ~ submitPayment ~ res:", res) + + if (res && res.timeStamp && res.nonceStr && res.package && res.signType && res.paySign) { + // 调用微信支付 + uni.requestPayment({ + timeStamp: res.timeStamp, + nonceStr: res.nonceStr, + package: res.package, + signType: res.signType, + paySign: res.paySign, + success: (payRes) => { + console.log("支付成功", payRes) + uni.showToast({ + title: '支付成功', + icon: 'success' + }) + }, + fail: (payErr) => { + console.log("支付失败", payErr) + uni.showToast({ + title: payErr.errMsg || '支付失败', + icon: 'none' + }) + }, + complete: () => { + // 支付完成后的回调,无论成功失败都会执行 + } + }) + } else { + console.error("获取支付参数失败,缺少必要参数") + uni.showToast({ + title: '获取支付信息失败', + icon: 'none' + }) + } }) }) }, diff --git a/packages/shop/shopCar/index.vue b/packages/shop/shopCar/index.vue index f11f3fd7..0ac93af3 100644 --- a/packages/shop/shopCar/index.vue +++ b/packages/shop/shopCar/index.vue @@ -31,8 +31,12 @@ - - + + + + {{ carItem.supplier_name }} @@ -64,7 +68,9 @@ - {{ item.commodity_goods_info.sales_price }} + {{ item.commodity_goods_info.group_buy_price ? + item.commodity_goods_info.group_buy_price : + item.commodity_goods_info.sales_price }} /{{ item.commodity_goods_info.goods_unit }} @@ -88,7 +94,6 @@ - @@ -104,8 +109,12 @@ - - + + + + {{ carItem.supplier_name }} @@ -124,7 +133,6 @@ - @@ -137,7 +145,9 @@ - {{ item.commodity_goods_info.sales_price }} + {{ item.commodity_goods_info.group_buy_price ? + item.commodity_goods_info.group_buy_price : + item.commodity_goods_info.sales_price }} /{{ item.commodity_goods_info.goods_unit }} @@ -234,32 +244,32 @@ export default { // } // }, methods: { - back() { - NavgateTo("1"); - }, + back() { + NavgateTo("1"); + }, - // 商家单选框全选/取消全选 - supplierCheck(carItem, isDay) { - carItem.supplierChecked = !carItem.supplierChecked; - carItem.commodity_cart_and_goods_model.forEach(goods => { - goods.checked = carItem.supplierChecked; - }); - this.calcTotal(); + // 商家单选框全选/取消全选 + supplierCheck(carItem, isDay) { + carItem.supplierChecked = !carItem.supplierChecked; + carItem.commodity_cart_and_goods_model.forEach(goods => { + goods.checked = carItem.supplierChecked; + }); + this.calcTotal(); - // 更新当日达或包邮全选状态 - if (isDay) { - this.isDaychecked = this.isDayCarList.every(item => - item.commodity_cart_and_goods_model.every(goods => goods.checked) - ); - } else { - this.isParcelPostchecked = this.shopCarList.every(item => - item.commodity_cart_and_goods_model.every(goods => goods.checked) - ); - } + // 更新当日达或包邮全选状态 + if (isDay) { + this.isDaychecked = this.isDayCarList.every(item => + item.commodity_cart_and_goods_model.every(goods => goods.checked) + ); + } else { + this.isParcelPostchecked = this.shopCarList.every(item => + item.commodity_cart_and_goods_model.every(goods => goods.checked) + ); + } - // 更新全选状态 - this.isAllchecked = this.isDaychecked && this.isParcelPostchecked; - }, + // 更新全选状态 + this.isAllchecked = this.isDaychecked && this.isParcelPostchecked; + }, // 结算 submitOrder() { @@ -294,30 +304,32 @@ export default { res.normal_cart_list.forEach((item) => { item.checked = false; item.supplierChecked = false; - this.parcelPostshow = true; }) + this.parcelPostshow = true; this.shopCarList = res.normal_cart_list } else { res.normal_cart_list.forEach((item) => { item.checked = false; item.supplierChecked = false; - this.parcelPostshow = false; }) + this.parcelPostshow = false; + this.shopCarList = [] } if (res.same_day_cart_list.length > 0) { res.same_day_cart_list.forEach((item) => { item.checked = false; item.supplierChecked = false; - this.isDayshow = true; }) + this.isDayshow = true; this.isDayCarList = res.same_day_cart_list } else { res.normal_cart_list.forEach((item) => { item.checked = false; item.supplierChecked = false; - this.isDayshow = false; }) + this.isDayshow = false; + this.isDayCarList = [] } // res.normal_cart_list.forEach((item) => { @@ -351,11 +363,11 @@ export default { }); // 检查当日达是否全选 - this.isDaychecked = this.isDayCarList.every(carItem => + this.isDaychecked = this.isDayCarList.every(carItem => carItem.commodity_cart_and_goods_model.every(goods => goods.checked) ); // 检查包邮是否全选 - this.isParcelPostchecked = this.shopCarList.every(carItem => + this.isParcelPostchecked = this.shopCarList.every(carItem => carItem.commodity_cart_and_goods_model.every(goods => goods.checked) ); // 检查全选状态 @@ -373,11 +385,11 @@ export default { }); // 检查当日达是否全选 - this.isDaychecked = this.isDayCarList.every(carItem => + this.isDaychecked = this.isDayCarList.every(carItem => carItem.commodity_cart_and_goods_model.every(goods => goods.checked) ); // 检查包邮是否全选 - this.isParcelPostchecked = this.shopCarList.every(carItem => + this.isParcelPostchecked = this.shopCarList.every(carItem => carItem.commodity_cart_and_goods_model.every(goods => goods.checked) ); // 检查全选状态 @@ -452,7 +464,10 @@ export default { this.isDayCarList.forEach(carItem => { carItem.commodity_cart_and_goods_model.forEach(goods => { if (goods.checked) { - total += goods.commodity_goods_info.sales_price * goods.count; + const price = goods.commodity_goods_info.group_buy_price !== undefined && goods.commodity_goods_info.group_buy_price !== null ? + goods.commodity_goods_info.group_buy_price : + goods.commodity_goods_info.sales_price; + total += price * goods.count; } }); }); @@ -461,7 +476,10 @@ export default { this.shopCarList.forEach(carItem => { carItem.commodity_cart_and_goods_model.forEach(goods => { if (goods.checked) { - total += goods.commodity_goods_info.sales_price * goods.count; + const price = goods.commodity_goods_info.group_buy_price !== undefined && goods.commodity_goods_info.group_buy_price !== null ? + goods.commodity_goods_info.group_buy_price : + goods.commodity_goods_info.sales_price; + total += price * goods.count; } }); }); diff --git a/packages/shop/ztLocation/index.vue b/packages/shop/ztLocation/index.vue index 39ad61f6..942712e2 100644 --- a/packages/shop/ztLocation/index.vue +++ b/packages/shop/ztLocation/index.vue @@ -34,7 +34,6 @@ export default { }, onLoad(options) { const item = JSON.parse(options.item) - console.log("🚀 ~ onLoad ~ item:", item) this.getLocationList(item.goods_id) }, methods: { @@ -45,7 +44,7 @@ export default { const res = await request(apiArr.groupBuyAddress, 'POST', params) // 遍历地址数组并正确赋值 res.self_pickup_address_list[0].address.forEach(item => { - const [name, phone, address] = item.split(' '); + const [address, phone, name] = item.split(' '); this.locationList.push({ id: id, name: name || '', @@ -57,14 +56,12 @@ export default { selectLocation(item, index) { // 更新选中项的索引 this.selectedIndex = index; - console.log("🚀 ~ selectLocation ~ 选中地址:", item) // 从本地存储获取已有的地址数据 let addressList = uni.getStorageSync('changeZTAddress') || []; // 检查id是否已存在 const existingIndex = addressList.findIndex(addr => addr.id === item.id); - console.log("🚀 ~ selectLocation ~ existingIndex:", existingIndex) if (existingIndex > -1) { // 如果id存在,则覆盖原来的数据