Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
修复购物车增加商品时的数量限制
Browse files Browse the repository at this point in the history
修改商品数量上限为当前库存
  • Loading branch information
钦点大都督 authored and 钦点大都督 committed May 26, 2018
1 parent 6cd3213 commit 115ca0f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Binary file modified pages/.DS_Store
Binary file not shown.
27 changes: 22 additions & 5 deletions pages/shop-cart/index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,30 @@ Page({
this.setGoodsList(this.getSaveHide(), this.totalPrice(), !currentAllSelect, this.noSelect(), list);
},
jiaBtnTap: function (e) {
var that = this
var index = e.currentTarget.dataset.index;
var list = this.data.goodsList.list;
var list = that.data.goodsList.list;
if (index !== "" && index != null) {
if (list[parseInt(index)].number < 10) {
list[parseInt(index)].number++;
this.setGoodsList(this.getSaveHide(), this.totalPrice(), this.allSelect(), this.noSelect(), list);
}
// 添加判断当前商品购买数量是否超过当前商品可购买库存
var carShopBean = list[parseInt(index)];
var carShopBeanStores = 0;
wx.request({
url: 'https://api.it120.cc/' + app.globalData.subDomain + '/shop/goods/detail',
data: {
id: carShopBean.goodsId
},
success: function (res) {
carShopBeanStores = res.data.data.basicInfo.stores;
console.log(' currnet good id and stores is :',carShopBean.goodsId, carShopBeanStores)
if (list[parseInt(index)].number < carShopBeanStores) {
list[parseInt(index)].number++;
that.setGoodsList(that.getSaveHide(), that.totalPrice(), that.allSelect(), that.noSelect(), list);
}
that.setData({
curTouchGoodStore: carShopBeanStores
})
}
})
}
},
jianBtnTap: function (e) {
Expand Down
Binary file added templates/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion templates/template-cart/template-cart.wxml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<view class="buy-num">
<view class="jian-btn {{item.number==1? 'disabled' : ''}}" catchtap="jianBtnTap" data-index="{{index}}">-</view>
<input type="number" value="{{item.number}}" disabled/>
<view class="jia-btn {{item.number==10? 'disabled' : ''}}" catchtap="jiaBtnTap" data-index="{{index}}">+</view>
<view class="jia-btn {{item.number==curTouchGoodStore? 'disabled' : ''}}" catchtap="jiaBtnTap" data-index="{{index}}">+</view>
</view>
</view>
</view>
Expand Down

0 comments on commit 115ca0f

Please sign in to comment.