失去焦点就开始做数据请求判断电话号码是正确

 <view class='register-input-box'>
    <input class='register-input' placeholder="请输入手机号" bindinput='phoneInput' bindblur="phoneOnBlur" value='{{phone}}' type="number" maxlength="11"></input>
  </view>
phoneOnBlur: function () {
    this.checkPhone()
},
checkPhone: function(sendSmsCode) {
    var that = this
    var phone = that.data.phone
    if (phone.length <= 0) {
      that.setData({
        errorMsg: '手机号不能为空',
      })
      return
    }
    xapi.request({
      url: getApp().apiHostNew + `/user/contact/${phone}/checkExist`,
      method: 'get'
    }).then( function(res) {
      if (res.data.code == 200) {
        if (res.data.data == true) {
          if (sendSmsCode) {
            that.sendSmsCode()
          }
          that.setData({
            showUserLoginTips: false
          })
        } else {
          that.setData({
            showUserLoginTips: true,
            smsCodeOk: false,
          })
        }
      } else {
        that.setData({
          showSendSmsCodeTips: false,
          smsCodeOk: false,
          errorMsg: res.data.message,
        })
      }
    })
  },
posted on 2018-11-14 15:46  周小姐你好  阅读(9596)  评论(0编辑  收藏  举报