const util = require("../../../utils/util"); const config = require("../../../config/config.js"); const Http = require("../../../utils/HttpBasics"); let app = getApp(); const imgurl = require("../../../utils/imgurl"); const QR = require("../../../utils/memberqrcode.js"); //券详情页面 Page({ data: { code: "", lineUrl: imgurl.line.url, wm01Url: imgurl.wm01.url, wm02Url: imgurl.wm02.url, wm03Url: imgurl.wm03.url, wm04Url: imgurl.wm04.url, teljpgUrl: imgurl.teljpg.url, newUrl: imgurl.new1.url, data: { salePrice: null, price: null, usePrice: null }, createDate: "", expiredTime: "", validStartDate:"", validEndDate:"", updateDate: "", //存储计时器 setInter: "", staticGamedata: {}, showIf: false, }, onUnload:function(){ let that = this; clearInterval(that.data.setInter); }, onHide:function(){ let that = this; clearInterval(that.data.setInter); }, gotogame: function () { let that = this; wx.navigateTo({ url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId, }) }, /** * 跳转到门店列表的详情页面 */ gotoDetail(e) { wx.navigateTo({ url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}` }) }, // 获取游戏 getStaticGame(token) { let _this = this; Http.get({ url: config.api.getGame, data: { triggleAction: 4 // 核销触发 } }).then(res => { if (res.data.id) { _this.setData({ showIf: true }) } _this.setData({ staticGamedata: res.data }) }) .catch(err => { wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, // onShow(options) { // setTimeout(function () { // wx.setScreenBrightness({ // value: 0.7, // }) // }, 200) // }, onLoad: function (options) { let that = this; that.setData({ code: options.quancode, couponorderstatus: options.couponorderstatus }); //获得优惠券的详情 that.data.setInter = setInterval(function () { if ( options.quancode && that.data.couponorderstatus == 0 ) { Http.get({ url: config.api.couponOrderDetail, data: { couponOrderId: options.quancode } }).then(res => { console.log(res); that.setData({ couponorderstatus: res.data.couponOrderStatus, data: res.data }); if (res.data.couponOrderStatus == 1) { /** * 动态改变上一级页面的核销状态 */ that.getStaticGame() var pages = getCurrentPages(); var prevPage = pages[pages.length - 2]; //上一个页面 //直接调用上一个页面的setData()方法,把数据存到上一个页面中去 prevPage.setData({ mystatus: res.data.couponOrderStatus }); } that.setData({ expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"), updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"), createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss") }); if (that.data.data.validStartDate && that.data.data.validEndDate) { that.setData({ validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"), validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss") }) } }) .catch(err => { wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) } }, 2000); /** * 页面需要初始渲染的效果 */ Http.get({ url: config.api.couponOrderDetail, data: { couponOrderId: options.quancode } }).then(res => { that.setData({ couponorderstatus: res.data.couponOrderStatus, data: res.data }); that.setData({ expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"), updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"), createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss") }); if (that.data.data.validStartDate && that.data.data.validEndDate){ that.setData({ validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"), validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss") }) } let url = JSON.stringify({ END:"C", TYPE:"couponorder", ID: options.quancode }) // util.qrcode("qrcode", url, 350, 350); that.createQrCode(url, "qrcode", 350, 350); }) .catch(err => { wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, createQrCode: function (url, canvasId, cavW, cavH) { //调用插件中的draw方法,绘制二维码图片 let that = this; QR.api.draw(url, canvasId, cavW, cavH, function (res) { that.setData({ tempFilePath: res }) }); }, phone: function (e) { let that = this; if (e.currentTarget.dataset.merchantlinkphone) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.merchantlinkphone }); } } });