成都创新互联网站制作重庆分公司

微信小程序如何实现购物时限购商品的数量

这篇文章主要介绍微信小程序如何实现购物时限购商品的数量,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

沙坪坝网站建设公司创新互联建站,沙坪坝网站设计制作,有大型网站制作公司丰富经验。已为沙坪坝1000+提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的沙坪坝做网站的公司定做!

展示效果如下:

微信小程序如何实现购物时限购商品的数量

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

wxml代码如下:

 
      
          
             
                
                     -
                
                1}}" class="Decrease">
                     -
                
             
              
           
                
                   +
                                   
          
         
      
 

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
    });
  },

以上是“微信小程序如何实现购物时限购商品的数量”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


本文题目:微信小程序如何实现购物时限购商品的数量
本文链接:http://cxhlcq.com/article/gddshc.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部