Commit d6e9bf9b by 谢中龙

711积分换物库存校验提前

parent f713cd1f
......@@ -46,6 +46,10 @@ wxService.page({
// this.initIntegralCouponList();
//获取会员积分信息
this.getMemberIntegrateInfo();
if (wx.getStorageSync('needReloadExchangeList')) {
wx.removeStorageSync('needReloadExchangeList');
this.initIntegralProductList();
}
},
//刷新积分请求
refreshPointRequest() {
......@@ -109,16 +113,49 @@ wxService.page({
else{
this.data.currentTab = 'goods';
}
let integralGoodsList = data ? data : [];
integralGoodsList.forEach(item => {
item.canExchange = true;
});
this.setData({
integralGoodsList: data? data : [],
currentTab: this.data.currentTab
})
});
this.findExchangeNumByIds(integralGoodsList);
}
}
}).finally(() => {
wx.hideLoading();
})
},
//查询指定积分换物活动兑换数量
findExchangeNumByIds(integralGoodsList) {
//获取ids
let ids = integralGoodsList.map(g => {
return g.id;
});
wxService.post(`/member/pointsRedemptionProductSetting/getExchangeCount`, ids).then(res => {
if(res){
let data = res.data.data ? res.data.data : null;
if (data) {
for (let k in data) {
let id = k, value = data[k];
for (let i = 0; i < integralGoodsList.length; i++) {
if (integralGoodsList[i].id == id) {
integralGoodsList[i].canExchange = integralGoodsList[i].stock > value;
}
}
}
}
}
this.setData({
integralGoodsList: integralGoodsList,
});
});
},
// 积分兑换优惠券列表
initIntegralCouponList() {
wx.showLoading({
......@@ -150,8 +187,15 @@ wxService.page({
},
// 立即兑换物品
exchangeGoods(e) {
const { id, point } = e.currentTarget.dataset;
const { id, point, canexchange} = e.currentTarget.dataset;
const { memberId } = wx.getStorageSync('_baseUserInfo')
if (!canexchange) {
this.setData({
dialogStockEmpty: true
});
return;
}
//检查是不是可以兑换
wx.showLoading({
title: '检查兑换资格中..',
......
......@@ -94,6 +94,7 @@
<view class='coupon-btn-click'
data-id="{{item.id}}"
data-point="{{item.point}}"
data-canexchange="{{item.canExchange}}"
catchtap='exchangeGoods'>立即兑换</view>
<view class='coupon-btn-num'>{{item.point}}积分</view>
</view>
......
......@@ -11,7 +11,8 @@ wxService.page({
*/
data: {
isExchange: false,
dialogUserLimit: false,
dialogUserLimit : false,
dialogStockEmpty : false,
integralMallDetail: {}
},
......@@ -24,10 +25,34 @@ wxService.page({
this.getIntegralCouponDetail(id)
},
//btn回调
onDialogBtnCallBack(e) {
let pages = getCurrentPages();
let index = pages.length - 1;
for (let i = 0; i < pages.length; i++) {
if (pages[i].route.indexOf('IntegralMallGoods/IntegralMallGoods') > -1) {
index = index - i;
break;
}
}
wx.navigateBack({
delta: index
});
},
//立即兑换
exchange() {
const { memberId } = wx.getStorageSync('_baseUserInfo');
const id = this.data.integralMallDetail.id;
if (!this.data.integralMallDetail.canExchange){
this.setData({
dialogStockEmpty : true,
});
return ;
}
//检查是不是可以兑换
wx.showLoading({
title: '检查兑换资格中..',
......@@ -57,12 +82,34 @@ wxService.page({
if (result == 0) {
wx.hideLoading()
data.desc = JSON.parse(data.desc)
data.canExchange = true;
this.setData({
integralMallDetail: data
},() => {
this.findExchangeNumByIds(id);
});
}
}).finally(() => {
wx.hideLoading()
})
},
//查询指定积分换物活动兑换数量
findExchangeNumByIds(id) {
//获取ids
let ids = [id];
wxService.post(`/member/pointsRedemptionProductSetting/getExchangeCount`, ids).then(res => {
if (res){
let data = res.data.data ? res.data.data : null;
if (data) {
let value = data[id];
this.data.integralMallDetail.canExchange = this.data.integralMallDetail.stock > value;
}
}
this.setData({
integralMallDetail: this.data.integralMallDetail
});
});
},
})
\ No newline at end of file
{
"navigationBarTitleText": "积分换物详情",
"usingComponents": {
"dialog-stock-empty": "/component/dialogStockEmpty/dialogStockEmpty",
"dialog-user-limit": "/component/dialogUserLimit/dialogUserLimit"
}
}
\ No newline at end of file
......@@ -27,3 +27,5 @@
<!--goHome-->
<go-home/>
<dialog-user-limit show="{{dialogUserLimit}}"/>
<dialog-stock-empty show="{{dialogStockEmpty}}" bind:btnClick="onDialogBtnCallBack"/>
......@@ -128,6 +128,7 @@ wxService.page({
wx.showToast({
title: '兑换成功',
});
wx.setStorageSync('needReloadExchangeList', true)
setTimeout(() => {
wx.navigateBack({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment