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.

473 lines
14 KiB
JavaScript

const app = getApp();
const util = require("../../utils/util.js")
const card = require('../../utils/card.js');
Page({
data: {
showUpWindow: false
},
onLoad: function(options) {
util.setNavTitle4Color("卡券中心", "#FFF9EB");
this.cy_couponGrounp();
this.cy_couponPointGrounp();
this.judgeUpWindown();
this.hy_getProductByType();
this.setData({color:app.globalData.color})
},
cy_couponPointGrounp: function() {
var that = this;
var list = [];
var len = 0;
card.couponCenter("", 1, function(json) {
var data = json.data;
if (data.status == 1) {
if (data.list.length > 0) {
var memberReceiveCoupons = data.memberReceiveCoupons;
var memberDayReceiveCoupons = data.memberDayReceiveCoupons;
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;
}
}
// else {
// continue;
// }
}
var dayPersonLimitNum = item.dayPersonLimitNum;
if (memberDayReceiveCoupons[item.id]) {
var num = memberDayReceiveCoupons[item.id] ? memberDayReceiveCoupons[item.id] : 0;
if (parseFloat(num) >= parseFloat(dayPersonLimitNum)) {
continue;
}
}
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;
} else if (item.cardType == "GIFT") {
item.unitName = "兑";
item.amount = "换券";
item.size = "34rpx";
item.height = "60rpx;";
}
if (item.coverLogo){
item.logoUrl = item.coverLogo
}else{
item.logoUrl ="http://pos.juweiyun.cn/373001/file/wechatApp%E5%88%B8%E5%8C%85%402x.png"
}
if (item.status == 0) {
item.bgImage = "../../images/icon-coupon-unimage.png";
item.useStatus = "条件\不足";
} else if (item.status == 1) {
item.bgImage = "http://pos.juweiyun.cn/373001/file/wechatAppnewCoupon.png";
item.useStatus = "立即\n领取";
}
item.color = app.globalData.color
item.condition = "满" + item.leastCost + "可用";
item.effective = item.startDate + " 至 " + item.endDate;
item.shopType = 0;
list.push(item);
if (list.length == 4) {
break;
}
}
that.setData({
listPackage: list
})
} else {
that.setData({
listPackage: data.list,
})
}
} else {
wx.showToast({
title: data.errMessage,
icon: "none"
})
}
}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
hy_getProductByType: function() {
var that = this;
card.pointAllTypeProduct( function(success) {
var result = success.data;
if (result.status == 1) {
var list = result.list;
var pointProduct=[];
for (var i = 0; i <4; i++) {
if (list[i]) {
list[i].shopType = (parseInt(0) + 1);
list[i].logoUrl=list[i].imageUrl
pointProduct.push(list[i]);
}
}
that.setData({
vipProduct: pointProduct
});
}
}, function(error) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
cy_couponGrounp: function() {
var that = this;
//2 代表免费领取
card.couponCenter("", 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 = [];
var flag = 0;
for (var item of data.list) {
if (flag >= 2) {
break;
}
if (memberReceiveCoupons[item.id]) {
var num = memberReceiveCoupons[item.id] ? memberReceiveCoupons[item.id] : 0;
if (item.personLimitNum != 0) {
if (parseFloat(num) >= parseFloat(item.personLimitNum)) {
continue;
}
} else {
continue;
}
}
var dayPersonLimitNum = item.dayPersonLimitNum;
console.error("dayPersonLimitNum", dayPersonLimitNum," memberDayReceiveCoupons[item.id] ",memberDayReceiveCoupons[item.id])
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
}
}
item.bgImage = "http://pos.juweiyun.cn/373001/file/wechatAppnewCoupon.png";
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;
} else if (item.cardType == "GIFT") {
item.unitName = "兑";
item.amount = "换券";
item.size = "34rpx";
item.height = "60rpx;";
}
if (item.status == 0) {
item.useStatus = "条件不足";
item.type=2;
} else if (item.status == 1) {
item.useStatus = "立即领取";
item.type=1;
}
item.color = app.globalData.color
item.condition = "满" + item.leastCost + "可用";
item.effective = item.startDate + " 至 " + item.endDate;
list.push(item);
flag++;
}
that.setData({
list: list
})
} else {
that.setData({
list: data.list,
})
}
} else {
wx.showToast({
title: data.errMessage,
icon: "none"
})
}
}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
receive: function(e) {
var status = e.currentTarget.dataset.status;
if (status==0){
util.showWaring("条件不足!")
return ;
}
var schemeId = e.currentTarget.dataset.id;
var formId = e.detail.formId;
if (schemeId) {
var formId = e.detail.formId;
wx.showLoading({
title: '领取中',
})
var that = this;
card.exchangeCouponScheme(schemeId, function(success) {
var result = success.data;
wx.hideLoading();
if (result.status == 1) {
wx.showToast({
title: "领取成功",
icon: "none",
duration: 2000
})
that.cy_couponGrounp();
var codes = result.data.codes;
card.sendTemPlate("receiveCoupon", formId, codes, function(success) {},
function(error) {
});
} else {
wx.showToast({
title: result.errMessage,
icon: "none",
duration: 3000
})
}
}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
} else {
util.showWaring("数据参数异常")
}
},
goto: function(e) {
wx.navigateTo({
url: e.currentTarget.dataset.url,
})
},
goto_detail: function(e) {
var shopType = e.currentTarget.dataset.shoptype;
var data = {};
data.shopType = shopType;
if (shopType == 0) {
var id = e.currentTarget.dataset.id;
var list = this.data.listPackage;
data.id = id;
for (var item of list) {
if (item.id) {
if (item.id == id) {
data.couponDetail = item;
}
}
}
} else if (shopType == 1 || shopType == 2) {
var productid = e.currentTarget.dataset.productid;
var schemeid = e.currentTarget.dataset.schemeid;
data.productid = productid;
data.schemeid = schemeid;
var list = this.data.vipProduct;
for (var item of list) {
if (item.productId) {
if (item.productId == productid) {
data.couponDetail = item;
}
}
}
if (data.shopType == 2) {
data.shopType = 1;
}
}
console.error("data",data)
app.globalData.productDetailLogUrl = data.couponDetail.logoUrl;
//怕图片地址太长页面传递参数长度超过限制解析报错
data.couponDetail.logoUrl="";
wx.navigateTo({
url: "productDetail?data=" + JSON.stringify(data),
})
},
//关闭弹窗
closeUpWindows: function() {
this.setData({
showUpWindow: false
})
card.closeUpWindow(this.data.schemeId, function(success) {}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
judgeUpWindown: function() {
var that = this;
card.judgeUpWindown(function(success) {
var result = success.data;
if (result.code != 1) {
if (result.data.status == 1) {
if (result.data.schemeId) {
that.setData({
schemeId: result.data.schemeId
})
}
var upWindowList = [];
var items = {};
for (var item of result.data.list) {
items.title = item.title;
items.id = item.id;
items.logoUrl = "http://imgv1.jwsaas.com/" + item.logoUrl;
if (item.quantity) {
items.quantity = item.quantity
} else {
items.quantity = 0
}
if (item.dateType == 0) {
var startTime = "";
var endTime = "";
if (item.beginTimestamp) {
startTime = util.formatTimeV(new Date(parseInt(item.beginTimestamp)), "yyyy-MM-dd");
}
if (item.endTimestamp) {
endTime = util.formatTimeV(new Date(parseInt(item.endTimestamp)), "yyyy-MM-dd");
}
items.time = startTime + " 至 " + endTime;
} else if (item.dateType == 1) {
if (item.fixedBeginTerm || item.fixedBeginTerm == 0) {
var pre = "";
if (item.fixedBeginTerm == 0) {
pre = "立即生效";
} else {
pre = item.fixedBeginTerm + "天后生效";
}
var sup = "";
if (item.fixedTerm) {
sup = " 有效期" + item.fixedTerm + "天";
}
items.time = pre + sup;
}
}
items.cardTypeCn = item.cardType == "CASH" ? "代金券" : item.cardType == "DISCOUNT" ? "折扣券" : item.cardType == "GIFT" ? "兑换券" : item.cardType == "PRODUCT" ? "单品券" : "";
var content = "";
if (items.cardTypeCn == "兑换券") {
if (item.subTitle) {
content = item.subTitle
}
} else if (items.cardTypeCn == "代金券") {
var leastCost = 0;
var reduceCost = 0;
if (item.leastCost) leastCost = item.leastCost
if (item.reduceCost) reduceCost = item.reduceCost
content = "满" + leastCost + "元 减 " + reduceCost + " 元";
} else if (items.cardTypeCn == "折扣券") {
if (item.discount) {
content = item.discount + "折";
}
} else if (items.cardTypeCn == "单品券") {
if (item.grantType == '1') content = item.discount + "折"
if (item.grantType == '2') content = "满" + item.leastCost + "元 减" + item.reduceCost + "元"
}
items.content = content;
upWindowList.push(items)
items = {};
}
var showUpWindow = false;
if (upWindowList.length > 0) {
showUpWindow = true;
}
that.setData({
upWindowList: upWindowList,
showUpWindow: showUpWindow
})
}
}
}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
receiveUpWindow: function() {
var that = this;
that.setData({
receive: false
})
var cardNo = wx.getStorageSync("memberInfo").cardNo;
var schemeId = that.data.schemeId;
card.receive(schemeId, function(success) {
var result = success.data;
that.setData({
receive: true
})
if (result.status == 1) {
util.showSuccessMsg("领取成功快去使用吧", "none")
} else {
util.showWaring("领取失败!", "none")
}
that.setData({
showUpWindow: false
})
}, function fail(err) {
console.log(err);
wx.showToast({
title: "网络连接不稳定, 请重试",
icon: "none"
})
})
},
onReady: function() {
},
onShow: function() {
},
onShareAppMessage: function() {
return {
title: '卡券中心',
path: '/pages/tabbar/launch'
}
}
})