购物车逻辑完善
个人信息存储优化 团购下单
This commit is contained in:
@@ -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 = [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user