register.js 3.11 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
// pages/register/register.js
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')
var util = require('../../utils/util.js')

var timeCount = 60;
var timer;
Page({
/**
* 页面的初始数据
*/
data: {
time: '获取验证码',
areaName: getApp().globalData.openInfo.hospitalName || ''
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
timeCount = 60
clearTimeout(timer)
},

/*-------自定义--------*/
// 计时器
keepTime: function() {
var that = this
timeCount--
that.setData({
time: timeCount + 's'
})
if (timeCount == 0) {
timeCount = 60
clearTimeout(timer);
return
}
timer = setTimeout(function() {
that.keepTime()
}, 1000)
},
inputPhone(e) {
this.data.phone = e.detail.value
},
// 获取验证码
getVerifyCode: function(e) {
if (timeCount < 60) {
return
}
if (this.data.phone.length != 11 || this.data.phone[0] != '1') {
networkUtil.showErrorToast('请填写正确的手机号')
return
}
var that = this
networkUtil._get(api.bindDoc, {
phone: this.data.phone
}, function(res) {

}, function(res) {
timeCount = 60
clearTimeout(timer);
that.setData({
time: '0s'
})
networkUtil.showErrorToast('获取验证码失败,请稍后再试')
})
if (timeCount == 60) {
this.keepTime()
}
},
submitData(e) {
var str = ''
if (!e.detail.value.userName) {
str = '请填写您的姓名'
} else
if (!e.detail.value.cardNo) {
str = '请填写您的身份证号'
} else
if (!util.checkIdCard(e.detail.value.cardNo)) {
str = '请填写正确的身份证号'
} else
if (!e.detail.value.phone) {
str = '请填写您的手机号'
} else
if (e.detail.value.phone.length != 11) {
str = '请填写正确的手机号'
} else
if (!e.detail.value.code) {
str = '请填写验证码'
} else
if (!e.detail.value.password) {
str = '请输入密码'
} else
if (!e.detail.value.passwordS) {
str = '请再次确认密码'
} else
if (e.detail.value.password.length < 6) {
str = '密码必须为6位以上'
} else
if (!str && e.detail.value.password != e.detail.value.passwordS) {
str = '两次密码输入不一致'
}
if (str) {
networkUtil.showErrorToast(str)
return
}
networkUtil.showLoading()
var param = e.detail.value
if (!getApp().globalData.openInfo.hospitalId) {
networkUtil.showErrorToast('未从二维码中获取到医院信息')
return
}
delete param.passwordS
param.hospitalId = getApp().globalData.openInfo.hospitalId
networkUtil._post(api.register, param, function(res) {
console.log(res)
wx.showToast({
title: '注册成功',
icon: 'success',
duration: 2000
})
setTimeout(function() {
wx.navigateBack({})
}, 1000)
}, function(res) {

networkUtil.showErrorToast(res.errormsg)
}, 'application/json')
}
})