溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

微信小程序如何實(shí)現(xiàn)購(gòu)物時(shí)限購(gòu)商品的數(shù)量

發(fā)布時(shí)間:2021-01-28 13:39:19 來源:億速云 閱讀:212 作者:小新 欄目:移動(dòng)開發(fā)

這篇文章主要介紹微信小程序如何實(shí)現(xiàn)購(gòu)物時(shí)限購(gòu)商品的數(shù)量,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

展示效果如下:

微信小程序如何實(shí)現(xiàn)購(gòu)物時(shí)限購(gòu)商品的數(shù)量

兩個(gè)底部用的是一個(gè)彈框,利用submit_type的類型不一樣來進(jìn)行區(qū)分哪個(gè)是單獨(dú)購(gòu)買哪個(gè)是包郵開團(tuán)

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就是判斷是單獨(dú)還是開團(tuán)購(gòu)買

js代碼如下:

// 增加數(shù)量
  addCount(e) {
    // 購(gòu)買類型,單獨(dú)購(gòu)買或拼團(tuán)購(gòu)買
    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) {  // 拼團(tuán)購(gòu)買
      var limited_num = this.data.collage.limited_num;
      if (goods_count > limited_num) {
        this.showTip('超出限購(gòu)');
        return;
      }
    }
    this.setData({
      goods_count: goods_count
    });
  },
// 改變數(shù)量(input內(nèi)的值)
  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) {  // 單獨(dú)購(gòu)買
        this.showTip('庫(kù)存不足');
        return;
      }
    } else if (submit_type == 2) {  // 拼團(tuán)購(gòu)買
      var limited_num = this.data.collage.limited_num;
      if (goods_count > limited_num) {
        this.showTip('超出限購(gòu)');
        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
    });
  },

以上是“微信小程序如何實(shí)現(xiàn)購(gòu)物時(shí)限購(gòu)商品的數(shù)量”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI