var app = getApp()

Page({
  data: {
    statusBarHeight: 44,
    loading: false
  },

  onLoad: function () {
    this.setData({ statusBarHeight: app.globalData.statusBarHeight })
  },

  onLogin: function () {
    var self = this
    self.setData({ loading: true })

    app.doLogin().then(function (data) {
      self.setData({ loading: false })
      if (data && (data.is_new_user || !data.user_info || !data.user_info.phone)) {
        wx.redirectTo({ url: '/pages/register/register' })
      } else {
        wx.switchTab({ url: '/pages/index/index' })
      }
    }).catch(function (err) {
      self.setData({ loading: false })
      wx.showToast({ title: err.message || '登录失败', icon: 'none' })
    })
  },

  onAgreement: function () {
    wx.showModal({ title: '提示', content: '用户协议和隐私政策内容建设中', showCancel: false })
  }
})
