import {
  iactivity
} from '../../../api/api.js'

const app = getApp()

Page({
  data: {
    gender: '男',
    age_range: ''
  },
  clickRegister() {
    if (!this.data.realname) {
      return wx.showToast({
        icon: 'loading',
        title: '请填写姓名！'
      })
    }
    if (!this.data.age_range) {
      return wx.showToast({
        icon: 'loading',
        title: '请选择年龄段！'
      })
    }

    if (!this.data.mobile || this.data.mobile.length != 11) {
      return wx.showToast({
        icon: 'loading',
        title: '请正确填写手机号！'
      })
    }

    if (!this.data.address) {
      return wx.showToast({
        icon: 'loading',
        title: '请填写地址！'
      })
    }

    delete this.data.showAgegroup
    delete this.data.__webviewId__
    iactivity.loadJoinin(this.data, r => {
      app.data.nav.joininActivityInfo = r.info
      wx.navigateTo({
        url: '../registerDone/registerDone'
      })
    })

  },
  clickRadio(e) {
    this.setData({
      gender: e.currentTarget.dataset.v
    })
  },
  clickAgegroup(e) {
    this.setData({
      showAgegroupModal: true
    })
  },
  clickAgegroupModalCancel() {
    this.setData({
      showAgegroupModal: false
    })
  },
  clickAgegroupItem(e) {
    this.setData({
      age_range: e.currentTarget.dataset.agegroup,
      showAgegroupModal: false
    })
  },
  inputName(e) {
    this.setData({
      realname: e.detail.value
    })
  },
  inputPhoneno(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  inputAddress(e) {
    this.setData({
      address: e.detail.value
    })
  },
  onLoad(opts) {
    this.setData({
      event_id: opts.id
    })
  }
})