diff --git a/api/shop.js b/api/shop.js index 19c30a4f..6e786f30 100644 --- a/api/shop.js +++ b/api/shop.js @@ -21,4 +21,7 @@ export const apiArr = { goodsSearch: '/api/v2/wechat/commodity/search', // 商品搜索 cancelPay: '/api/v2/wechat/commodity/order/cancel_pay', // 用户取消支付 + + + adverGoodsList: '/api/v2/wechat/commodity/adver-goods-list', // 广告货品列表 } \ No newline at end of file diff --git a/packages/advertising/index/index.vue b/packages/advertising/index/index.vue index fd5f4a24..69b28f83 100644 --- a/packages/advertising/index/index.vue +++ b/packages/advertising/index/index.vue @@ -4,88 +4,27 @@ - - - - - - - {{ item.commodity_name }} - {{ item.commodity_intro }} - {{ getPriceRange(item.group_buy_goods_list) }} - - - - {{ item.showSkuList ? '收起' : '选择规格' }} - - - - - - - - - - - - - - {{ sku.goods_name }} - {{ sku.goods_spec }} - - - - - 团购价 - ¥{{ sku.group_buy_price }}/{{ sku.goods_unit }} - - - - - - - {{ sku.quantity }} - + - - - - - 单买价 ¥{{ sku.sales_price }}/{{ sku.goods_unit }} - - {{ - getEndTheCountdown(sku.group_buy_activity_info.end_time) - }} - - - - - - - - + - {{ item.commodity_name }} - {{ item.commodity_intro }} + {{ item.goods_name }} + {{ item.goods_spec }} - 团购价 - ¥{{ item.group_buy_goods_list[0].group_buy_price }}/{{ - item.group_buy_goods_list[0].goods_unit }} + 活动价 + ¥{{ item.promotional_price }}/{{ item.goods_unit }} + - - - {{ item.group_buy_goods_list[0].quantity }} - + + - + {{ item.quantity }} + + - 单买价 ¥{{ item.group_buy_goods_list[0].sales_price }}/{{ - item.group_buy_goods_list[0].goods_unit }} - - {{ getEndTheCountdown(item.group_buy_goods_list[0].group_buy_activity_info.end_time) }} - + 零售价 ¥{{ item.retail_price }}/{{ item.goods_unit }} @@ -155,18 +94,12 @@ export default { adver_id: this.idVal, } return request(shopApi.adverGoodsList, 'POST', params).then(res => { - const list = res.data.adver_goods_list.map(item => { - // 为每个货品初始化quantity - const group_buy_goods_list = item.group_buy_goods_list.map(sku => ({ - ...sku, - commodity_pic: picUrl + sku.commodity_pic, - quantity: 0 - })); + const list = res.adver_goods_list.map(item => { + // 为每个商品初始化quantity return { ...item, - commodity_pic: picUrl + item.commodity_pic, - showSkuList: false, - group_buy_goods_list + commodity_pic: picUrl + item.goods_pic, + quantity: 0 } }) this.goodsList = list @@ -175,7 +108,7 @@ export default { }, getShopdetail() { const params = { - is_group_buy: 1, + is_adver: 1, } return request(shopApi.getCar, "POST", params).then((res) => { this.carNum = res.total; @@ -189,95 +122,82 @@ export default { if (!this.goodsDetail || !this.goodsList || this.goodsList.length === 0) { return; } - // 遍历所有商品 + // 遍历所有商品,直接对item进行处理 this.goodsList.forEach(goods => { - // 遍历商品的所有货品 - goods.group_buy_goods_list.forEach(sku => { - // 在购物车数据中查找对应的货品 - const matchedItem = this.goodsDetail.find(item => item.goods_id === sku.goods_id); + // 在购物车数据中查找对应的商品 + const matchedItem = this.goodsDetail.find(item => item.goods_id === goods.goods_id); - // 如果找到匹配项,更新quantity - if (matchedItem) { - sku.quantity = matchedItem.count; - } else { - // 如果没有找到,设置为0 - sku.quantity = 0; - } - }); + // 如果找到匹配项,更新quantity + if (matchedItem) { + goods.quantity = matchedItem.count; + } else { + // 如果没有找到,设置为0 + goods.quantity = 0; + } }); }, toDetail(itemObj) { - const item = { - ...itemObj, - groupById: itemObj.group_buy_activity_info.id - }; - NavgateTo(`/packages/shop/groupPurchaseDetail/index?item=${JSON.stringify(item)}`) + // const item = { + // ...itemObj, + // groupById: itemObj.group_buy_activity_info ? itemObj.group_buy_activity_info.id : '' + // }; + // NavgateTo(`/packages/shop/groupPurchaseDetail/index?item=${JSON.stringify(item)}`) }, - // 获取商品价格范围 - getPriceRange(goodsList) { - if (!goodsList || goodsList.length === 0) return '¥0'; - const prices = goodsList.map(item => Number(item.sales_price)); - const minPrice = Math.min(...prices); - const maxPrice = Math.max(...prices); - return minPrice === maxPrice ? `¥${minPrice}` : `¥${minPrice} ~ ¥${maxPrice}`; - }, - // 展开/收起货品列表 - toggleSkuList(index) { - this.goodsList[index].showSkuList = !this.goodsList[index].showSkuList; - }, - // 增加货品数量 - increaseQuantity(goodsIndex, skuIndex) { - 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 + // 增加商品数量 + increaseQuantity(index) { + const item = this.goodsList[index] + if (item.quantity == 0) { + item.quantity += item.min_order_quantity || 1 + this.carNum += item.min_order_quantity || 1 } else { - if (this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity == this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].total_stock) { + if (item.quantity == item.total_stock) { uni.showToast({ title: '库存不足', icon: 'none' }); return } - if (this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity == this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].max_limit_quantity) { + if (item.quantity == item.max_limit_quantity) { uni.showToast({ - title: '一次最多购买' + this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].max_limit_quantity + '件', + title: '一次最多购买' + item.max_limit_quantity + '件', icon: 'none' }); return } - this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity++; + item.quantity++; this.carNum++; } const params = { goods_id_and_count: [ { - goods_id: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].id, - count: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity, + goods_id: item.goods_id, + count: item.quantity, }, ], - group_buy_id: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].group_buy_activity_info.id + adver_id: item.adver_id } this.updateCar(params); }, - // 减少货品数量 - decreaseQuantity(goodsIndex, skuIndex) { - if (this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity > 0) { - 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 + // 减少商品数量 + decreaseQuantity(index) { + const item = this.goodsList[index] + if (item.quantity > 0) { + if (item.quantity == (item.min_order_quantity || 1)) { + item.quantity = 0 this.carNum = 0 } else { - this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity--; + item.quantity--; this.carNum--; } const params = { goods_id_and_count: [ { - goods_id: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].id, - count: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].quantity, + goods_id: item.goods_id, + count: item.quantity, }, ], - group_buy_id: this.goodsList[goodsIndex].group_buy_goods_list[skuIndex].group_buy_activity_info.id + adver_id: item.adver_id } this.updateCar(params); } else { @@ -300,9 +220,9 @@ export default { // 跳转到购物车 shopCar() { const item = { - is_group_buy: 1, + is_adver: 1, } - NavgateTo("../shopCar/index?item=" + JSON.stringify(item)); + NavgateTo("/packages/shop/shopCar/index?item=" + JSON.stringify(item)); }, // 计算距离结束日期的剩余时间 getEndTheCountdown(endTime) { diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index 78f0b4bd..13bd96e3 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -338,7 +338,6 @@ export default { }, onLoad(options) { this.carList = JSON.parse(options.shopCarList) - console.log("🚀 ~ onLoad ~ JSON.parse(options.shopCarList):", JSON.parse(options.shopCarList)) }, onShow() { this.getUserAddress() @@ -425,7 +424,6 @@ export default { } }, increaseQuantity(item) { - console.log("🚀 ~ increaseQuantity ~ item:", 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(); @@ -600,7 +598,8 @@ export default { // 原始逻辑:创建订单后再进行支付 const params = { user_id: uni.getStorageSync('userId'), - is_group_buy: isGroupBuyValid, + // 先判断shopCarList数据中是否包含isAdver且为true + is_group_buy: this.carList.some(item => item.isAdver === true) ? 3 : (isGroupBuyValid ? 2 : 1), goods_list: Object.keys(this.supplierGroups).map(supplierId => { const group = this.supplierGroups[supplierId]; const firstItem = group[0]; @@ -662,8 +661,9 @@ export default { success: (payRes) => { const params = { order_id: orderId, - from: 2, + from: this.carList.some(item => item.isAdver === true) ? 3 : (isGroupBuyValid ? 2 : 1), group_buy_activity_id: this.group_buy_activity_id, + adver_id: this.carList.some(item => item.isAdver === true) ? this.carList.find(item => item.isAdver === true).adver_id : '' } request(apiArr.queryOrder, "POST", params).then(res => { this.verifyCode = res.verification_code diff --git a/packages/shop/shopCar/index.vue b/packages/shop/shopCar/index.vue index 9e6ca891..de7f9271 100644 --- a/packages/shop/shopCar/index.vue +++ b/packages/shop/shopCar/index.vue @@ -297,8 +297,13 @@ export default { this.$u.toast("请选择商品"); return; } + // 给每个商品添加isAdver=true参数 + const updatedArr = arr.map(item => ({ + ...item, + isAdver: item.adver_id ? true : '' + })); // NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`); - NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(arr)}`); + NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(updatedArr)}`); }, // 获取购物车列表 diff --git a/pages/index/index.vue b/pages/index/index.vue index 228a1ff0..9c3c9abd 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -93,7 +93,7 @@ - + @@ -308,6 +308,7 @@ export default { // 中部1左侧广告 serverLeft: '', + serverLeftList: [], // 中部1右侧广告 serverRightList: [], @@ -351,8 +352,9 @@ export default { }, // 广告商品跳转 - toAdvertisingView(item) { - NavgateTo('/packages/advertising/index/index') + toAdvertisingView(itemArry) { + const item = itemArry[0] + NavgateTo('/packages/advertising/index/index?id=' + item.id) }, async goToWuye() { @@ -679,6 +681,7 @@ export default { }, { silent: false }); if (res.rows.length) { + this.serverLeftList = res.rows let filterRes = this.filterShowList(res?.rows, 1); filterRes.forEach(item => { item.pic_src = picUrl + item.pic_src