// 通过pinia添加到购物车商品
//shops 代表每个商品
const addCart = (shops) => {
if (cartStores.shop.includes(shops)) {
cartStores.addItemToArray(shops);
} else {
const index = cartStores.shop.findIndex((item) => item.id === shops.id)
if (index !== -1 ) {
// 购物车中已有该商品,只增加数量 这里有bug
// 如果添加的数量是1
if(shops.num ==1){
cartStores.shop[index].num++;
}else{
cartStores.shop[index].num += shops.num++
}
} else {
// 购物车中没有该商品,添加到购物车
// cartStores.shop.push({ ...shops});
cartStores.addShop(shops);
}
}