// pages/TicketDetails/TicketDetails.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    ticketUser: [],//优惠券信息
    ticketStateArr:[],//优惠券使用状态
    codePicUrl:"",//二维码图片地址
    yesCode: false,//二维码图片隐藏
    id:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id)
    this.data.id = options.id;
    if (app.globalData.openId) {
      this.getTicketUser()
      this.getCodeFn()
    } else {
      app.globalData.openidSuccessFuc = this.getTicketUser;
      app.globalData.openidSuccessFuc = this.getCodeFn;
    }

    if (state == 1) {//已注册

    } else if (state == 0) {//未注册
      wx.navigateTo({
        url: '/pages/register/register',
      })
    } else if (state == -1) {
      app.globalData.userInfoBackFn = res => {//等待结果
        console.log(res)
        if (res) {

        } else {
          wx.navigateTo({
            url: '/pages/register/register',
          })
        }
      }
    }
  },
  getTicketUser: function () {//获取优惠券信息
    app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.id, from: 1}, e => {
      console.log(e)
      if (e.code == 200) {
        this.setData({
          ticketUser: e.data
        })
      }
    }, this)
  },
  getCodeFn:function(){//获取二维码
    app.wxRequest(app.globalData.httpUrl + 'couponbuy/getqrcode', { coupon_sell_id: this.data.id}, e => {
      console.log(e)
      if (e.code == 200) {
        this.setData({
          codePicUrl: e.data.coupon_url,
        })
      }
    }, this)
  },
  showCode:function(){//查看二维码
    this.setData({
      yesCode: true,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "老门框爆肚会员",
      success: res => {
        console.log(res, "转发成功")
      },
    }
  }
})