微信小程序实现购物时限购商品的数量(附代码)

互联网 18-8-10
本篇文章给大家带来的内容是关于微信小程序实现购物时限购商品的数量(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

展示效果如下:

两个底部用的是一个弹框,利用submit_type的类型不一样来进行区分哪个是单独购买哪个是包邮开团

wxml代码如下:

 <view class="num-box">       <view class="weui-media-box__bd">           <view class="promotion-sku clear">              <view class="Spinner">                 <a wx:if="{{goods_count==1}}" class="DisDe">                      <i bindtap="minusCount" data-index="{{index}}" class="DisDe">-</i>                 </a>                 <a wx:if="{{goods_count>1}}" class="Decrease">                      <i bindtap="minusCount" data-index="{{index}}" class="DisDe">-</i>                 </a>              <view>               <input class="Amount" bindinput="changeCount" type='number' value="{{goods_count}}" autocomplete="off" maxlength="3"  data-submit_type="{{submit_type}}" />            </view>                 <a class="Increase">                    <i bindtap="addCount" data-index="{{index}}" data-submit_type="{{submit_type}}">+</i>                 </a>                              </view>          </view>       </view>  </view>

data-submit_type="{{submit_type}}"中的submit_type就是判断是单独还是开团购买

js代码如下:

// 增加数量   addCount(e) {     // 购买类型,单独购买或拼团购买     let submit_type = e.target.dataset.submit_type;     var goods_count = this.data.goods_count;     goods_count = parseInt(goods_count) + 1;     //debugger     if (submit_type == 2) {  // 拼团购买       var limited_num = this.data.collage.limited_num;       if (goods_count > limited_num) {         this.showTip('超出限购');         return;       }     }     this.setData({       goods_count: goods_count     });   }, // 改变数量(input内的值)   changeCount(e) {     var goods_count = e.detail.value;      let submit_type = e.target.dataset.submit_type;     if (submit_type == 1) {       var sys_num = this.data.goods_num;       if (goods_count > sys_num) {  // 单独购买         this.showTip('库存不足');         return;       }     } else if (submit_type == 2) {  // 拼团购买       var limited_num = this.data.collage.limited_num;       if (goods_count > limited_num) {         this.showTip('超出限购');         return;       }     }      if (!(/^[\d]+\.?\d*$/.test(goods_count))) {       goods_count = goods_count.replace(/\D/g, '');       return goods_count ? goods_count : 1;     }     if (goods_count < 1) {       return 1;     }     this.setData({       goods_count: goods_count     });   },

相关推荐:

微信小程序自定义底部tarbar的代码实现

微信小程序实例:实现顶部tab切换以及滑动切换时导航栏会随着移动的效果(代码)

以上就是微信小程序实现购物时限购商品的数量(附代码)的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: 微信小程序
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:微信小程序自定义底部tarbar的代码实现

相关资讯