WeChat applet allows you to limit the number of items you can purchase during shopping (with code)

不言
Release: 2018-08-10 14:45:19
Original
6013 people have browsed it

The content of this article is about the WeChat applet that implements the number of products that can be purchased during shopping (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The display effect is as follows:

#The two bottoms use a pop-up box, and the different types of submit_type are used to distinguish which one is separate Which one is purchased with free shipping in a group?

The wxml code is as follows:

 <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=&#39;number&#39; 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>
Copy after login

data-submit_type="{{submit_type}}" The submit_type in it is used to determine whether to purchase individually or in a group

js code is as follows:

// 增加数量
  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(&#39;超出限购&#39;);
        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(&#39;库存不足&#39;);
        return;
      }
    } else if (submit_type == 2) {  // 拼团购买
      var limited_num = this.data.collage.limited_num;
      if (goods_count > limited_num) {
        this.showTip(&#39;超出限购&#39;);
        return;
      }
    }

    if (!(/^[\d]+\.?\d*$/.test(goods_count))) {
      goods_count = goods_count.replace(/\D/g, &#39;&#39;);
      return goods_count ? goods_count : 1;
    }
    if (goods_count < 1) {
      return 1;
    }
    this.setData({
      goods_count: goods_count
    });
  },
Copy after login

Related recommendations:

WeChat applet customizes the bottom tarbar code implementation

WeChat applet Example: Implement the effect of the navigation bar moving with the top tab switching and sliding switching (code)

The above is the detailed content of WeChat applet allows you to limit the number of items you can purchase during shopping (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template