diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 429afca..786d303 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -2099,34 +2099,54 @@ Page({ if (th.data.sele_g.viplimited > 0) { var gd_buy_num = th.data.promcardbuynum; - if(t.goods_num > th.data.sele_g.goods_num) { - wx.showModal({ - title: '超出活动库存', - }); + // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”; + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” + + if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) { + // 计算还可以购买的数量:库存量 - 已购数 + var num = th.data.sele_g.goods_num - gd_buy_num; + if(num < 0) num = 0; + if(t.goods_num > num) { + wx.showModal({ + title: '超出活动库存', + }); + + // var num = th.data.sele_g.goods_num; + th.setData({[txt]: num}); + // t.goods_num = num; + // th.doCheckAll(); + // th.update_cart_ser(t, pitem, item); + // return false; + + }; - var num = th.data.sele_g.goods_num; - th.setData({goodsInputNum: num}) - return false; + } else { + + if ((t.goods_num + gd_buy_num> th.data.sele_g.viplimited) && (t.goods_num <= th.data.sele_g.goods_num)) { + wx.showModal({ + title: '超出活动限购数量', + }); + + var num = th.data.sele_g.viplimited - gd_buy_num; + if (num <= 0) num = 1; + + th.setData({ + [txt]: num, + gdnum: num, + }); + + // return false; + } }; - if ((t.goods_num + gd_buy_num> th.data.sele_g.viplimited) && (t.goods_num <= th.data.sele_g.goods_num)) { - wx.showModal({ - title: '超出活动限购数量', - }); - - var num = th.data.sele_g.viplimited - gd_buy_num; - if (num <= 0) num = 1; - - th.setData({ - [txt]: num, - gdnum: num, - }); - t.goods_num = num; - th.doCheckAll(); - th.update_cart_ser(t, pitem, item); - // return false; - } + + t.goods_num = num; + th.doCheckAll(); + th.update_cart_ser(t, pitem, item); + + + }; };