HasDocumentedVerify.js 2.88 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
// 已有档案验证

// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')

var timeCount = 60;
var timer;
var phone;
var name;
Page({
data: {
inputFocus: {codeInput:false},
time:'60s',
},
/*-------生命周期--------*/
onLoad: function(option){
phone = option.phone;
name = option.name;
this.keepTime()
},
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)
},
/*-------交互--------*/
// 提交表单
formSubmit: function(e) {

var self = this
if(e.detail.value.code == "") {
wx.showModal({
title: '提示',
content: '请输入验证码',
showCancel:false,
success: function(res) {
}
})
return
}
networkUtil.showLoading()
var param = {code : e.detail.value.code ,phone : phone}
if(getApp().globalData.openInfo.mpid){
param.gzopenid = getApp().globalData.openInfo.mpid
console.log('绑定mpid',param)
}
if(getApp().globalData.openInfo.code){
param.jscode = getApp().globalData.openInfo.code
console.log('绑定code',param)
}
networkUtil._get(api.verifyCode,param,function(res){
console.log(res)
self.loginSuccess(res.data)
},function(res){
networkUtil.showErrorToast(res.errormsg)
})
},
loginSuccess(data){
console.log(data)
wx.setStorageSync('userToken', data.token)
wx.setStorageSync('hxName', data.hxName)
wx.setStorageSync('hxPassWord', data.hxPassWord)
getApp().globalData.token = data.token
wx.navigateTo({
url: '../HasDocumentedVerifySuccess/HasDocumentedVerifySuccess?name='+name
})
}
,
// 获取验证码
getVerifyCode:function(e){
if(timeCount < 60){
return
}
var that = this
networkUtil._post(api.bindDoc,{username : name ,phone : phone},function(res){
},function(res){
timeCount = 60
clearTimeout(timer);
that.setData({
time : '0s'
})
networkUtil.showErrorToast('获取验证码失败,请稍后再试')
})
if (timeCount == 60) {
this.keepTime()
}
},
// 获取焦点
getFocus:function(e) {
var that = this
var focus = that.data.inputFocus
focus.codeInput = true
that.setData({
inputFocus:focus
})
},
// 失去焦点
blurInput:function(e) {
var that = this
var focus = that.data.inputFocus
focus.codeInput = false
that.setData({
inputFocus:focus
})
}
})