bind.js
4.95 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
/**
* 注册
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/8
*/
let $ = require('yoho-jquery');
let $phoneNum = $('#phone-num'),
$countrySelect = $('#country-select'),
$areaCode = $('#area-code'),
$openId = $('#openId'),
$nickname = $('#nickname'),
$sourceType = $('#sourceType'),
$btnNext = $('#btn-next'),
$captcha = $('#js-img-check');
let api = require('../api'),
tip = require('js/plugin/tip'),
dialog = require('js/plugin/dialog');
let trim = $.trim;
let showErrTip = tip.show;
let requested = false;
require('js/common');
let Validate = require('js/plugin/validata');
let validate = new Validate('#js-img-check', {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
if ($captcha.data('userverify')) {
validate.init();
}
function nextStep(url, mobileNo, areaCode) {
if (requested) {
return false;
}
let params = {
phoneNum: mobileNo,
areaCode: areaCode.replace('+', '')
};
validate.getResults().then((result) => {
if (typeof result === 'undefined') {
return;
}
requested = true;
$btnNext.addClass('disable').html('绑定中...');
$.extend(params, result);
$.ajax({
type: 'POST',
url: '/passport/bind/sendBindMsg',
data: params,
success: function(res) {
requested = false;
if (res.code === 200) {
// 统计代码:用于统计从哪个渠道登录
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
loginRefer: $sourceType.val()
}, false);
}
location.href = url;
} else {
$btnNext.removeClass('disable').html('下一步');
tip.show(res.message);
}
},
error: function() {
tip.show('出错了,请重试!');
$btnNext.removeClass('disable').html('下一步');
requested = false;
}
});
});
}
api.selectCssHack($('#country-select'));
api.bindClearEvt();
$phoneNum.bind('input', function() {
if (trim($phoneNum.val()) === '') {
$btnNext.addClass('disable');
} else {
$btnNext.removeClass('disable');
}
});
$countrySelect.change(function() {
$areaCode.text($countrySelect.val());
});
$btnNext.on('touchstart', function() {
let pn = trim($phoneNum.val()),
openId = trim($openId.val()),
nickname = trim($nickname.val()),
sourceType = trim($sourceType.val()),
areaCode = $countrySelect.val();
if ($btnNext.hasClass('disable')) {
return;
}
if (api.phoneRegx[areaCode].test(pn)) {
let params = {
areaCode: areaCode.replace('+', ''),
phoneNum: pn,
openId: openId,
sourceType: sourceType,
nickname: nickname
};
$.ajax({
url: '/passport/bind/bindCheck',
type: 'POST',
data: params,
success: function(res) {
validate.type === 2 && validate.refresh();
if (res.code === 200) {
if (res.data.is_register === 1) {
dialog.showDialog({
dialogText: '该手机号已注册过有货\n' + pn + ',确定绑定吗?',
hasFooter: {
leftBtnText: '更换号码',
rightBtnText: '继续绑定'
}
}, () => {
dialog.hideDialog();
nextStep(res.data.next, pn, areaCode);
});
} else if (res.data.is_register === 3) {
dialog.showDialog({
dialogText: '绑定失败,该手机号已注册,请更换或使用该手机号直接登录',
hasFooter: {
centerBtnText: '确定'
}
});
} else {
nextStep(res.data.next, pn, areaCode);
}
} else {
if (res.captchaShow) {
((res.changeCaptcha && validate.type !== 2) && validate.refresh());
}
showErrTip(res.message);
}
},
error: function() {
showErrTip('网络断开连接啦~');
validate.refresh();
}
});
} else {
showErrTip('手机号格式不正确,请重新输入');
}
});
if (/MicroMessenger/i.test(navigator.userAgent) && $.queryString().refer) {
$('.go-back').attr('href', decodeURIComponent($.queryString().refer));
}