From 39e04ae78de69865b74cd40f92e8bddcfce687bd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 27 Apr 2025 23:48:43 +0800 Subject: [PATCH] =?UTF-8?q?sync=EF=BC=9A=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E9=92=88=E5=AF=B9=E5=B7=B2=E5=AD=98=E5=9C=A8=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=A2=AB=E4=B8=8B=E6=9E=B6=20=E6=A0=B7=E5=BC=8F=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9=20https://gitee.com/sheepjs/shopro-?= =?UTF-8?q?uniapp/commit/c752b19acdf24ca3138b1a6190c82fb8cf0f36f7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/cart.vue | 39 ++++++++++++++++++++++++++++++++------- sheep/store/cart.js | 19 ++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/pages/index/cart.vue b/pages/index/cart.vue index 2a114a8a..45a37804 100644 --- a/pages/index/cart.vue +++ b/pages/index/cart.vue @@ -15,10 +15,10 @@ 件商品 - - @@ -35,6 +35,12 @@ @tap.stop="onSelectSingle(item.id)" /> + + 该商品已下架 + + + 该商品无库存 + cart.editMode), list: computed(() => cart.list), selectedList: [], selectedIds: computed(() => cart.selectedIds), @@ -127,6 +133,11 @@ cart.selectSingle(id); } + // 编辑、取消 + function onChangeEditMode(flag) { + cart.onChangeEditMode(flag); + } + // 全选 function onSelectAll() { cart.selectAll(!state.isAllSelected); @@ -172,7 +183,7 @@ throw new Error('未找到商品信息'); } // 获取所有商品的配送方式列表 - const deliveryTypesList = spuList.map(item => item.deliveryTypes); + const deliveryTypesList = spuList.map((item) => item.deliveryTypes); // 检查配送方式冲突 const hasConflict = checkDeliveryConflicts(deliveryTypesList); if (hasConflict) { @@ -202,9 +213,7 @@ for (let j = i + 1; j < deliveryTypesList.length; j++) { const nextTypes = deliveryTypesList[j]; // 检查是否没有交集(即冲突) - const hasNoIntersection = !currentTypes.some(type => - nextTypes.includes(type), - ); + const hasNoIntersection = !currentTypes.some((type) => nextTypes.includes(type)); if (hasNoIntersection) { return true; } @@ -270,6 +279,22 @@ .goods-box { background-color: #fff; + position: relative; + } + // 下架商品 + .down-box { + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 100%; + background: rgba(#fff, 0.8); + z-index: 2; + display: flex; + justify-content: center; + align-items: center; + color: #999; + font-size: 32rpx; } } } diff --git a/sheep/store/cart.js b/sheep/store/cart.js index edde779d..ab96a2bc 100644 --- a/sheep/store/cart.js +++ b/sheep/store/cart.js @@ -4,26 +4,29 @@ import CartApi from '@/sheep/api/trade/cart'; const cart = defineStore({ id: 'cart', state: () => ({ - list: [], // 购物车列表 + list: [], // 购物车列表(invalidList + validList) selectedIds: [], // 已选列表 isAllSelected: false, // 是否全选 totalPriceSelected: 0, // 选中项总金额 + newList: [], // 除去已下架的购物车列表(validList) + editMode: false, // 是否是编辑模式 }), actions: { // 获取购物车列表 async getList() { const { data, code } = await CartApi.getCartList(); if (code === 0) { - this.list = data.validList; + this.list = [...data.validList, ...data.invalidList]; + this.newList = data.validList; // 计算各种关联属性 this.selectedIds = []; this.isAllSelected = true; this.totalPriceSelected = 0; - this.list.forEach((item) => { + (this.editMode ? this.list : this.newList).forEach((item) => { if (item.selected) { this.selectedIds.push(item.id); - this.totalPriceSelected += item.count * item.sku.price; + this.totalPriceSelected += item.count * item.sku?.price; } else { this.isAllSelected = false; } @@ -31,6 +34,12 @@ const cart = defineStore({ } }, + onChangeEditMode(flag) { + this.editMode = flag; + this.selectedIds = []; + this.getList(); + }, + // 添加购物车 async add(goodsInfo) { // 添加购物项 @@ -84,7 +93,7 @@ const cart = defineStore({ async selectAll(flag) { const { code } = await CartApi.updateCartSelected({ ids: this.list.map((item) => item.id), - selected: flag + selected: flag, }); if (code === 0) { await this.getList();