lilei 4 vuotta sitten
vanhempi
commit
5cd6096e78
2 muutettua tiedostoa jossa 44 lisäystä ja 14 poistoa
  1. 40 14
      pages/cart/cart.vue
  2. 4 0
      pages/index/index.vue

+ 40 - 14
pages/cart/cart.vue

@@ -23,7 +23,7 @@
 						</u-checkbox>
 						</u-checkbox>
 					</view>
 					</view>
 					<view class="des">
 					<view class="des">
-						<view>满<text>{{item.goldLimit}}</text></view>
+						<view>商品乐豆合计满<text>{{item.goldLimit}}</text></view>
 						<u-image mode="scaleToFill" width="26rpx" height="26rpx" src="/static/ledou.png"></u-image>
 						<u-image mode="scaleToFill" width="26rpx" height="26rpx" src="/static/ledou.png"></u-image>
 						<view>才可购买</view>
 						<view>才可购买</view>
 					</view>
 					</view>
@@ -140,7 +140,8 @@
 				return this.$store.state.vuex_cartList
 				return this.$store.state.vuex_cartList
 			}
 			}
 		},
 		},
-		onLoad() {
+		onShow() {
+			uni.$emit('getCartList')
 			this.hasCheckAll()
 			this.hasCheckAll()
 		},
 		},
 		methods: {
 		methods: {
@@ -168,28 +169,53 @@
 				})
 				})
 				arr.splice()
 				arr.splice()
 			},
 			},
+			// 判断当前分类下的商品总和是否满足规则
+			hasZgjindu(item){
+				let ret = 0
+				let goldLimit = item.goldLimit
+				item.shoppingCartGoodsList.map(good=>{
+					ret = ret + good.goods.sellGold
+				})
+				console.log(ret , goldLimit)
+				return ret >= goldLimit
+			},
 			// 每个分类的全选
 			// 每个分类的全选
 			goodsClasChange(e){
 			goodsClasChange(e){
 				console.log(e);
 				console.log(e);
 				let index = this.cartList.findIndex(item => item.goodsTypeNo == e.name)
 				let index = this.cartList.findIndex(item => item.goodsTypeNo == e.name)
-				this.cartList[index].checked = e.value
-				this.cartList[index].shoppingCartGoodsList.map(goods=>{
-					goods.checked = e.value
-				})
-				// 判断是否全选
-				this.hasCheckAll()
+				let item = this.cartList[index]
+				if(this.hasZgjindu(item)){
+					item.checked = e.value
+					item.shoppingCartGoodsList.map(goods=>{
+						goods.checked = e.value
+					})
+					// 判断是否全选
+					this.hasCheckAll()
+				}else{
+					uni.showToast({
+						icon: 'none',
+						title: '此分类的商品乐豆合计需要满'+item.goldLimit+'乐豆才可以购买'
+					})
+				}
 			},
 			},
 			// 商品选择
 			// 商品选择
 			goodsChange(e){
 			goodsChange(e){
 				console.log(e)
 				console.log(e)
 				let a = e.name.split('-')
 				let a = e.name.split('-')
 				let row = this.cartList[a[1]]
 				let row = this.cartList[a[1]]
-				let goodsIndex = row.shoppingCartGoodsList.findIndex(item => item.id == a[0])
-				row.shoppingCartGoodsList[goodsIndex].checked = e.value
-				// 判断当前分类是否全选
-				this.clasGoodsHasCheckAll(a[1])
-				// 判断是否全选
-				this.hasCheckAll()
+				if(this.hasZgjindu(row)){
+					let goodsIndex = row.shoppingCartGoodsList.findIndex(item => item.id == a[0])
+					row.shoppingCartGoodsList[goodsIndex].checked = e.value
+					// 判断当前分类是否全选
+					this.clasGoodsHasCheckAll(a[1])
+					// 判断是否全选
+					this.hasCheckAll()
+				}else{
+					uni.showToast({
+						icon: 'none',
+						title: '此分类的商品乐豆合计需要满'+row.goldLimit+'乐豆才可以购买'
+					})
+				}
 			},
 			},
 			// 判断某个分类是否全选
 			// 判断某个分类是否全选
 			clasGoodsHasCheckAll(index){
 			clasGoodsHasCheckAll(index){

+ 4 - 0
pages/index/index.vue

@@ -91,6 +91,10 @@
 			this.getLocation()
 			this.getLocation()
 			// 查询购物车列表
 			// 查询购物车列表
 			this.getCartList()
 			this.getCartList()
+			// 刷新购物车列表
+			uni.$on("getCartList",item =>{
+				this.getCartList()
+			})
 			// 加入购物车
 			// 加入购物车
 			uni.$on("addCart",item =>{
 			uni.$on("addCart",item =>{
 				this.addGoodToCart(item)
 				this.addGoodToCart(item)