// pages/Voucher/Voucher.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    telPhone: '',
    tcId: null,
    orderId: null,
    dataList: [],
    tipsMsg: ""
  },
  goPage: function (e) {
    console.log(e)
    let index = e.currentTarget.dataset.index;
    let name = this.data.dataList[index].nameID
    let orderId = this.data.dataList[index].OrderId
    wx.setStorage({
      key: "info",
      data: {
        ID: this.data.dataList[index].Id,
        nameID: name
      }
    })
    wx.navigateTo({
      url: '/pages/Voucher/VoucherDetails/VoucherDetails?&orderId=' + orderId + '&tcId=' + this.data.tcId
      // url: '/pages/Voucher/VoucherDetails/VoucherDetails?&orderId=' + _this.data.orderId + '&tcId=3278'
    })
    return
    wx.navigateTo({
      url: '/pages/Voucher/VoucherDetails/VoucherDetails?&orderId=' + orderId + '&tcId=' + _this.data.tcId
      // url: '/pages/Voucher/VoucherDetails/VoucherDetails?&orderId=' + _this.data.orderId + '&tcId=3278'
    })
  },
  //问券详情跳转
  Details: function (e) {
    let data = {
      guestMobile: this.data.telPhone,
      TCID: this.data.tcId
      // TCID: 3278
    }
    app.$api('miniProgram_price_GetGuestByPhone', data).then(res => {
      let _this = this;
      let data = res
      for(let i = 0; i< data.length; i++){
        data[i].nameID = data[i].SurName + (data[i].Sex === 1 ? '先生' : '女士');
        data[i].MobilePhoneS = data[i].MobilePhone.substr(0, 3) + '****' + data[i].MobilePhone.substr(7)
      }  
      _this.setData({
        dataList: data
      })
    }).catch(err => {
      console.log(err)
      this.setData({
        tipsMsg: err.message
      })
    })
    return
    if (!this.data.telPhone) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none',
        duration: 1000
      })
    } else {
      
      
    }
  },
  //输入手机号
  TelPhone: function (e) {
    console.log(e.detail.value)
    this.setData({
      telPhone: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const scene = decodeURIComponent(options.scene)
    if (scene) {
      let tcId = scene.split('=')[1] ? scene.split('=')[1] : options.tcid;
      // let tcId = 4006
      // this.setData({
      //   tcId: tcId
      // })
    }else{
      // this.setData({
      //   tcId: 3278
      // })
    }
    this.Details()
    //修改title
    wx.setNavigationBarTitle({
      title: '意见调查'  
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})