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 @@
-