购物车逻辑调整
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
|
||||
<view class='shopping-cart' @click.stop='goPath("/pages/mall/subs/shoppingcart/index")'>
|
||||
<image :src='assetsUrl("ic_shopping_cart.png")' />
|
||||
<text v-if='shoppingCartList.length>0'>{{ shoppingCartList?.length }}</text>
|
||||
<text v-if='totalCount>0'>{{ totalCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class='content' v-else style='align-items: center;justify-content:center;'>
|
||||
@@ -52,7 +52,7 @@ import { useUserStore } from '@/store';
|
||||
const userStore = useUserStore();
|
||||
const { companyConfigInfo } = storeToRefs(userStore);
|
||||
const shoppingCartStore = useShoppingCartStore();
|
||||
const { shoppingCartList } = storeToRefs(shoppingCartStore);
|
||||
const { totalCount } = storeToRefs(shoppingCartStore);
|
||||
|
||||
const skuDialogRef = ref();
|
||||
const categoryList = ref<CategoryBean[]>([]);
|
||||
@@ -66,13 +66,12 @@ onLoad(() => {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('companyConfigInfo.value', companyConfigInfo.value);
|
||||
|
||||
userStore.$onAction(({ name, after }) => {
|
||||
after(() => {
|
||||
//更新用户信息
|
||||
if(name === 'setUserInfo') {
|
||||
fetchCategoryList();
|
||||
shoppingCartStore.resetData();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -127,7 +126,16 @@ const getRandomFloatInRange = (a: number, b: number) => {
|
||||
|
||||
const addShoppingCart = (goodsBean: GoodsBean) => {
|
||||
skuDialogRef.value.show(goodsBean.goodsId, (e: GoodsBean) => {
|
||||
shoppingCartStore.save(e);
|
||||
//重新选择sku后判断当前购物中是否存在相同sku的商品
|
||||
const existsIndex = shoppingCartStore.getSameGoodsIndex(e?.id || '', e.checkedStock.colorId, e.checkedStock.sizeId);
|
||||
//不存在则更新当前商品sku
|
||||
if(existsIndex < 0) {
|
||||
shoppingCartStore.save(e);
|
||||
}
|
||||
//如果已存在,则更新已存在商品数量,并删除当前商品
|
||||
else {
|
||||
shoppingCartStore.updateCount(existsIndex, e.checkedStock.count);
|
||||
}
|
||||
showToast('添加购物车成功');
|
||||
});
|
||||
};
|
||||
|
@@ -42,7 +42,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class='recommend-view c-flex-column' v-if='recommendList?.length>0'>
|
||||
<view class='recommend-view c-flex-column' v-if='(recommendList?.length||0)>0'>
|
||||
<text>浏览此商品的客户还浏览了</text>
|
||||
<scroll-view scroll-x>
|
||||
<view style='display: inline-block' v-for='(item, index) in recommendList'
|
||||
@@ -78,7 +78,7 @@
|
||||
<view class='small-button-item'>
|
||||
<view class='shoppingcart-count' @click.stop='goPath("/pages/mall/subs/shoppingcart/index")'>
|
||||
<image :src='assetsUrl("ic_goods_shoppingcart.png")' />
|
||||
<text v-if='shoppingCartList.length>0'>{{ shoppingCartList.length }}</text>
|
||||
<text v-if='totalCount>0'>{{ totalCount }}</text>
|
||||
</view>
|
||||
<text>购物车</text>
|
||||
</view>
|
||||
@@ -102,7 +102,7 @@ import { GoodsBean } from '@/api/goods/types';
|
||||
import useShoppingCartStore from '@/store/modules/shoppingcart';
|
||||
|
||||
const shoppingCartStore = useShoppingCartStore();
|
||||
const { shoppingCartList } = storeToRefs(shoppingCartStore);
|
||||
const { totalCount } = storeToRefs(shoppingCartStore);
|
||||
|
||||
const goodsBean = ref<GoodsBean>();
|
||||
const recommendList = ref<GoodsBean[]>();
|
||||
|
@@ -6,7 +6,7 @@
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class='card-view' v-if='shoppingCartList.length>0'>
|
||||
<view class='card-view' v-if='totalCount>0'>
|
||||
<scroll-view>
|
||||
<view class='c-flex-column' v-for='(item, index) in shoppingCartList' :key='index'>
|
||||
<view class='c-flex-row'>
|
||||
@@ -72,7 +72,7 @@ const isEditMode = ref(false);
|
||||
const checkedAll = ref(false);
|
||||
|
||||
const shoppingCartStore = useShoppingCartStore();
|
||||
const { shoppingCartList } = storeToRefs(shoppingCartStore);
|
||||
const { shoppingCartList, totalCount } = storeToRefs(shoppingCartStore);
|
||||
|
||||
const skuDialogRef = ref();
|
||||
const temporaryGoodsBean = ref<GoodsBean>();
|
||||
|
Reference in New Issue
Block a user