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

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

展示效果如下:

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

wxml代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<view class=”num-box”>

<view class=系统开发mhkj33“weui-media-box__bd”>

<view class=”promotion-sku clear”>

<view class=”Spinner”>

<a wx:if=”{{goods_count系统开发mhkj33==1}}” class=”DisDe”>

<i bindtap=”minusCount” data-index=”{{index}}” class=”DisDe”>-</i>

</a>

<a wx:if=系统开发mhkj33“{{goods_count>1}}” class=”Decrease”>

<i bindtap=”minusCount” data-index=”{{index}}” class=”DisDe”>-<系统开发mhkj33/i>

</a>

<view>

<input class=”Amount” bindinput=”changeCount” type=&#39;number&#39; value=”{{goods_coun系统开发mhkj33t}}” autocomplete=”off” maxlength=”3″  data-submit_type=”{{submit_type}}” />

</view>

<a class=”Increas系统开发mhkj33e”>

<i bindtap=”addCount” data-index=”{{index}}” data-submit_type=”{{submit_type}}”>+</i>

</a>                  

</view>

<系统开发mhkj33/view>

</view>

</view>

登录后复制

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

js代码如下:

1

2

3

4

5

6

7

8系统开发mhkj33

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

// 增加数量

addCount(e) {

/系统开发mhkj33/ 购买类型,单独购买或拼团购买

let submit_type = e.target.dataset.submit_type;

var goods_count = this.data.goods_cou系统开发mhkj33nt;

goods_count = parseInt(goods_count) + 1;

//debugger

if (submit_type == 2) {  // 拼团购买

var limited_num系统开发mhkj33 = this.data.collage.limited_num;

if (goods_count > limited_num) {

this.showTip(&#39;超出限购&#39;);

return系统开发mhkj33;

}

}

this.setData({

goods_count: goods_count

});

},

// 改变数量(input内的值)

changeCount(e) {

var goods_count = e.d系统开发mhkj33etail.value;

let submit_type = e.target.dataset.submit_type;

if (submit_type == 1) {

var sys_num = this系统开发mhkj33.data.goods_num;

if (goods_count > sys_num) {  // 单独购买

this.showTip(&#39;库存不足&#39;);

return;

}

} else if 系统开发mhkj33(submit_type == 2) {  // 拼团购买

var limited_num = this.data.collage.limited_num;

if (goods_count > limit系统开发mhkj33ed_num) {

this.showTip(&#39;超出限购&#39;);

return;

}

}

if (!(/^[\d]+\.?\d*$/.test(goods_count))) {

goods_coun系统开发mhkj33t = goods_count.replace(/\D/g, &#39;&#39;);

return goods_count ? goods_count : 1;

}

if (goods_count < 1系统开发mhkj33) {

return 1;

}

this.setData({

goods_count: goods_count

});

},

登录后复制

 相关推荐:

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

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

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

© 版权声明
THE END
喜欢就支持一下吧
点赞873 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容