Browse Source

库存限制

panhui 5 years ago
parent
commit
d6cb13bc85
2 changed files with 12 additions and 1 deletions
  1. 4 1
      src/components/GoodsSuk.vue
  2. 8 0
      src/pages/shoppingDetail.vue

+ 4 - 1
src/components/GoodsSuk.vue

@@ -28,7 +28,7 @@
 
         <div class="num">
             <div class="text1">购买数量</div>
-            <van-stepper :value="num" @change="changeNum" />
+            <van-stepper :value="num" @change="changeNum" :max="stock" />
         </div>
 
         <div style="flex-grow:1;min-height:10px"></div>
@@ -71,6 +71,9 @@ export default {
         },
         mainImg() {
             return this.info.images ? [...this.info.images].shift() : '';
+        },
+        stock() {
+            return this.info.stock || 0;
         }
     },
     watch: {

+ 8 - 0
src/pages/shoppingDetail.vue

@@ -363,6 +363,14 @@ export default {
                 });
                 return;
             }
+
+            if (this.num > this.info.stock || 0) {
+                wx.showToast({
+                    icon: 'none',
+                    title: '商品库存不足'
+                });
+                return;
+            }
             // if (!this.cityId) {
             //     wx.showToast({
             //         icon: 'none',