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.

182 lines
5.0 KiB
JavaScript

var app = getApp();
const util = require('../../utils/util.js');
const card = require('../../utils/card.js');
const wxbarcode = require('../../utils/wxbarcode.js');
const mqttMessage = require('../../utils/mqttMessage.js');
var intercode;
Page({
data: {
num: 0,
fontSize: 100,
hiden:false
},
/**
* 订阅优惠券核销主题
*/
subscribeCouponCode: function () {
mqttMessage.mqttSubscribe(4);
mqttMessage.mqttOn(this);
},
onHide: function () {
if (this.data.code) {
mqttMessage.mqttunSubscribe(app.getCouponConsumeCode(this.data.code));
}
clearInterval(intercode);
},
onLoad: function (options) {
wx.setNavigationBarTitle({
title: "优惠券详情",
})
if (options.couponDetail) {
var couponDetail = JSON.parse(options.couponDetail);
this.queryCouponShopNum(couponDetail.couponId);
var time = "有效期:" + util.formatTimeV(new Date(couponDetail.beginTimestamp), "yyyy-MM-dd") + "-" + util.formatTimeV(new Date(couponDetail.endTimestamp), "yyyy-MM-dd");
var timeLimit = couponDetail.timeLimit;
var timeDesc = "周一至周日";
if (timeLimit != "") {
timeDesc = "";
if (timeLimit.indexOf("MONDAY") > -1) {
timeDesc += "、周一"
}
if (timeLimit.indexOf("TUESDAY") > -1) {
timeDesc += "、周二"
}
if (timeLimit.indexOf("WEDNESDAY") > -1) {
timeDesc += "、周三"
}
if (timeLimit.indexOf("THURSDAY") > -1) {
timeDesc += "、周四"
}
if (timeLimit.indexOf("FRIDAY") > -1) {
timeDesc += "、周五"
}
if (timeLimit.indexOf("SATURDAY") > -1) {
timeDesc += "、周六"
}
if (timeLimit.indexOf("SUNDAY") > -1) {
timeDesc += "、周日"
}
timeDesc = timeDesc.substring(1, timeDesc.length);
}
couponDetail.time = time;
couponDetail.timeDesc = timeDesc;
if (couponDetail.cardType == 'CASH') {
couponDetail.prefix = "¥"
couponDetail.context = couponDetail.reduceCost;
} else if (couponDetail.cardType == 'PRODUCT') {
couponDetail.prefix = "商"
this.setData({
fontSize: 45
})
couponDetail.context = couponDetail.title;
} else if (couponDetail.cardType == 'DISCOUNT') {
couponDetail.prefix = "折"
couponDetail.context = couponDetail.discount;
} else if (couponDetail.cardType == 'GIFT') {
couponDetail.prefix = "兑"
this.setData({
fontSize: 45
})
couponDetail.context = couponDetail.title;
} else if (couponDetail.cardType == 'NEWPRODUCT ') {
couponDetail.prefix = "新"
this.setData({
fontSize: 45
})
couponDetail.context = couponDetail.title;
}
if (couponDetail.couponDesc) {
this.setData({
list: couponDetail.couponDesc.split('\n')
})
}
this.setData({
couponDetail: couponDetail
});
} else {
app.showMsg("缺少券详情即将返回上一层", "none");
wx.navigateBack({})
}
},
queryCouponShopNum: function (id) {
var that = this;
wx.getLocation({
type: 'gcj02',
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
card.getCouponApplyShopNum(id, latitude, longitude, function (res) {
var result = res.data;
if (result.status == 1) {
that.setData({
num: result.pageCount
})
} else {
app.showMsg("获取优惠券适用门店失败=>" + result.errorMessage, "none");
}
}, function (res) {
app.showMsg("网络异常哦", "none");
})
}
})
},
onReady: function () {
},
onShow: function () {
this.setData({color:app.globalData.color})
},
lookShop: function (e) {
var couponId = e.currentTarget.dataset.couponid;
wx.navigateTo({
url: 'applyShop?couponId=' + couponId,
})
},
userCoupon: function (e) {
var detail = this.data.couponDetail;
var code = detail.code;
var title = detail.title;
var subTitle = detail.subtitle;
app.globalData.oldCode = code;
wxbarcode.barcode('barcode', code, 680, 200);
wxbarcode.qrcode('qrcode', code, 450, 450);
var that = this;
that.setData({
hiden: true,
code:code
})
var i = 0;
if (intercode)
clearInterval(intercode);
intercode = setInterval(function () {
i = i + 1;
wxbarcode.barcode('barcode', code, 680, 200);
wxbarcode.qrcode('qrcode', code, 450, 450);
if (i == 10) {
clearInterval(intercode);
}
}, 1000)
},
close: function () {
this.setData({
hiden: false
})
clearInterval(intercode);
mqttMessage.mqttunSubscribe(app.getCouponConsumeCode(this.data.code));
},
onUnload: function () {
if (this.data.code) {
mqttMessage.mqttunSubscribe(app.getCouponConsumeCode(this.data.code));
}
clearInterval(intercode);
},
})