...
|
...
|
@@ -31,9 +31,13 @@ Page({ |
|
|
skup: '',
|
|
|
coupons: [],
|
|
|
selectCouponCode: '',
|
|
|
selectCouponAmount: '',
|
|
|
selectCouponAmount: 0,
|
|
|
selectingCoupon: false,
|
|
|
isManualSelect: false,
|
|
|
selectPromotionCode: 0,
|
|
|
selectPromotionAmount: 0,
|
|
|
selectingPromotion: false,
|
|
|
isManualSelectPro: false,
|
|
|
promotionid: '',
|
|
|
user_activity_id: '' // 有值代表砍价
|
|
|
},
|
...
|
...
|
@@ -60,10 +64,10 @@ Page({ |
|
|
|
|
|
//选中优惠卷后,切到后台,再切回前台页面,不在请求数据
|
|
|
if (!this.data.selectCouponCode) {
|
|
|
await this.fetchData(this.data.isStore);
|
|
|
if (!this.data.isStore && !this.data.hasAddress) {
|
|
|
await this.fetchAddress()
|
|
|
}
|
|
|
await this.fetchData(this.data.isStore);
|
|
|
}
|
|
|
|
|
|
},
|
...
|
...
|
@@ -73,10 +77,41 @@ Page({ |
|
|
selectingCoupon: true
|
|
|
});
|
|
|
},
|
|
|
|
|
|
async confirmSelectCoupon({detail}) {
|
|
|
showSelectPromotion: function () {
|
|
|
this.setData({
|
|
|
selectingPromotion: true
|
|
|
});
|
|
|
},
|
|
|
async confirmSelectPromotion({detail}) {
|
|
|
let code = detail.code;
|
|
|
let amount = detail.amount || 0;
|
|
|
let promotionsList = this.data.promotionList;
|
|
|
if (promotionsList) {
|
|
|
promotionsList.forEach((item, index) => {
|
|
|
if (code ===item.promotionId) {
|
|
|
item.isChosen = true;
|
|
|
item.selected = 'Y'
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
this.setData({
|
|
|
promotionsList,
|
|
|
selectingPromotion: false,
|
|
|
selectPromotionCode: code,
|
|
|
selectPromotionAmount: amount,
|
|
|
isManualSelectPro: true,
|
|
|
// 重置优惠券
|
|
|
selectCouponAmount: 0,
|
|
|
selectCouponCode: '',
|
|
|
isManualSelect: false
|
|
|
});
|
|
|
this.orderCompute({
|
|
|
promotion_id: code
|
|
|
})
|
|
|
},
|
|
|
confirmSelectCoupon({detail}) {
|
|
|
let code = detail.code;
|
|
|
let amount = detail.amount || '';
|
|
|
let amount = detail.amount || 0;
|
|
|
let couponsList = this.data.couponList;
|
|
|
if (couponsList){
|
|
|
couponsList.forEach((item, index) => {
|
...
|
...
|
@@ -92,16 +127,20 @@ Page({ |
|
|
selectCouponAmount: amount,
|
|
|
selectCouponCode: code,
|
|
|
selectingCoupon: false,
|
|
|
isManualSelect: true
|
|
|
isManualSelect: true,
|
|
|
// 重置促销
|
|
|
selectPromotionCode: 0,
|
|
|
selectPromotionAmount: 0,
|
|
|
isManualSelectPro: false
|
|
|
});
|
|
|
|
|
|
this.orderCompute({code})
|
|
|
},
|
|
|
async orderCompute({
|
|
|
code = '',
|
|
|
promotion_id = ''
|
|
|
}) {
|
|
|
// 区分线上线下
|
|
|
let info;
|
|
|
//如果选择了非运费券,促销不选择
|
|
|
let promotion_id = '';
|
|
|
if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds) {
|
|
|
promotion_id = this.data.promotionTips.promotionIds;
|
|
|
}
|
|
|
try {
|
|
|
if (this.data.isStore) {
|
|
|
info = await api.orderOfflineCompute({
|
...
|
...
|
@@ -111,10 +150,12 @@ Page({ |
|
|
app_version: '1'
|
|
|
}, () => wx.hideLoading());
|
|
|
} else {
|
|
|
let addressId = this.data.hasAddress && this.data.address && this.data.address.address_id
|
|
|
const params = {
|
|
|
skup: this.data.skup,
|
|
|
coupon_code: code,
|
|
|
promotionid: promotion_id
|
|
|
promotionId: promotion_id,
|
|
|
addressId
|
|
|
};
|
|
|
|
|
|
if (this.data.user_activity_id) {
|
...
|
...
|
@@ -126,20 +167,23 @@ Page({ |
|
|
|
|
|
info = await api.orderCompute(params, () => wx.hideLoading());
|
|
|
}
|
|
|
} catch(e) {}
|
|
|
} catch (e) {}
|
|
|
|
|
|
this.setData({
|
|
|
amount: info.amount,
|
|
|
promotionFormulaList: info.promotionFormulaList
|
|
|
});
|
|
|
},
|
|
|
|
|
|
cancelSelectCoupon: function () {
|
|
|
this.setData({
|
|
|
selectingCoupon: false
|
|
|
});
|
|
|
},
|
|
|
|
|
|
cancelSelectPromotion: function () {
|
|
|
this.setData({
|
|
|
selectingPromotion: false
|
|
|
});
|
|
|
},
|
|
|
async fetchData(isStore) {
|
|
|
wx.showLoading({
|
|
|
title: '',
|
...
|
...
|
@@ -168,6 +212,8 @@ Page({ |
|
|
})
|
|
|
data.promotionFormulaList.splice(index,1)
|
|
|
} else {
|
|
|
let addressId = this.data.hasAddress && this.data.address && this.data.address.address_id
|
|
|
params.addressId = addressId
|
|
|
try {
|
|
|
data = await api.createPaymentInfo(params, () => wx.hideLoading())
|
|
|
} catch (e) {
|
...
|
...
|
@@ -184,15 +230,12 @@ Page({ |
|
|
// await api.orderSelectCoupon(this.data.skup, () => wx.hideLoading()).then(data => {
|
|
|
// this.setData(coupons)
|
|
|
// });
|
|
|
let that = this;
|
|
|
|
|
|
if (data && data.couponList && data.couponList.length > 0){
|
|
|
let coupons = [];
|
|
|
let activityCoupons = [];
|
|
|
let expressCoupons = [];
|
|
|
let couponsAmount = 0;
|
|
|
data.couponList.forEach((item, index) => {
|
|
|
let selected = item.selected;
|
|
|
let couponsType = item.coupon_type;
|
|
|
if (selected === 'Y'){
|
|
|
item.isChosen = true;
|
|
|
couponsAmount += parseFloat(item.coupon_value_str);
|
...
|
...
|
@@ -200,18 +243,28 @@ Page({ |
|
|
}else {
|
|
|
item.isChosen = false;
|
|
|
}
|
|
|
if(couponsType === 100) {
|
|
|
activityCoupons.push(item)
|
|
|
} else if(couponsType === 110) {
|
|
|
expressCoupons.push(item)
|
|
|
}
|
|
|
});
|
|
|
data.activityCoupons = activityCoupons;
|
|
|
data.expressCoupons = expressCoupons;
|
|
|
|
|
|
data.selectCouponAmount = couponsAmount;
|
|
|
data.selectCouponCode = coupons.join(',');
|
|
|
}
|
|
|
if (data && data.promotionList && data.promotionList.length > 0) {
|
|
|
let promotions = 0;
|
|
|
let promotionsAmount = 0;
|
|
|
data.promotionList.forEach((item, index) => {
|
|
|
let selected = item.selected;
|
|
|
if (selected === 'Y') {
|
|
|
item.isChosen = true;
|
|
|
promotionsAmount = parseFloat(item.cutAmount);
|
|
|
promotions = item.promotionId;
|
|
|
} else {
|
|
|
item.isChosen = false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
data.selectPromotionAmount = promotionsAmount;
|
|
|
data.selectPromotionCode = promotions;
|
|
|
}
|
|
|
if (data.good && data.good.goodImg) {
|
|
|
data.good.goodImg = getImgUrl(data.good.goodImg, 270, 270)
|
|
|
}
|
...
|
...
|
@@ -257,11 +310,8 @@ Page({ |
|
|
if (!this.data.agreeProtocol) return;
|
|
|
let data;
|
|
|
try {
|
|
|
let promotionId = '';
|
|
|
if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds){
|
|
|
promotionId = this.data.promotionTips.promotionIds;
|
|
|
}
|
|
|
|
|
|
let promotionId = this.data.selectPromotionCode || '';
|
|
|
let couponCode = this.data.selectCouponCode || '';
|
|
|
if (this.data.isStore) {
|
|
|
this.check = this.selectComponent("#check");
|
|
|
let checkRes = await this.check.init();
|
...
|
...
|
@@ -269,15 +319,12 @@ Page({ |
|
|
let param = checkRes.data;
|
|
|
param.skup = this.data.skup;
|
|
|
param.api_version = '1';
|
|
|
param.coupon_code = this.data.selectCouponCode || '';
|
|
|
param.coupon_code = couponCode;
|
|
|
param.promotionId = promotionId;
|
|
|
// wx.showLoading({
|
|
|
// title: '',
|
|
|
// })
|
|
|
|
|
|
data = await api.storeBuyerSubmit(param, () => {
|
|
|
wx.hideLoading()
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
if (!this.data.hasAddress) {
|
|
|
wx.showToast({
|
...
|
...
|
@@ -288,11 +335,8 @@ Page({ |
|
|
|
|
|
let addressId = this.data.hasAddress && this.data.address && this.data.address.address_id
|
|
|
let skup = this.data.skup
|
|
|
let channelNo = '';
|
|
|
let couponCode = this.data.selectCouponCode || '';
|
|
|
let channelNo = '';
|
|
|
let extra = null;
|
|
|
|
|
|
|
|
|
if (this.data.user_activity_id) {
|
|
|
extra = {
|
|
|
user_activity_id: this.data.user_activity_id,
|
...
|
...
|
@@ -300,9 +344,6 @@ Page({ |
|
|
};
|
|
|
}
|
|
|
|
|
|
// wx.showLoading({
|
|
|
// title: '',
|
|
|
// })
|
|
|
data = await api.buyerSubmit({ skup, channelNo, addressId, couponCode, promotionId, extra}, () => wx.hideLoading());
|
|
|
}
|
|
|
if (data && data.orderCode) {
|
...
|
...
|
|