operate.js
5.87 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* [个人中心]个人设置-第二步操作
* @author: jiangmin
* @date: 2016/07/14
*/
var dialog = require('../../plugins/dialog');
var _alert = dialog.Alert;
var regValidate = require('../../passport/common/mail-phone-regx');
var types = location.pathname.split('/');
var type = types[types.length - 1]; // 界面操作类型
var $imgCaptchaInput = $('#captcha');
var second = 60;
var $sms = $('#send-code2'); // 发送短信验证码按钮
var area = $('#country-code').text().substring(1) || '86'; // 地区码
// 发送短信后倒计时显示
var disableSMSBtn = function() {
second -= 1;
if (second < 0) {
second = 60;
$sms.text('获取短信验证码');
$sms.removeClass('disable');
$sms.removeClass('progress');
} else {
$sms.add('progress');
$sms.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
};
// 校验手机号码格式
var validatePhoneNumLocal = function(phoneNum) {
var length = phoneNum.length;
phoneNum = parseInt(phoneNum, 10);
if (length === 0) {
new _alert('请输入手机号码!').show();
return false;
} else if (length !== 11 || !/^[0-9]+$/.test(phoneNum) || !regValidate.phoneRegx['+86'].test(phoneNum)) {
new _alert('手机号码格式不正确,请重新输入!').show();
return false;
} else {
return true;
}
};
require('yoho-jquery-placeholder');
$('[placeholder]').placeholder();
/**
* 绑定手机号码部分
*/
$('#region').on('change', function() {
$('#country-code').text($(this).val());
area = $(this).val().substring(1);
});
// 校验手机号码
$('#real-mobile').blur(function() {
var mobile = $(this).val();
var self = $('#real-mobile').parent();
if (validatePhoneNumLocal(mobile)) {
$.ajax({
type: 'POST',
url: '/me/account/checkVerifyMobile',
dataType: 'json',
data: {
mobile: mobile,
area: area
},
success: function(data) {
if (data.code === 200) {
$sms.removeClass('disable');
self.find('.tips-success').addClass('ok').show();
self.find('.tips-error').removeClass('notok').hide();
} else {
new _alert(data.message).show();
self.find('.tips-success').removeClass('ok').hide();
self.find('.tips-error').addClass('notok').show();
}
}
});
}
});
// 发送手机验证码
$sms.click(function() {
var mobile = $('#real-mobile').val();
if ($(this).hasClass('disable')) {
return;
}
$sms.addClass('disable');
$.ajax({
type: 'POST',
url: '/me/account/sendMobileMsg',
dataType: 'json',
data: {
mobile: mobile,
area: area
},
success: function(data) {
if (data.code !== 200) {
new _alert(data.message).show();
$sms.removeClass('disable');
} else {
disableSMSBtn();
}
}
});
});
// 绑定手机第二步提交
$('#mobile-step2').click(function() {
var code = $('#msg-code').val();
var mobile = $('#real-mobile').val();
var self = $('#msg-code').parent();
$.ajax({
type: 'POST',
url: '/me/setting/step2/mobile',
data: {
code: code,
mobile: mobile,
area: area,
type: type,
_csrf: $('#checkCode').val()
},
success: function(data) {
if (data.code === 200) {
self.find('.tips-success').addClass('ok').show();
self.find('.tips-error').removeClass('notok').hide();
location.href = '/me/setting/step3/' + type;
} else {
new _alert(data.message).show();
self.find('.tips-success').removeClass('ok').hide();
self.find('.tips-error').addClass('notok').show();
}
}
});
});
/**
* 修改密码部分
*/
// 输入确认密码
$('#checkPwd').blur(function() {
var newPwd = $('#newPwd').val().trim();
var checkPwd = $(this).val().trim();
var self = $(this).parent();
if (newPwd === checkPwd) {
self.find('.tips-success').addClass('ok').show();
self.find('.tips-error').removeClass('notok').hide();
} else {
self.find('.tips-success').removeClass('ok').hide();
self.find('.tips-error').addClass('notok').show();
}
});
// 校验图片验证码
$imgCaptchaInput.blur(function() {
$.ajax({
type: 'POST',
url: '/passport/images/check',
data: {
verifyCode: $imgCaptchaInput.val()
},
success: function(data) {
if (data.code === 200) {
$imgCaptchaInput.parent().find('.tips-success').addClass('ok').show();
$imgCaptchaInput.parent().find('.tips-error').removeClass('notok').hide();
} else {
$imgCaptchaInput.parent().find('.tips-success').removeClass('ok').hide();
$imgCaptchaInput.parent().find('.tips-error').addClass('notok').show();
}
}
});
});
// 提交修改密码
$('#step2-pwd').click(function() {
var password = $('#newPwd').val();
if ($('.notok').length === 0) {
$.ajax({
type: 'POST',
url: '/me/setting/step2/password',
data: {
password: password,
type: type,
_csrf: $('#checkCode').val()
},
success: function(data) {
if (data.code === 200) {
location.href = '/me/setting/step3/' + type;
} else {
new _alert(data.message).show();
}
}
});
}
});