diff --git a/src/pages/goods_detail/goods_detail.vue b/src/pages/goods_detail/goods_detail.vue index ffd5688..3333cb8 100644 --- a/src/pages/goods_detail/goods_detail.vue +++ b/src/pages/goods_detail/goods_detail.vue @@ -125,7 +125,28 @@ export default { // 添加到购物车 addToCartHandle(){ - console.log('加入购物车') + const cartList = uni.getStorageSync("cartList") || []; + const index = cartList.findIndex((item) => item.goods_id === this.goods_id) + if (index === -1) { + const goodsObj = { + goods_id: this.goods_id, + goods_small_logo: this.goods_small_logo, + goods_price: this.goods_price, + goods_name: this.goods_name, + goods_select: true, // 选中状态 + goods_count: 1, // 商品数量 + } + cartList.push(goodsObj) + }else{ + cartList[index].goods_count += 1 + } + uni.setStorageSync("cartList", cartList) + uni.showToast({ + title: "加入成功", + // 是否显示透明蒙层,防止触摸穿透 + mask: true, + duration: 1000, + }) } },