const api = require('../../utils/api')

Page({
  data: {
    phone: '18600000000',
    code: '682139',
    error: '',
  },
  onPhone(e) {
    this.setData({ phone: e.detail.value })
  },
  onCode(e) {
    this.setData({ code: e.detail.value })
  },
  async submit() {
    try {
      await api.login(this.data.phone, this.data.code)
      wx.redirectTo({ url: '/pages/home/home' })
    } catch (err) {
      this.setData({ error: err.message || '登录失败' })
    }
  },
})
