sync:购物车针对已存在商品被下架 样式 逻辑修改 https://gitee.com/sheepjs/shopro-uniapp/commit/c752b19acdf24ca3138b1a6190c82fb8cf0f36f7
This commit is contained in:
+14
-5
@@ -4,26 +4,29 @@ import CartApi from '@/sheep/api/trade/cart';
|
||||
const cart = defineStore({
|
||||
id: 'cart',
|
||||
state: () => ({
|
||||
list: [], // 购物车列表
|
||||
list: [], // 购物车列表(invalidList + validList)
|
||||
selectedIds: [], // 已选列表
|
||||
isAllSelected: false, // 是否全选
|
||||
totalPriceSelected: 0, // 选中项总金额
|
||||
newList: [], // 除去已下架的购物车列表(validList)
|
||||
editMode: false, // 是否是编辑模式
|
||||
}),
|
||||
actions: {
|
||||
// 获取购物车列表
|
||||
async getList() {
|
||||
const { data, code } = await CartApi.getCartList();
|
||||
if (code === 0) {
|
||||
this.list = data.validList;
|
||||
this.list = [...data.validList, ...data.invalidList];
|
||||
this.newList = data.validList;
|
||||
|
||||
// 计算各种关联属性
|
||||
this.selectedIds = [];
|
||||
this.isAllSelected = true;
|
||||
this.totalPriceSelected = 0;
|
||||
this.list.forEach((item) => {
|
||||
(this.editMode ? this.list : this.newList).forEach((item) => {
|
||||
if (item.selected) {
|
||||
this.selectedIds.push(item.id);
|
||||
this.totalPriceSelected += item.count * item.sku.price;
|
||||
this.totalPriceSelected += item.count * item.sku?.price;
|
||||
} else {
|
||||
this.isAllSelected = false;
|
||||
}
|
||||
@@ -31,6 +34,12 @@ const cart = defineStore({
|
||||
}
|
||||
},
|
||||
|
||||
onChangeEditMode(flag) {
|
||||
this.editMode = flag;
|
||||
this.selectedIds = [];
|
||||
this.getList();
|
||||
},
|
||||
|
||||
// 添加购物车
|
||||
async add(goodsInfo) {
|
||||
// 添加购物项
|
||||
@@ -84,7 +93,7 @@ const cart = defineStore({
|
||||
async selectAll(flag) {
|
||||
const { code } = await CartApi.updateCartSelected({
|
||||
ids: this.list.map((item) => item.id),
|
||||
selected: flag
|
||||
selected: flag,
|
||||
});
|
||||
if (code === 0) {
|
||||
await this.getList();
|
||||
|
||||
Reference in New Issue
Block a user