relate.js
2.7 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
/**
* 我的信息
* @author: yyqing<yanqing.yang@yoho.cn>
* @date: 2016/4/11
*/
var $ = require('yoho.jquery');
var $relateMain = $('#relate-main'),
$codeValidate = $('#code-validate'),
$vaWrapper = $codeValidate.find('.validate-wrapper'),
$msgCode = $codeValidate.find('.msg-code'),
$second = $codeValidate.find('.count-down span'),
$hideDom = $('#hide-info');
var relate = {};
var circleTime = {};
relate = $hideDom.data();
$hideDom.remove();
// 倒计时
circleTime = {
init: function() {
if (this.timer) {
window.clearTimeout(this.timer);
}
this.second = 60;
$vaWrapper.addClass('waiting');
this.changeTime();
},
changeTime: function() {
var that = this;
if (this.second && this.second > 0) {
$second.text(this.second);
this.second--;
this.timer = window.setTimeout(function() {
that.changeTime();
}, 1000);
} else {
this.clearTime();
}
},
clearTime: function() {
if (this.timer) {
window.clearTimeout(this.timer);
}
$vaWrapper.removeClass('waiting');
}
};
function sendVerifyMsg() {
circleTime.init();
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/sendBindMsg',
data: {
mobile: relate.mobile,
area: relate.area
}
}).then(function(jsonData) {
if (jsonData && jsonData.code !== 200) {
circleTime.clearTime();
alert(jsonData.message);
}
});
}
function relateMobile() {
var code = $msgCode.val();
if (!code) {
return;
}
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/relateMobile',
data: {
mobile: relate.mobile,
area: relate.area,
openId: relate.openid,
sourceType: relate.source,
code: code
}
}).then(function(jsonData) {
if (jsonData.code === 200) {
window.location.href = jsonData.data.refer;
} else {
alert(jsonData.message);
}
});
}
$('#next-step-btn').click(function() {
sendVerifyMsg();
$relateMain.addClass('hide');
$codeValidate.removeClass('hide');
});
$codeValidate.on('click', '.get-code', function() {
sendVerifyMsg();
});
$codeValidate.on('click', '.perv-step', function() {
circleTime.clearTime();
$relateMain.removeClass('hide');
$codeValidate.addClass('hide');
$msgCode.val('');
});
$('#relate-btn').click(function() {
relateMobile();
});