// 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') } })