购物车逻辑完善

个人信息存储优化
团购下单
This commit is contained in:
2024-03-31 03:19:19 +08:00
parent 074b0057da
commit 1fc0aa432b
17 changed files with 316 additions and 166 deletions

View File

@@ -1,4 +1,5 @@
import { defineStore } from 'pinia';
import { StockBean } from '@/api/goods/types';
const useShoppingCartStore = defineStore('shoppingCart', {
state: (): { shoppingCartList: any[] } => ({
@@ -27,14 +28,35 @@ const useShoppingCartStore = defineStore('shoppingCart', {
getTotalCount(): number {
return this.shoppingCartList.length;
},
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
return state.shoppingCartList.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId);
}
},
actions: {
save(partial: Partial<any>) {
this.shoppingCartList.push(partial);
},
clear() {
updateCount(index: number, count: number) {
this.shoppingCartList[index].checkedStock.count += count;
},
updateStock(index: number, stock: StockBean) {
this.shoppingCartList[index].checkedStock = stock;
},
delete(index: number) {
this.shoppingCartList.splice(index, 1);
},
deleteIfChecked() {
this.shoppingCartList = this.shoppingCartList.filter(res => res.checked == undefined || res.checked === false);
},
clearAll() {
this.shoppingCartList = [];
}
}