|  | // let util = require("../../utils/util");
const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
let Http = require("../../utils/HttpBasics");
let config = require("../../config/config.js");
let app = getApp();
const imgurl = require("../../utils/imgurl");
const QR = require("../../utils/memberqrcode.js");
Page({
  data: {
    navigationBarHeight,
    btomLineUrl: imgurl.btomLine.url,
    topLineUrl: imgurl.topLine.url,
    lineUrl: imgurl.line.url,
    wm01Url: imgurl.wm01.url,
    wm02Url: imgurl.wm02.url,
    wm03Url: imgurl.wm03.url,
    wm04Url: imgurl.wm04.url,
    code: "",
    //存储计时器
    setInter: "",
    staticGamedata: {},
    showIf: false,
    curHtml: '',
    contentType: 0,
  },
  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,
    })
  },
  // 获取游戏
  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
        });
      })
  },
  onLoad: function (options) {
    console.log(options)
    console.log(app.globalData.curHtml)
    let that = this;
    let value = JSON.stringify({ END: "C", TYPE: "couponorder", ID: options.quancode})
    that.createQrCode(value, "qrcode", 350, 350);
    that.setData({
      code: options.quancode,
      title: options.title,
      subtitle: options.subtitle,
      remark: options.remark,
      couponorderstatus: options.couponorderstatus,
      validStatus: options.validstatus,
      contentType: options.contentType
    });
    if (options.contentType != undefined && options.contentType==1) {
      this.setData({
        curHtml: app.globalData.curHtml
      })
    }
    /**
     * 如果没有核销
     */
    that.data.setInter = setInterval(function () {
      if (that.data.couponorderstatus == 0) {
        Http.get({
          url: config.api.getStatus,
          data: {
            couponOrderId: options.quancode
          }
        }).then(res => {
          console.log(res);
          that.setData({
            couponorderstatus: res.data.CouponOrderStatus
          });
          if (res.data.CouponOrderStatus == 1) {
            /**
             * 动态改变上一级页面的核销状态
             */
            that.getStaticGame()
            var pages = getCurrentPages();
            var prevPage = pages[pages.length - 2]; //上一个页面
            //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
            prevPage.setData({
              mystatus: res.data.CouponOrderStatus
            });
          }
        })
          .catch(err => {
            wx.showToast({
              title: err.errMsg,
              icon: 'none',
              duration: 2000,
              mask: false
            });
          })
      }
    }, 2000);
    if (that.data.couponorderstatus == 1) {
      /**
       * 如果已经核销
       * 不需要循环
       */
      Http.get({
        url: config.api.getStatus,
        data: {
          couponOrderId: options.quancode
        }
      }).then(res => {
        that.setData({
          couponorderstatus: res.data.CouponOrderStatus
        });
      })
        .catch(err => {
          wx.showToast({
            title: err.errMsg,
            icon: 'none',
            duration: 2000,
            mask: false
          });
        })
    }
    /**
     * couponorderstatus
     * 0 没有核销
     * 1 已经核销成功
     */
  },
  createQrCode: function (url, canvasId, cavW, cavH) {
    //调用插件中的draw方法,绘制二维码图片
    let that = this;
    QR.api.draw(url, canvasId, cavW, cavH, function (res) {
      that.setData({
        tempFilePath: res
      })
    });
  },
  onUnload: function () {
    let that = this;
    clearInterval(that.data.setInter);
  },
  onHide: function () {
    let that = this;
    clearInterval(that.data.setInter);
  },
  // onHide:function(){
  //   console.log(app.globalData.sight)
  //   wx.setScreenBrightness({
  //     value: app.globalData.sight,
  //   })
  // }
});
 |