lilei 9 ヶ月 前
コミット
ab0e7bb3c7
4 ファイル変更30 行追加19 行削除
  1. 22 2
      pages/index/index.vue
  2. 1 0
      pagesB/cart/index.vue
  3. 4 17
      pagesB/shopiing/productDetail.vue
  4. 3 0
      store/index.js

+ 22 - 2
pages/index/index.vue

@@ -180,7 +180,7 @@
 	import { scanVinLogQueryRoll, getScanVinLogList, getScanGetMaxQty }from '@/api/car.js'
 	import { promoTerminalList } from '@/api/video.js'
 	import { getRewardRollList } from '@/api/rewardRule.js'
-	import { getShopStatus } from '@/api/cart.js'
+	import { getShopStatus, getCartCount } from '@/api/cart.js'
 	import { getShopCategory, getShopProductList } from '@/api/shop.js'
 	import { openWebView, clickTab, toAuthStore, clickBannerList, toLogin } from "@/utils/index.js"
 	export default {
@@ -339,11 +339,16 @@
 			uni.$on("refashHome",()=>{
 				this.pageInit(2)
 			})
+			// 刷新购物车
+			uni.$on("refashCart",()=>{
+				this.cartCount()
+			})
 		},
 		// 页面卸载
 		onUnload() {
 			uni.$off('refashHome')
 			uni.$off('refashProm')
+			uni.$off('refashCart')
 		},
 		onHide() {
 			// 用户头像
@@ -468,7 +473,7 @@
 					// 有商城
 					if(this.hasShopiing){
 						// 隐藏tab 视频,显示tab购物车
-						this.showCatTab()
+						this.cartCount()
 						// 商品分类
 						this.getGoodType(flag)
 						// 获取推荐产品
@@ -487,6 +492,15 @@
 					this.getRedPacketRule()
 				})
 			},
+			// 购物车数量
+			cartCount(){
+				getCartCount({}).then(res => {
+					if(res.status == 200){
+						this.$store.state.vuex_cartTotal = res.data?res.data.qty:0
+						this.showCatTab()
+					}
+				})
+			},
 			// 商品一级分类
 			getGoodType(flag){
 				this.productTypeList = []
@@ -705,8 +719,14 @@
 						"selectedIconPath": "/static/tab/tab_cart_pressed.png",
 						"text": "购物车",
 						'customIcon': false,
+						'count': this.$store.state.vuex_cartTotal,
+						'isDot': false
 					})
 				}
+				// 购物车已存在
+				if(catIndex>=0){
+					this.$store.state.vuex_tabBarList[catIndex].count = this.$store.state.vuex_cartTotal
+				}
 			},
 			// 显示视频tab,隐藏购物车
 			showVideoTab(){

+ 1 - 0
pagesB/cart/index.vue

@@ -248,6 +248,7 @@
 							this.list[crow.p].splice()
 							// 合计
 							this.getChooseHeji()
+							uni.$emit('refashCart')
 						}
 					}
 					uni.hideLoading()

+ 4 - 17
pagesB/shopiing/productDetail.vue

@@ -127,7 +127,6 @@
 				statusBarHeight: 0, // 状态栏高度
 				safeAreaBottom: 0, // 底部安全区域高度
 				imgList: [],
-				totalNum: 0 ,// 购物车总数
 				shopProductSn: null,
 				detail: null,
 				qty: 1,// 数量
@@ -143,13 +142,6 @@
 			// 获取产品详情
 			this.getDetail()
 		},
-		onShow(){
-			// 已登录,且已认证
-			if(this.hasLogin&&this.userInfo.sysUserFlag == '1'){
-				// 购物车数量
-				this.cartCount()
-			}
-		},
 		// 分享
 		onShareAppMessage(e){
 			return {
@@ -165,6 +157,9 @@
 			userInfo(){
 				return this.$store.state.vuex_userInfo
 			},
+			totalNum(){
+				return this.hasLogin&&this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_cartTotal : 0
+			}
 		},
 		methods: {
 			// 返回
@@ -213,14 +208,6 @@
 					uni.hideLoading()
 				})
 			},
-			// 购物车数量
-			cartCount(){
-				getCartCount({}).then(res => {
-					if(res.status == 200){
-						this.totalNum = res.data?res.data.qty:0
-					}
-				})
-	        },
 			// 加入购物车
 			addCart(){
 				if(this.hasLogin){
@@ -239,7 +226,7 @@
 							productSn: this.detail.productSn
 						}).then(res => {
 							if(res.status == 200){
-								this.cartCount()
+								uni.$emit('refashCart')
 								uni.hideLoading()
 							}
 						})

+ 3 - 0
store/index.js

@@ -61,6 +61,7 @@ const store = new Vuex.Store({
 		vuex_nowRoleInfo: null, // 角色
 		vuex_vinScanNums:null, // 扫描次数
 		vuex_scanMaxNums: 10, // 最大扫描次数
+		vuex_cartTotal: 0, // 购物车总数
 		vuex_storeAuthInfo: null ,// 门店认证状态信息
 		vuex_tempData: null, // 临时数据
 		vuex_configPrice: null, // 价格显示配置
@@ -87,6 +88,8 @@ const store = new Vuex.Store({
 				"selectedIconPath": "/static/tab/tab_cart_pressed.png",
 				"text": "购物车",
 				'customIcon': false,
+				'count': 0,
+				'isDot': false
 			},
 			{
 				"pagePath": "/pages/morePage/morePage",