// pages/Add/index.js
const config = require('../../config/config.js')
const Http = require('../../utils/http.js')
const HttpBasics = require('../../utils/HttpBasics.js')
const util = require('../../utils/util.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    paramData:null,
    isAdmin:null,
    userData:null,
    phoneIf:false,
    businessId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,88888888888888888)
    let phoneIf = options.phone != 'undefined' ? true : false
    options.phone = (options.phone != 'undefined' ? options.phone:'未绑定')
    this.setData({
      paramData:options,
      phoneIf
    });
    this.getUserInfo()
  },
  getUserInfo(){
    let _this=this;
    app.globalData.userInfo().then(res => {
      console.log(res)
      if (res.businessId == 3){
        _this.setData({
          businessId:3
        })
      }
      _this.setData({
        userData:res
      })
    }).catch(err=>{
      wx.showToast({
        title: '商户信息获取出错',
        icon: 'none',
        duration: 2000,
        mask: false
      });
    })
  },
  gotoScore(e){
    // console.log(e.currentTarget.id,6666666666)
    if (e.currentTarget.id == '1') {
      wx.navigateTo({
        url: `/pages/operation/index?address=${this.data.paramData.address}&avatarUrl=${this.data.paramData.avatarUrl}&id=${this.data.paramData.id}&levelName=${this.data.paramData.levelName}&name=${this.data.paramData.name}&nickName=${this.data.paramData.nickName}&phone=${this.data.paramData.phone}&score=${this.data.paramData.score}&credit=${this.data.paramData.credit}&type=${e.currentTarget.id}&isAdmin=${this.data.userData.is_admin}&merchant_id=${this.data.userData.merchant_id}&businessId=${this.data.businessId}`
      })
    } else {
      wx.navigateTo({
        url: `/pages/exchange/index?address=${this.data.paramData.address}&avatarUrl=${this.data.paramData.avatarUrl}&id=${this.data.paramData.id}&levelName=${this.data.paramData.levelName}&name=${this.data.paramData.name}&nickName=${this.data.paramData.nickName}&phone=${this.data.paramData.phone}&score=${this.data.paramData.score}&credit=${this.data.paramData.credit}&type=${e.currentTarget.id}&merchant_id=${this.data.userData.merchant_id}`
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})