var app = getApp()
const util = require('../../../utils/utils.js')
Page({
  data: {
    balance:'0.00',//显示余额
    state:'',//认证状态
    phone: '',//手机认证状态
    imgUrl:'http://resource.weilaibike.com/xiaobanma/walletBg.png',
    stateStatus: '',
    is_bindPhone: '',
    student:'',
    is_student:'',
    setting:wx.getStorageSync('setting')
  },
  getBalance: util.throttle(function (e) {
    app.request("/me", '', "GET").then(res => {
      200 == res.statusCode && wx.setStorageSync("userInfo", res.data), this.setData({
        balance: res.data.wallet_money
      })
    })
    //获取实名认证状态
  },1000),
  walletDetail: function () {
    wx.navigateTo({
      url: '/pages/wallet_details/wallet_details',
    })
  },
  goCertified:function(){
    wx.navigateTo({
      url: '/pages/real_name/real_name?state2=2&index=1&hidden=true',
    })
  },
  goStudent:function(){
    wx.navigateTo({
      url: '/pages/student_certification/student_certification',
    })
  },
  goBindphone: function () {
    wx.navigateTo({
      url: '/pages/real_name/real_name?state1=1&index=0&hidden=true',
    })
  },
  huanbang: function () {
    wx.navigateTo({
      url: '/pages/huan_bang/huan_bang',
    })
  },
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    this.getBalance();
    app.request("/user/status", '', "GET").then(res => {
      console.log(res)
      if (res.statusCode == 200) {
        if (res.data.is_card_certified == 1){
          this.setData({
            state:'已认证'
          })
        }else{
          this.setData({
            state:'去认证'
          })
        }
        if (res.data.is_bind_mobile == 1) {
          this.setData({
            phone: '去换绑'
          })
        } else {
          this.setData({
            phone: '去认证'
          })
        }
        if (res.data.is_student == 1) {
          this.setData({
            student: '认证成功'
          })
        } else {
          this.setData({
            student: '去认证'
          })
        }
        this.setData({
          stateStatus: res.data.is_card_certified,
          is_bindPhone: res.data.is_bind_mobile,
          is_student:res.data.is_student,
          setting:wx.getStorageSync('setting')
        })
      wx.setStorageSync('userState', res.data)
      }
    })
    
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    
  }
})