购物车逻辑

This commit is contained in:
2024-03-20 22:20:24 +08:00
parent 8d7f82b07c
commit 792aa4268a
9 changed files with 118 additions and 63 deletions

View File

@@ -23,7 +23,7 @@
<image class='goods-image' :src='item.images' />
<text class='goods-name'>{{ item.goodsName }}</text>
<text class='goods-price'>¥{{ item.price }}</text>
<image class='add-image' :src='assetsUrl("ic_add_goods.png")' @click.stop='addShoppingCart' />
<image class='add-image' :src='assetsUrl("ic_add_goods.png")' @click.stop='addShoppingCart(item)' />
</view>
</grid-view>
</scroll-view>
@@ -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='shoppingCartCount>0'>{{ shoppingCartCount }}</text>
<text v-if='shoppingCartList.length>0'>{{ shoppingCartList.length }}</text>
</view>
</view>
</template>
@@ -41,11 +41,14 @@ import { assetsUrl } from '@/utils/assets';
import { goPath } from '@/utils';
import { getCategoryList, getGoodsList } from '@/api/goods';
import { CategoryBean, GoodsBean } from '@/api/goods/types';
import useShoppingCartStore from '@/store/modules/shoppingcart';
const shoppingCart = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart);
const categoryList = ref<CategoryBean[]>([]);
const categorySelectedIndex = ref<number>(0);
const goodsList = ref<GoodsBean[]>([]);
const shoppingCartCount = ref<number>(0);
onLoad(() => {
fetchCategoryList();
@@ -73,8 +76,10 @@ const fetchGoodsList = async () => {
goodsList.value = data.rows;
};
const addShoppingCart = () => {
const addShoppingCart = (goodsBean: GoodsBean) => {
shoppingCart.save({
...goodsBean
});
};
</script>

View File

@@ -12,7 +12,7 @@
</view>
</view>
<view class='goods-info-view c-flex-column'>
<view class='goods-info-view c-flex-column' style='margin-right: 10rpx'>
<view class='c-flex-row'>
<text class='goods-price accent-text-color'>{{ goodsBean?.price || 0 }}</text>
<text>销量2653</text>
@@ -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>0</text>
<text v-if='shoppingCartList.length>0'>{{ shoppingCartList.length }}</text>
</view>
<text>购物车</text>
</view>
@@ -90,20 +90,25 @@
</view>
</view>
</view>
<sku-dialog ref='skuDialogRef' @bean='goodsBean' />
<sku-dialog ref='skuDialogRef' :bean='goodsBean' @confirm='confirmGoodsSku' />
</template>
<script lang='ts' setup>
import { assetsUrl } from '@/utils/assets';
import SkuDialog from '@/components/sku-dialog.vue';
import { goPath } from '@/utils';
import { goPath, showToast } from '@/utils';
import { getGoodsDetail, getGoodsList } from '@/api/goods';
import { GoodsBean } from '@/api/goods/types';
import useShoppingCartStore from '@/store/modules/shoppingcart';
const shoppingCart = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart);
const goodsBean = ref<GoodsBean>();
const recommendList = ref<GoodsBean[]>();
const skuDialogRef = ref();
const skuBean = ref();
const bannerList = ref([]);
const swiperIndex = ref(0);
@@ -115,7 +120,7 @@ onLoad(async (e: any) => {
pageSize: 10,
bean: {
keyword: '',
typeIds: ['519334122586648576']
typeIds: ['1724629185362591745']
}
});
recommendList.value = rows;
@@ -133,11 +138,18 @@ const showSkuDialog = () => {
skuDialogRef.value.show();
};
const confirmGoodsSku = (e: any) => {
skuBean.value = e;
};
const addShoppingCart = () => {
uni.showToast({
title: '加入购物车成功',
icon: 'none'
});
shoppingCart.save(
{
...goodsBean.value,
...skuBean.value
}
);
showToast('加入购物车成功');
};
const placeOrder = () => {

View File

@@ -6,23 +6,22 @@
<view class='card-view'>
<scroll-view>
<view class='c-flex-column' v-for='(item, index) in [1,2,3,5]' :key='index'>
<view class='c-flex-column' v-for='(item, index) in shoppingCartList' :key='index'>
<view class='c-flex-row'>
<image v-show='isEditMode' class='checkbox' :src='assetsUrl("ic_checkbox_active_red.png")' />
<image class='goods-image' :src='assetsUrl("test_bg.png")' />
<image class='goods-image' :src='item.images' />
<view class='c-flex-column'>
<text>女童夏装套装洋气装短袖阔腿裤子夏装夏装套装
</text>
<text>{{item.name}}</text>
<view class='sku-view'>
<text>紫色120cm x1</text>
<image :src='assetsUrl("ic_arrow_down_gray.png")' />
</view>
<text>29.90</text>
<text>{{item.price}}</text>
<view class='count-change-view c-flex-row'>
<view class='count-image' @click.stop='countChange(false)'>
<image :src='assetsUrl("ic_reduce.png")' />
</view>
<text>{{ goodsCount }}</text>
<text>{{ item.count || 0 }}</text>
<view class='count-image' @click.stop='countChange(true)'>
<image :src='assetsUrl("ic_plus.png")' />
</view>
@@ -50,10 +49,15 @@
<script lang='ts' setup>
import { assetsUrl } from '@/utils/assets';
import useShoppingCartStore from '@/store/modules/shoppingcart';
const isEditMode = ref(false);
const checkedAll = ref(false);
const goodsCount = ref(1);
const shoppingCart = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart);
// const goodsCount = ref(1);
const countChange = (isPlus: Boolean) => {
@@ -83,7 +87,7 @@ const settlement = () => {
margin: 30rpx;
border-radius: 10rpx;
background: #FFFFFF;
padding: 10rpx 20rpx 20rpx 17rpx;
padding: 10rpx 20rpx 120rpx 17rpx;
.c-flex-column:nth-of-type(1) {
margin: 20rpx 0;

View File

@@ -13,7 +13,7 @@
<text>{{ userInfo.telephone }}</text>
</view>
<image :src='assetsUrl("ic_qrcode_white.png")' />
<image :src='assetsUrl("ic_qrcode_white.png")' @click.stop='gotoPath("qrcode")' />
</view>
<view class='bottom-row'>
@@ -130,6 +130,10 @@ const { userInfo } = storeToRefs(store);
const gotoPath = (path: string) => {
if(path === 'follow_official_account') {
showOfficialAccountDialog();
} else if(path === 'qrcode') {
uni.switchTab({
url: '/pages/qrcode/index'
});
} else {
goPath(path);
}
@@ -138,7 +142,6 @@ const gotoPath = (path: string) => {
const showOfficialAccountDialog = () => {
officialAccountDialogRef.value.show();
};
</script>
<style lang='scss' scoped>

View File

@@ -33,8 +33,8 @@
<text>卡信息</text>
</view>
<text>店铺名称武汉xx店</text>
<text>253654587852</text>
<text>店铺名称{{userInfo.creatorName}}</text>
<text>{{ userInfo.storeId }}</text>
</view>
</view>
@@ -48,6 +48,7 @@ import { generateBarCode, generateQrCode } from '@/api/common';
import { getDynamicCode } from '@/api/user';
import { useUserStore } from '@/store';
import { goPath } from '@/utils';
import { use } from 'licia';
const store = useUserStore();
const { userInfo } = storeToRefs(store);
@@ -58,6 +59,7 @@ const codeRefreshInterval = ref(30);
onLoad(() => {
generateCode();
console.log('------->>>',userInfo.value)
setInterval(() => {
codeRefreshInterval.value -= 1;