Commit 0c5d45598453e6883377b549e68bb632b4a7b39f

Authored by 泉州测试
1 parent 30825842

fix负数问题

Showing 1 changed file with 7 additions and 5 deletions
pages/cart/cart/cart.js
@@ -2108,14 +2108,16 @@ Page({ @@ -2108,14 +2108,16 @@ Page({
2108 icon: 'none', 2108 icon: 'none',
2109 }); 2109 });
2110 // 开启限购 2110 // 开启限购
  2111 + var inputRedisNum = redis_num-cartGoodsNum;
  2112 + var inputNum = num - cartGoodsNum;
2111 if (buylimit > 0) { 2113 if (buylimit > 0) {
2112 if (num > redis_num) { 2114 if (num > redis_num) {
2113 - th.setData({[txt]: redis_num-cartGoodsNum}); 2115 + th.setData({[txt]: inputRedisNum < 0 ? 1 : inputRedisNum});
2114 } else { 2116 } else {
2115 - th.setData({[txt]: num - cartGoodsNum}); 2117 + th.setData({[txt]: inputNum < 0 ? 1 : inputNum});
2116 } 2118 }
2117 } else { 2119 } else {
2118 - th.setData({[txt]: redis_num - cartGoodsNum}); 2120 + th.setData({[txt]: inputRedisNum < 0 ? 1 : inputRedisNum});
2119 } 2121 }
2120 2122
2121 await e.doCheckAll(); 2123 await e.doCheckAll();
@@ -2125,7 +2127,7 @@ Page({ @@ -2125,7 +2127,7 @@ Page({
2125 2127
2126 //--秒杀:判断商品是否超出活动限购-- 2128 //--秒杀:判断商品是否超出活动限购--
2127 if (buylimit > 0) { 2129 if (buylimit > 0) {
2128 - 2130 + var inputNum = num - cartGoodsNum;
2129 // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” 2131 // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量”
2130 if(totalNum > num) { 2132 if(totalNum > num) {
2131 // 计算还可以购买的数量:库存量 - 已购数 2133 // 计算还可以购买的数量:库存量 - 已购数
@@ -2134,7 +2136,7 @@ Page({ @@ -2134,7 +2136,7 @@ Page({
2134 icon: 'none', 2136 icon: 'none',
2135 }); 2137 });
2136 if (num <= 0) num = 1; 2138 if (num <= 0) num = 1;
2137 - th.setData({[txt]: num - cartGoodsNum}); 2139 + th.setData({[txt]: inputNum < 0 ? 1 : inputNum});
2138 await e.doCheckAll(); 2140 await e.doCheckAll();
2139 return false; 2141 return false;
2140 }; 2142 };