Commit d0c80654e66fc2d62c236c0349ddf2ce54f3b543
1 parent
ec5b07d3
fix提示框
Showing
1 changed file
with
48 additions
and
26 deletions
packageA/pages/goodsInfo/goodsInfo.js
| ... | ... | @@ -877,10 +877,21 @@ Page({ |
| 877 | 877 | var redisNum = 0; |
| 878 | 878 | await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { |
| 879 | 879 | if (res.data.code == 0) { |
| 880 | - redisNum = res.data.data; | |
| 880 | + redisNum = !res.data.data ? 0 : res.data.data; | |
| 881 | 881 | }; |
| 882 | 882 | }); |
| 883 | 883 | |
| 884 | + // 获取购物车同款数量 判断是否超库存 | |
| 885 | + var cartGoodsNum = 0; | |
| 886 | + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id+"&pick_id="+th.data.sto_sele_id, | |
| 887 | + { }).then(res => { | |
| 888 | + if (res.data.data.pageData.length > 0) { | |
| 889 | + const tmpObj = res.data.data.pageData[0]; | |
| 890 | + cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; | |
| 891 | + } | |
| 892 | + | |
| 893 | + }); | |
| 894 | + | |
| 884 | 895 | // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 |
| 885 | 896 | // 没有库存,已抢光的情况下,走正常购买流程 |
| 886 | 897 | if(redisNum > 0 && !this.data.is_normal) { |
| ... | ... | @@ -888,36 +899,40 @@ Page({ |
| 888 | 899 | var t = th.data.goodsInputNum; |
| 889 | 900 | |
| 890 | 901 | if (t > redisNum) { |
| 891 | - wx.showModal({ | |
| 902 | + wx.showToast({ | |
| 892 | 903 | title: '超出活动库存', |
| 904 | + icon: 'none' | |
| 893 | 905 | }); |
| 894 | 906 | |
| 895 | 907 | // 开启限购 |
| 896 | 908 | if (th.data.sele_g.viplimited > 0) { |
| 909 | + | |
| 897 | 910 | let num = th.data.sele_g.viplimited - gd_buy_num; |
| 898 | - if (num > redisNum) { | |
| 899 | - th.setData({goodsInputNum: redisNum}); | |
| 911 | + if (action !="buy") { | |
| 912 | + // 购物车 | |
| 913 | + if (num > redisNum) { | |
| 914 | + th.setData({goodsInputNum: redisNum - cartGoodsNum}); | |
| 915 | + } else { | |
| 916 | + th.setData({goodsInputNum: num - cartGoodsNum}); | |
| 917 | + } | |
| 900 | 918 | } else { |
| 901 | - th.setData({goodsInputNum: num}); | |
| 919 | + // 立即购买 | |
| 920 | + if (num > redisNum) { | |
| 921 | + th.setData({goodsInputNum: redisNum}); | |
| 922 | + } else { | |
| 923 | + th.setData({goodsInputNum: num}); | |
| 924 | + } | |
| 902 | 925 | } |
| 926 | + | |
| 927 | + | |
| 903 | 928 | } else { |
| 904 | 929 | th.setData({goodsInputNum: redisNum}); |
| 905 | 930 | } |
| 906 | 931 | |
| 907 | - | |
| 908 | 932 | return false; |
| 909 | 933 | } |
| 910 | 934 | |
| 911 | - // 获取购物车同款数量 判断是否超库存 | |
| 912 | - var cartGoodsNum = 0; | |
| 913 | - await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id+"&pick_id="+th.data.sto_sele_id, | |
| 914 | - { }).then(res => { | |
| 915 | - if (res.data.data.pageData.length > 0) { | |
| 916 | - const tmpObj = res.data.data.pageData[0]; | |
| 917 | - cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; | |
| 918 | - } | |
| 919 | - | |
| 920 | - }); | |
| 935 | + | |
| 921 | 936 | |
| 922 | 937 | // 跳过<立即购买> 购物车 |
| 923 | 938 | if (action !="buy") { |
| ... | ... | @@ -929,8 +944,9 @@ Page({ |
| 929 | 944 | if (th.data.sele_g.viplimited > 0) { |
| 930 | 945 | |
| 931 | 946 | if (maxNum + gd_buy_num > th.data.sele_g.buy_limit) { |
| 932 | - wx.showModal({ | |
| 947 | + wx.showToast({ | |
| 933 | 948 | title: '超出活动限购数量', |
| 949 | + icon: 'none' | |
| 934 | 950 | }); |
| 935 | 951 | |
| 936 | 952 | // 可购买数量 |
| ... | ... | @@ -942,8 +958,9 @@ Page({ |
| 942 | 958 | } |
| 943 | 959 | |
| 944 | 960 | if (maxNum > redisNum) { |
| 945 | - wx.showModal({ | |
| 961 | + wx.showToast({ | |
| 946 | 962 | title: '超出活动库存', |
| 963 | + icon: 'none' | |
| 947 | 964 | }); |
| 948 | 965 | // 可购买数量 |
| 949 | 966 | let num = redisNum - cartGoodsNum; |
| ... | ... | @@ -952,14 +969,14 @@ Page({ |
| 952 | 969 | } |
| 953 | 970 | |
| 954 | 971 | } else { |
| 955 | - | |
| 956 | 972 | // 以下为立即购买 |
| 957 | 973 | // 是否开启个人限购 |
| 958 | 974 | if (th.data.sele_g.viplimited > 0) { |
| 959 | 975 | |
| 960 | 976 | if (t + gd_buy_num > th.data.sele_g.viplimited) { |
| 961 | - wx.showModal({ | |
| 977 | + wx.showToast({ | |
| 962 | 978 | title: '超出活动限购数量', |
| 979 | + icon: 'none' | |
| 963 | 980 | }); |
| 964 | 981 | |
| 965 | 982 | let num = th.data.sele_g.viplimited - gd_buy_num; |
| ... | ... | @@ -973,6 +990,7 @@ Page({ |
| 973 | 990 | |
| 974 | 991 | |
| 975 | 992 | }; |
| 993 | + | |
| 976 | 994 | } |
| 977 | 995 | |
| 978 | 996 | }; |
| ... | ... | @@ -1210,9 +1228,10 @@ Page({ |
| 1210 | 1228 | }); |
| 1211 | 1229 | |
| 1212 | 1230 | if (t > redis_num) { |
| 1213 | - wx.showModal({ | |
| 1231 | + wx.showToast({ | |
| 1214 | 1232 | // title: '超出商品活动库存', |
| 1215 | 1233 | title: '超出活动库存', |
| 1234 | + icon: 'none', | |
| 1216 | 1235 | }); |
| 1217 | 1236 | th.setData({goodsInputNum: redis_num}) |
| 1218 | 1237 | return false; |
| ... | ... | @@ -1231,8 +1250,9 @@ Page({ |
| 1231 | 1250 | var num = th.data.sele_g.goods_num - gd_buy_num; |
| 1232 | 1251 | if(num < 0) num = 0; |
| 1233 | 1252 | if(t > num) { |
| 1234 | - wx.showModal({ | |
| 1253 | + wx.showToast({ | |
| 1235 | 1254 | title: '超出活动库存', |
| 1255 | + icon: 'none', | |
| 1236 | 1256 | }); |
| 1237 | 1257 | |
| 1238 | 1258 | th.setData({goodsInputNum: num}) |
| ... | ... | @@ -1242,8 +1262,9 @@ Page({ |
| 1242 | 1262 | |
| 1243 | 1263 | } else { |
| 1244 | 1264 | if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) { |
| 1245 | - wx.showModal({ | |
| 1265 | + wx.showToast({ | |
| 1246 | 1266 | title: '超出活动限购数量', |
| 1267 | + icon: 'none', | |
| 1247 | 1268 | }); |
| 1248 | 1269 | |
| 1249 | 1270 | var num = th.data.sele_g.viplimited - gd_buy_num; |
| ... | ... | @@ -1285,7 +1306,6 @@ Page({ |
| 1285 | 1306 | // e = th.data.def_pick_store.CanOutQty; |
| 1286 | 1307 | } |
| 1287 | 1308 | } |
| 1288 | - | |
| 1289 | 1309 | |
| 1290 | 1310 | th.setData({goodsInputNum: t}); |
| 1291 | 1311 | |
| ... | ... | @@ -1321,10 +1341,12 @@ Page({ |
| 1321 | 1341 | return false; |
| 1322 | 1342 | } |
| 1323 | 1343 | |
| 1324 | - var ind = t.currentTarget.dataset.ind; | |
| 1344 | + var ind = t.currentTarget.dataset.ind; | |
| 1345 | + | |
| 1325 | 1346 | this.setData({ |
| 1326 | 1347 | openSpecModal: !0, |
| 1327 | - openSpecModal_ind: ind, | |
| 1348 | + openSpecModal_ind: ind, | |
| 1349 | + goodsInputNum: 1, | |
| 1328 | 1350 | }); |
| 1329 | 1351 | |
| 1330 | 1352 | }, | ... | ... |