verification.js
3.43 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
/**
* 验证手机
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/14
*/
var $ = require('yoho-jquery');
var Captcha = require('../../plugins/captcha');
var $sc = $('#send-captcha'),
$msgTip = $('#captcha-tip'),
$errTip = $('#err-tip'),
$next = $('#next-step'),
seconds,
itime,
captcha = new Captcha('#captcha-img');
captcha.onSuccess(function() {
$sc.trigger('click');
});
require('../../simple-header');
$sc.click(function() {
$.post('/passport/back/sendbackmobile', {
mobile: $('#mobile').val(),
area: $('#area').val(),
verifyCode: captcha.getResults()
}, function(result) {
if (result.code === 200) {
$errTip.hide();
if ($(this).hasClass('disable')) {
return;
}
seconds = 60;
$sc.addClass('disable').attr('disabled', true);
$msgTip.removeClass('hide');
$sc.val(seconds-- + '秒后可重新操作');
itime = setInterval(function() {
if (seconds === 0) {
clearInterval(itime);
$sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
captcha.refresh();
} else {
$sc.val(seconds-- + '秒后可重新操作');
}
}, 1000);
} else {
if (result.data && result.data.needCaptcha) {
captcha.show();
}
if (result.code === captcha.errorCode) {
captcha.showTip(result.message);
return;
}
$(this).addClass('error');
$errTip.removeClass('hide').text(result.message);
}
});
});
seconds = 60;
$sc.addClass('disable').attr('disabled', true);
$msgTip.removeClass('hide');
$sc.val(seconds-- + '秒后可重新操作');
itime = setInterval(function() {
if (seconds === 0) {
clearInterval(itime);
$sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
captcha.init();
} else {
$sc.val(seconds-- + '秒后可重新操作');
}
}, 1000);
$('#captcha').keyup(function() {
var v = $.trim($(this).val()),
that = this;
if (v.length === 4) {
$.ajax({
type: 'POST',
url: '/passport/back/backmobile',
dataType: 'json',
data: {
code: $('#captcha').val(),
area: $('#area').val(),
mobile: $('#mobile').val()
},
success: function(res) {
if (res.code === 200) {
// 添加验证码正确验证
$next.removeClass('disable').attr('href', res.data);
$errTip.addClass('hide');
$(that).removeClass('error');
} else {
$next.addClass('disable');
$errTip.removeClass('hide').find('em').text('验证码输入错误');
$(that).addClass('error');
}
}
});
} else {
$next.addClass('disable').attr('href', 'javascript:;'); // eslint-disable-line
}
}).blur(function() {
var v = $.trim($(this).val());
if (v === '') {
// 添加验证码正确验证
$(this).addClass('error');
$errTip.removeClass('hide').text('请输入验证码');
}
}).focus(function() {
$(this).removeClass('error');
});