Bladeren bron

bug 修复

lilei 4 jaren geleden
bovenliggende
commit
92b786863e
3 gewijzigde bestanden met toevoegingen van 33 en 7 verwijderingen
  1. 19 3
      components/uni-coods/uni-coods.vue
  2. 3 2
      components/uni-numbers-box/uni-numbers-box.vue
  3. 11 2
      pages/cart/cart.vue

+ 19 - 3
components/uni-coods/uni-coods.vue

@@ -54,11 +54,27 @@
 			}
 		},
 		methods: {
+			// 判断当前商品库存是否够
+			hasZgKucun(data){
+				let list = this.$store.state.vuex_cartList
+				let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
+				let good = row.shoppingCartGoodsList.find(item => item.goodsNo == data.goodsNo)
+				console.log(good,data.inventoryQty)
+				return !good ? true : good.buyQty < data.inventoryQty
+			},
 			// 加入购物车
 			addCart(item) {
-				this.$bindClick(function(){
-					uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
-				})
+				console.log(item)
+				if(this.hasZgKucun(item)){
+					this.$bindClick(function(){
+						uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
+					})
+				}else{
+					uni.showToast({
+						icon: 'none',
+						title: '此商品库存不足'
+					})
+				}
 			},
 			// 商品详情
 			toDetail(item){

+ 3 - 2
components/uni-numbers-box/uni-numbers-box.vue

@@ -50,7 +50,7 @@
 			},
 			inputValue(newVal, oldVal) {
 				console.log(newVal,oldVal,this.index,'111')
-				if (+newVal !== +oldVal) {
+				if (+newVal !== +oldVal && this.max >= +newVal && this.min <= +newVal) {
 					this.$emit("change", newVal, this.index);
 				}
 			}
@@ -126,7 +126,7 @@
 		display: flex;
 		/* #endif */
 		flex-direction: row;
-		width: 100px;
+		width: 120px;
 	}
 
 	.uni-numbox__value {
@@ -136,6 +136,7 @@
 		line-height: $box-height;
 		text-align: center;
 		font-size: $uni-font-size-lg;
+		margin: 0 10px;
 	}
 
 	.uni-numbox__minus {

+ 11 - 2
pages/cart/cart.vue

@@ -56,12 +56,14 @@
 										<image mode="scaleToFill" style="width: 30rpx;height: 30rpx;"src="/static/ledou.png"></image>
 									</view>
 									<view v-if="good.goods.inventoryQty>0&&good.goods.state==1">
-										<uni-numbers-box @change="goodsNumsChange()" :index="cindex+'-'+index" :value="good.buyQty" :min="1"></uni-numbers-box>
+										<uni-numbers-box @change="goodsNumsChange()" :index="cindex+'-'+index" :value="good.buyQty" :max="good.goods.inventoryQty" :min="1"></uni-numbers-box>
 									</view>
 									<view v-else>
 										<view style="width: 100rpx;text-align: center;">×{{good.buyQty}}</view>
 									</view>
 								</view>
+								<view class="goods-kucun" v-if="good.goods.state == 1&&good.goods.inventoryQty==0">库存不足</view>
+								<view class="goods-kucun" v-else>库存:<text>{{good.goods.inventoryQty}}</text></view>
 							</view>
 						</view>
 					</view>
@@ -460,11 +462,18 @@ page{
 					}
 				}
 			}
+			.goods-kucun{
+				padding-top: 10rpx;
+				font-size: 22rpx;
+				text{
+					color: #999;
+				}
+			}
 			.goods-price{
 				display: flex;
 				align-items: center;
 				justify-content: space-between;
-				padding-top: 20upx;
+				padding-top: 10upx;
 				>view{
 					&:first-child{
 						font-size: 22upx;