购物车添加商品
This commit is contained in:
parent
ea34fe93f5
commit
c6b6e21ca0
@ -125,7 +125,28 @@ export default {
|
|||||||
|
|
||||||
// 添加到购物车
|
// 添加到购物车
|
||||||
addToCartHandle(){
|
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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user