import {loginByUserInfo, loginFn} from './../../utils/login'

//获取应用实例
const app = getApp()
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    navUrl: '',
    code: '',
    login_img: "/image/4Dage/login-bg.svg",
    login_logo: "/assets/images/login-logo.svg"    
  },

  onLoad: function(options) {
    wx.login({
      success: (res) => {
        if (res.code) {
          this.setData({
            code: res.code
          })
        }
      }
    });
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  },
  bindgetphonenumber(e) {
    loginFn(e, this.data.code).then(() => {
      wx.navigateBack()
    })
  },
  bindgetuserinfo (e) {
    wx.showLoading({
      title: '登录中',
    })
    loginByUserInfo(e.detail, this.data.code).then(() => {
      wx.hideLoading({
        complete: (res) => {
          wx.navigateBack()
        },
      })
    })
    
  }
})