From 38b037bf795004cae617f9ca8fe432524e799bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E5=9F=8E?= <141405260+17521612761@users.noreply.github.com> Date: Sun, 17 Nov 2024 11:57:28 +0800 Subject: [PATCH] =?UTF-8?q?uniapp=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91:?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E9=A1=B5=E9=9D=A2=E6=97=A0?= =?UTF-8?q?=E8=AE=BA=E6=98=AF=E8=BF=94=E5=9B=9E=E8=BF=9B=E5=85=A5=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreShop/core/models/cart.ts | 5 +++ .../classify-five/classify-five.vue | 36 ++++++++----------- .../classify-four/classify-four.vue | 27 ++++++-------- .../CoreShop/pages/classify/classify.vue | 34 +++++++++++++----- 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/CoreCms.Net.Uni-App/CoreShop/core/models/cart.ts b/CoreCms.Net.Uni-App/CoreShop/core/models/cart.ts index c31e34cf..7a9e9262 100644 --- a/CoreCms.Net.Uni-App/CoreShop/core/models/cart.ts +++ b/CoreCms.Net.Uni-App/CoreShop/core/models/cart.ts @@ -10,4 +10,9 @@ export interface CartListType { userId ?: number; weight ?: number; select ?: boolean; +} + +export interface CartMoneyNumType { + count ?: number, + money ?: number, } \ No newline at end of file diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-five/classify-five.vue b/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-five/classify-five.vue index 6abd987e..1b9defe5 100644 --- a/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-five/classify-five.vue +++ b/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-five/classify-five.vue @@ -85,8 +85,8 @@ - 购物车数量:{{ state.cartCount }} - ¥{{ state.cartMoney }} + 购物车数量:{{ props.cartData.count }} + ¥{{ props.cartData.money }} @@ -126,8 +126,8 @@ import { reactive, watch, ref, onMounted, getCurrentInstance, nextTick } from 'vue'; import { advertPosition, UserToken, onClassifyPageHide, onClassifyPagePullDownRefresh } from '@/core/consts'; import { useLoginStore } from '@/core/store'; - import { queryGoodsPageList, queryCartNumAndMoney, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api'; - import type { CategoriesType, Response, GoodsListType, GoodsType } from '@/core/models'; + import { queryGoodsPageList, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api'; + import type { CategoriesType, Response, GoodsListType, GoodsType, CartMoneyNumType } from '@/core/models'; import { getDomInfo, handleStaticResources, handleRouteNavigateTo, handleShowToast, handleRouteSwitchTab } from '@/core/utils'; import { AddCartEnum, PaymentTypeEnum, RouteSwitchTabEnum } from '@/core/enum'; import GoodsDetailSkuPopup from '@/pages/components/goods-detail/components/goods-detail-sku/goods-detail-sku.vue'; @@ -142,10 +142,12 @@ data : Array, height : number, statusBarHeight : number, + cartData : CartMoneyNumType, }>(), { data: () => [], height: 0, statusBarHeight: 0, + cartData: () => ({}), }); const bigClassifyPop = ref(); @@ -190,8 +192,9 @@ const addCartLoading = ref(false); const handleBuyNow = useLoadingFn(onBuyNow, buyNowLoading); - const handleAddCart = useLoadingFn(onAddCart, addCartLoading) - + const handleAddCart = useLoadingFn(onAddCart, addCartLoading) + + const emit = defineEmits(['getCartNumAndMoney']) watch(() => props.data, (newVal : Array) => { if (newVal) { @@ -216,9 +219,9 @@ }) onMounted(() => { - if (uni.getStorageSync(UserToken)) { - getCartNumAndMoney(); - } + uni.$on(onClassifyPageHide, () => { + state.showSku = false; + }) uni.$on(onClassifyPagePullDownRefresh, () => { state.page = 1; @@ -226,10 +229,6 @@ state.goodsList = []; }) - uni.$on(onClassifyPageHide, () => { - state.showSku = false; - }) - nextTick(async () => { state.bigClassifyH = ((await getDomInfo('.big-classify', instance.proxy)) as { height : number }).height; setTimeout(async () => { @@ -252,13 +251,6 @@ } } - /** 获取购物车数量和价格 */ - const getCartNumAndMoney = async () => { - const cartNumAndMoney : Response<{ count : number, money : number }> = await queryCartNumAndMoney(); - state.cartCount = cartNumAndMoney?.data?.count || 0; - state.cartMoney = cartNumAndMoney?.data?.money || 0; - } - /** 选择sku */ const handleSelectSku = (id : number) => { _useLoginStore.checkLogin(async () => { @@ -296,7 +288,7 @@ if (addCart.status) { handleShowToast(addCart.msg, "success"); /** 添加成功后,重新获取购物车数量和价格 */ - getCartNumAndMoney(); + emit("getCartNumAndMoney"); /** 关闭sku弹框 */ handleChangePopup(false); } else { @@ -336,7 +328,7 @@ state.leftTabId = item?.child[0].id; state.leftTabList = item?.child; state.rightTabList = item?.child[0]?.child; - + handleResetGoodsList(); hanlderHidebigClassifyPop(); } diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-four/classify-four.vue b/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-four/classify-four.vue index 1bcaac9d..1d547d8a 100644 --- a/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-four/classify-four.vue +++ b/CoreCms.Net.Uni-App/CoreShop/pages/classify/classify-page/classify-four/classify-four.vue @@ -56,8 +56,8 @@ - 购物车数量:{{ state.cartCount }} - ¥{{ state.cartMoney }} + 购物车数量:{{ props.cartData.count }} + ¥{{ props.cartData.money }} @@ -77,8 +77,8 @@