const util = require("../../../utils/util")

const app = getApp()
Page({
  data: {
    spinShow: false,
    userInfo:{},
  },
  onShow: function () {
    app.checkLogin( userInfo=>{
      this.setData({userInfo})
    } )
  },
  doLoginByCode( code ){
    app.formPost( "Auth.WxLoginByCode", {code}).then( (res)=>{
      if( res.code == 200){
        this.setData( {userInfo: res.data})
        app.setUserInfo( res.data )
      }
    })
  },
  doGetPhoneNumber( code, iv, encryptedData ){
    let param = {code, iv, encryptedData }
    app.formPost( "Auth.WxLoginByPhone", param).then( (res)=>{
      if( res.code == 200){
        this.setData( {userInfo: res.data})
        app.setUserInfo( res.data )
      }
    })
  },
  logOut() {
    wx.setStorageSync('userId', '')
    wx.setStorageSync('token', '')
    wx.setStorageSync('@openid', '')
    let userInfo = {}
    this.setData({userInfo})
    app.setUserInfo( userInfo )
    wx.navigateTo({
      url: '/pages/index/index',
    })
  },
  gotoIdentify(){
    wx.navigateTo({
      url: '/pages/user/identify/index',
    })
  }
})