From 34be99fccb9a66a63b7af6a1cb3883ca7ee1624b Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 19 Dec 2024 15:45:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E7=BC=BA=E9=99=B7=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E3=80=91=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=85=8D=E9=80=81=E6=96=B9=E5=BC=8F=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/cart.vue | 82 ++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/pages/index/cart.vue b/pages/index/cart.vue index c257ede2..e6b58bea 100644 --- a/pages/index/cart.vue +++ b/pages/index/cart.vue @@ -109,7 +109,6 @@ import { computed, reactive } from 'vue'; import { fen2yuan } from '@/sheep/hooks/useGoods'; import { isEmpty } from '@/sheep/helper/utils'; - import { DeliveryTypeEnum } from '@/sheep/util/const'; const sys_navBar = sheep.$platform.navbar; const cart = sheep.$store('cart'); @@ -158,37 +157,60 @@ }); } - /** 校验配送方式 */ - function validateDeliveryType(spuIds) { - return new Promise(async (resolve, reject) => { - const { data } = await SpuApi.getSpuListByIds(spuIds.join(',')); - if (isEmpty(data)) { - reject('获取商品信息失败!!!'); - return; - } - let onlyExpress = false; // 只快递 - let onlyPickup = false; // 只自提 - // TODO @puhui999:这里需要比对,A 商品支持自提、B 商品支持快递,这样导致 A 和 B 无法一起下单。 - const deliveryTypes = data.map((item) => item.deliveryTypes); - for (const deliveryType of deliveryTypes) { - // 情况一:两种配送方式都支持 - if (deliveryType.length > 1) { - continue; - } - // 情况二:只支持一种 - if (deliveryType[0] === DeliveryTypeEnum.EXPRESS.type) { - onlyExpress = true; - } else if (deliveryType[0] === DeliveryTypeEnum.PICK_UP.type) { - onlyPickup = true; + /** + * 校验配送方式冲突 + * + * @param {string[]} spuIds - 商品ID数组 + * @returns {Promise} + * @throws {Error} 当配送方式冲突或获取商品信息失败时抛出错误 + */ + async function validateDeliveryType(spuIds) { + // 获取商品信息 + const { data: spuList } = await SpuApi.getSpuListByIds(spuIds.join(',')); + if (isEmpty(spuList)) { + sheep.$helper.toast('未找到商品信息'); + throw new Error('未找到商品信息'); + } + // 获取所有商品的配送方式列表 + const deliveryTypesList = spuList.map(item => item.deliveryTypes); + // 检查配送方式冲突 + const hasConflict = checkDeliveryConflicts(deliveryTypesList); + if (hasConflict) { + sheep.$helper.toast('选中商品支持的配送方式冲突,不允许提交'); + throw new Error('选中商品支持的配送方式冲突,不允许提交'); + } + } + + /** + * 检查配送方式列表中是否存在冲突 + * @description + * 示例场景: + * A 商品支持:[快递, 自提] + * B 商品支持:[快递] + * C 商品支持:[自提] + * + * 对比结果: + * A 和 B:不冲突 (有交集:快递) + * A 和 C:不冲突 (有交集:自提) + * B 和 C:冲突 (无交集) + * @param {Array>} deliveryTypesList - 配送方式列表的数组 + * @returns {boolean} 是否存在冲突 + */ + function checkDeliveryConflicts(deliveryTypesList) { + for (let i = 0; i < deliveryTypesList.length - 1; i++) { + const currentTypes = deliveryTypesList[i]; + for (let j = i + 1; j < deliveryTypesList.length; j++) { + const nextTypes = deliveryTypesList[j]; + // 检查是否没有交集(即冲突) + const hasNoIntersection = !currentTypes.some(type => + nextTypes.includes(type), + ); + if (hasNoIntersection) { + return true; } } - if (onlyExpress || onlyPickup) { - reject('选中商品存在只支持特定配送方式的情况不允许提交!!!'); - sheep.$helper.toast('选中商品存在只支持特定配送方式的情况不允许提交!!!'); - return; - } - resolve(); - }); + } + return false; } function onNumberChange(e, cartItem) { From 52cfca1ca17f35b320edd7c3c66ccbe7828e7fab Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 19 Dec 2024 16:23:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E7=BC=BA=E9=99=B7=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E3=80=91s-layout=20bgStyle=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/activity/groupon/list.vue | 2 +- pages/activity/seckill/list.vue | 2 +- pages/coupon/list.vue | 2 +- pages/index/cart.vue | 2 +- pages/index/category.vue | 2 +- pages/index/search.vue | 2 +- pages/pay/result.vue | 2 +- pages/public/faq.vue | 2 +- pages/public/richtext.vue | 2 +- pages/public/setting.vue | 2 +- pages/user/address/list.vue | 2 +- pages/user/goods-log.vue | 2 +- pages/user/goods_details_store/index.vue | 2 +- sheep/components/s-layout/s-layout.vue | 7 +++---- 14 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pages/activity/groupon/list.vue b/pages/activity/groupon/list.vue index 0e741876..0cd8bc97 100644 --- a/pages/activity/groupon/list.vue +++ b/pages/activity/groupon/list.vue @@ -1,6 +1,6 @@