bind-card.page.js
2.76 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
/**
* 新增银行卡
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/25
*/
var $ = require('yoho-jquery');
var tip = require('plugin/tip');
var checkCard = require('./bind-card-check');
var loading = require('plugin/loading');
var applyButton = $('.open-btn');
var flag = true;
var formData = {
cardNo: '',
mobile: '',
bankName: '',
bankCode: ''
};
var validateForm = function() {
var ret = false;
if (formData.cardNo &&
formData.mobile.length === 11 &&
formData.bankName &&
formData.bankCode) {
applyButton.removeClass('disabled');
ret = true;
} else {
applyButton.addClass('disabled');
ret = false;
}
return ret;
};
require('common');
require('./overdue-notice');
checkCard(formData);
// 定时更新模型,解决各种浏览器奇葩问题终极办法
setInterval(function() {
$('input').each(function() {
var name = $(this).attr('name');
formData[name] = $(this).val();
});
validateForm();
}, 500);
applyButton.on('click', function() {
if (!flag || $(this).hasClass('disabled') || !validateForm()) {
return false;
}
if (!/^1[3|4|5|8|7][0-9]{9}$/.test(formData.mobile)) {
tip.show('手机号输入不正确!');
return false;
}
loading.showLoadingMask();
flag = false;
$.ajax({
type: 'GET',
url: '/home/installment/post-account',
data: formData,
success: function(data) {
var params = {
action: 'go.bindCardResult',
params: {
status: 0
}
};
var url = location.href + '&openby:yohobuy=';
if (window.queryString.title) {
params.params.name = $('.username').html();
}
if (data.code === 200) {
params.params.status = 1;
} else if (data.code === 500) {
tip.show('连接超时');
flag = true;
params.params.message = '网络连接超时!';
} else {
params.params.message = data.message;
}
url += encodeURIComponent(JSON.stringify(params));
loading.hideLoadingMask();
$('body').append('<a href=' + url + ' style="display: none;"><span class="jump">&npsb;</span></a>');
$('.jump').click();
},
error: function() {
loading.hideLoadingMask();
tip.show('网络断开连接了~');
flag = true;
}
});
});
// 使用H5标签后 maxlength 标签失效
$('input[maxlength]').keyup(function() {
var value = $(this).val(),
length = $(this).attr('maxlength') || 20;
$(this).val(value.slice(0, length));
});