diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index 01760201..04d2e96d 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -97,30 +97,41 @@ 暂无商品数据 - - - - 自提点 - - - - - - - {{ adItem.name }} - {{ adItem.phone }} + + + + + + 自提点 + + + + + + + {{ adItem.name }} + {{ adItem.phone }} + + + {{ adItem.address }} + + - - {{ adItem.address }} - + - - + + + + + 请选择自提点 + + + - + 请选择自提点 @@ -129,18 +140,11 @@ - - - - 请选择自提点 - - - - - + + @@ -313,6 +317,20 @@ export default { group_buy_activity_id: 0, }; }, + computed: { + // 按供应商id分组商品 + supplierGroups() { + const groups = {}; + this.orderList2.forEach(item => { + const supplierId = item.commodity_goods_info.group_buy_activity_info?.supplier_id || 'default'; + if (!groups[supplierId]) { + groups[supplierId] = []; + } + groups[supplierId].push(item); + }); + return groups; + }, + }, onLoad(options) { this.carList = JSON.parse(options.shopCarList) }, @@ -482,11 +500,15 @@ export default { this.selectedPayment = payment; }, submitPayment() { - // 检查所有商品是否都选择了自提点 - const allHaveZTAddress = this.orderList2.every(item => { - const ztAddress = this.defZTAddress.find(adItem => adItem.id === item.goods_id); - return ztAddress && ztAddress.id; - }); + // 检查所有供应商是否都选择了自提点 + const supplierIds = [...new Set(this.orderList2.map(item => + item.commodity_goods_info.group_buy_activity_info?.supplier_id || 'default' + ))]; + + const allHaveZTAddress = supplierIds.every(supplierId => { + const ztAddress = this.defZTAddress.find(adItem => adItem.id == supplierId); + return !!ztAddress; + }); if (!allHaveZTAddress) { uni.showToast({ @@ -499,28 +521,38 @@ export default { const params = { user_id: uni.getStorageSync('userId'), is_group_buy: true, - goods_list: this.orderList2.map(item => { + goods_list: Object.keys(this.supplierGroups).map(supplierId => { + const group = this.supplierGroups[supplierId]; + const firstItem = group[0]; + // 团购活动id - this.group_buy_activity_id = item.commodity_goods_info.group_buy_activity_id - const ztAddress = this.defZTAddress.find(adItem => adItem.id === item.goods_id) || {}; + this.group_buy_activity_id = firstItem.commodity_goods_info.group_buy_activity_id; + + // 根据供应商id获取自提点信息 + const ztAddress = this.defZTAddress.find(adItem => adItem.id == supplierId) || {}; + // 团购活动时间判断 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 isGroupBuy = currentTime >= startTime && currentTime <= endTime; + return { - supplier_id: item.commodity_goods_info.group_buy_activity_info.supplier_id, - supplier_name: item.supplier_name || '', - is_same_day: item.commodity_goods_info.is_same_day, + supplier_id: firstItem.commodity_goods_info.group_buy_activity_info.supplier_id, + supplier_name: firstItem.supplier_name || '', + is_same_day: firstItem.commodity_goods_info.is_same_day, receiving_name: ztAddress.name || '', receiving_phone: ztAddress.phone || '', receiving_address: ztAddress.address || '', - group_buy_activity_id: item.commodity_goods_info.group_buy_activity_id, - goods_and_count: [{ - goods_id: item.commodity_goods_info.goods_id, - count: item.count, - price: isGroupBuy ? item.commodity_goods_info.group_buy_price : item.commodity_goods_info.sales_price - }] + group_buy_activity_id: firstItem.commodity_goods_info.group_buy_activity_id, + goods_and_count: group.map(item => { + 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 isGroupBuy = currentTime >= startTime && currentTime <= endTime; + return { + goods_id: item.commodity_goods_info.goods_id, + count: item.count, + price: isGroupBuy ? item.commodity_goods_info.group_buy_price : item.commodity_goods_info.sales_price, + freight: item.commodity_goods_info.freight, + } + }) } }) } diff --git a/packages/shop/ztLocation/index.vue b/packages/shop/ztLocation/index.vue index 942712e2..740ac76a 100644 --- a/packages/shop/ztLocation/index.vue +++ b/packages/shop/ztLocation/index.vue @@ -34,10 +34,10 @@ export default { }, onLoad(options) { const item = JSON.parse(options.item) - this.getLocationList(item.goods_id) + this.getLocationList(item.goods_id, item.supplier_id) }, methods: { - async getLocationList(id) { + async getLocationList(id, supplier_id) { const params = { goods_ids: id, } @@ -46,7 +46,7 @@ export default { res.self_pickup_address_list[0].address.forEach(item => { const [address, phone, name] = item.split(' '); this.locationList.push({ - id: id, + id: supplier_id, name: name || '', phone: phone || '', address: address || '' @@ -56,13 +56,13 @@ export default { selectLocation(item, index) { // 更新选中项的索引 this.selectedIndex = index; - + // 从本地存储获取已有的地址数据 let addressList = uni.getStorageSync('changeZTAddress') || []; - + // 检查id是否已存在 const existingIndex = addressList.findIndex(addr => addr.id === item.id); - + if (existingIndex > -1) { // 如果id存在,则覆盖原来的数据 addressList[existingIndex] = item; @@ -70,10 +70,10 @@ export default { // 如果id不存在,则新增 addressList.push(item); } - + // 存储更新后的地址列表 uni.setStorageSync('changeZTAddress', addressList); - + NavgateTo("1") } }