You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
261 lines
7.2 KiB
JavaScript
261 lines
7.2 KiB
JavaScript
9 months ago
|
const app = getApp();
|
||
|
const card = require('../../utils/card.js');
|
||
|
const util = require('../../utils/util.js');
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
couponStatus: [{
|
||
|
status: 1,
|
||
|
title: "代金券",
|
||
|
select: true,
|
||
|
value: "CASH"
|
||
|
}, {
|
||
|
status: 2,
|
||
|
title: "兑换券",
|
||
|
select: false,
|
||
|
value: "GIFT"
|
||
|
}, {
|
||
|
status: 3,
|
||
|
title: "折扣券",
|
||
|
select: false,
|
||
|
value: "DISCOUNT"
|
||
|
}]
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function(options) {
|
||
|
this.cy_couponGrounp();
|
||
|
this.setData({color:app.globalData.color})
|
||
|
},
|
||
|
cy_couponGrounp: function() {
|
||
|
var that = this;
|
||
|
var couponType = this.cy_getDefaultTitleValue();
|
||
|
//2 代表免费领取
|
||
|
card.couponCenter(couponType, 2, function(json) {
|
||
|
console.log(json)
|
||
|
var data = json.data;
|
||
|
if (data.status == 1) {
|
||
|
var list = [];
|
||
|
if (data.list.length > 0) {
|
||
|
var memberReceiveCoupons = data.memberReceiveCoupons;
|
||
|
var memberDayReceiveCoupons = data.memberDayReceiveCoupons;
|
||
|
var list = [];
|
||
|
for (var item of data.list) {
|
||
|
if (memberReceiveCoupons[item.id]) {
|
||
|
var num = memberReceiveCoupons[item.id] ? memberReceiveCoupons[item.id] : 0;
|
||
|
if (item.personLimitNum != 0) {
|
||
|
if (parseFloat(num) >= parseFloat(item.personLimitNum)) {
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
var dayPersonLimitNum = item.dayPersonLimitNum;
|
||
|
if (memberDayReceiveCoupons[item.id]) {
|
||
|
var num = memberDayReceiveCoupons[item.id] ? memberDayReceiveCoupons[item.id] : 0;
|
||
|
if (parseFloat(num) >= parseFloat(dayPersonLimitNum)) {
|
||
|
continue;
|
||
|
}else{
|
||
|
if(item.personLimitNum!=0){
|
||
|
item.syNum=item.personLimitNum-num
|
||
|
}
|
||
|
}
|
||
|
}else{
|
||
|
if(item.personLimitNum!=0){
|
||
|
item.syNum=item.personLimitNum-num
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (item.cardType == "DISCOUNT") {
|
||
|
item.unitName = "折";
|
||
|
item.amount = item.discount;
|
||
|
item.size = "60rpx";
|
||
|
item.height = "90rpx;";
|
||
|
} else if (item.cardType == "CASH") {
|
||
|
item.unitName = "¥";
|
||
|
item.size = "60rpx";
|
||
|
item.height = "90rpx;";
|
||
|
item.amount = item.reduceCost;
|
||
|
// item.amount = app.utils.getZero(parseFloat(item.reduceCost) / 100);
|
||
|
} else if (item.cardType == "GIFT") {
|
||
|
item.unitName = "兑";
|
||
|
item.amount = "换券";
|
||
|
item.size = "34rpx";
|
||
|
item.height = "60rpx;";
|
||
|
}
|
||
|
//判断是否兑换券显示图片
|
||
|
if(that.data.couponStatus[2].select){
|
||
|
item.showImage=true;
|
||
|
}else{
|
||
|
item.showImage=false;
|
||
|
}
|
||
|
item.color = "#3cc271";
|
||
|
|
||
|
// item.condition = "满" + app.utils.getOne(parseFloat(item.leastCost) / 100) + "可用";
|
||
|
item.condition = "满" + item.leastCost + "可用";
|
||
|
item.effective = item.startDate + " 至 " + item.endDate;
|
||
|
if (item.status == 0) {
|
||
|
item.bgImage ="http://pos.juweiyun.cn/373001/file/wechatAppnewCoupon.png";
|
||
|
item.useStatus = "条件不足";
|
||
|
item.type=2;
|
||
|
} else if (item.status == 1) {
|
||
|
item.bgImage = "http://pos.juweiyun.cn/373001/file/wechatAppnewCoupon.png";
|
||
|
item.useStatus = "立即领取";
|
||
|
item.type=1;
|
||
|
}
|
||
|
list.push(item);
|
||
|
}
|
||
|
if (list.length <= 0) {
|
||
|
var couponName = that.cy_getDefaultTitle();
|
||
|
wx.showToast({
|
||
|
title: "暂无可用" + couponName,
|
||
|
icon: "none"
|
||
|
})
|
||
|
}
|
||
|
that.setData({
|
||
|
list: list
|
||
|
})
|
||
|
|
||
|
} else {
|
||
|
that.setData({
|
||
|
list: data.list,
|
||
|
})
|
||
|
wx.showToast({
|
||
|
title: "暂无优惠券",
|
||
|
icon: "none"
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
wx.showToast({
|
||
|
title: data.errMessage,
|
||
|
icon: "none"
|
||
|
})
|
||
|
}
|
||
|
}, function fail(err) {
|
||
|
console.log(err);
|
||
|
wx.showToast({
|
||
|
title: "网络连接不稳定, 请重试",
|
||
|
icon: "none"
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
cy_getDefaultTitleValue: function() {
|
||
|
var list = this.data.couponStatus;
|
||
|
for (var item of list) {
|
||
|
if (item.select) {
|
||
|
return item.value;
|
||
|
}
|
||
|
}
|
||
|
return list[0].value;
|
||
|
},
|
||
|
cy_getDefaultTitle: function() {
|
||
|
var list = this.data.couponStatus;
|
||
|
for (var item of list) {
|
||
|
if (item.select) {
|
||
|
return item.title;
|
||
|
}
|
||
|
}
|
||
|
return list[0].title;
|
||
|
},
|
||
|
/**
|
||
|
* 选择优惠券类型
|
||
|
*/
|
||
|
cy_selectTypeCoupon: function(e) {
|
||
|
var status = e.currentTarget.dataset.status;
|
||
|
for (var item of this.data.couponStatus) {
|
||
|
item.select = false;
|
||
|
if (item.status == status) {
|
||
|
item.select = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
this.cy_couponGrounp();
|
||
|
this.setData({
|
||
|
couponStatus: this.data.couponStatus
|
||
|
});
|
||
|
},
|
||
|
receive: function(e) {
|
||
|
var status = e.currentTarget.dataset.status;
|
||
|
console.error(e,"...")
|
||
|
if (status == 0) {
|
||
|
util.showWaring("条件不足!")
|
||
|
return;
|
||
|
}
|
||
|
var schemeId = e.currentTarget.dataset.id;
|
||
|
var formId = e.detail.formId;
|
||
|
wx.showLoading({
|
||
|
title: '兑换中',
|
||
|
})
|
||
|
var that = this;
|
||
|
card.exchangeCouponScheme(schemeId, function(success) {
|
||
|
var result = success.data;
|
||
|
if (result.status == 1) {
|
||
|
wx.showToast({
|
||
|
title: "兑换成功",
|
||
|
icon: "none",
|
||
|
duration: 2000
|
||
|
})
|
||
|
that.cy_couponGrounp();
|
||
|
var codes = result.data.codes;
|
||
|
wx.requestSubscribeMessage({
|
||
|
tmplIds: ['EtZx0oL7j8de4GvAKdvVvAp4r54FmkUgljBV6odEwP8','pGnicqZClpvzbrvHhkK5TzF486QC-TbxG4dOiMxQinA','Ztg4uD0POZyKhg2onTOUaJRGQou1dpOqxB62yIdhkds'],
|
||
|
success:function (params) {
|
||
|
console.error(" success ",params)
|
||
|
card.sendTemPlate("receiveCoupon", formId, codes, function(success) {},
|
||
|
function(error) {
|
||
|
|
||
|
});
|
||
|
},
|
||
|
fail:function (params) {
|
||
|
console.error(" error ",params)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
} else {
|
||
|
wx.showToast({
|
||
|
title: result.errMessage,
|
||
|
icon: "none",
|
||
|
duration: 3000
|
||
|
})
|
||
|
}
|
||
|
wx.hideLoading();
|
||
|
}, function fail(err) {
|
||
|
console.log(err);
|
||
|
wx.showToast({
|
||
|
title: "网络连接不稳定, 请重试",
|
||
|
icon: "none"
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
/**测试formid
|
||
|
* e207fb10f83e430c821eea3301f28e5d ----
|
||
|
* 4c0829e9ff5747d589711586f1aa7776
|
||
|
* e7df56ef99254283b4c9fe6268f03a9c
|
||
|
* d9da7d9312cc414189e60acd14625150
|
||
|
* 3c33ffc4783f4a3991aec0197b707770
|
||
|
*/
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function() {
|
||
|
|
||
|
}
|
||
|
})
|