bind-card-check.js
2 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
/**
* 银行卡校验
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/25
*/
var $ = require('yoho-jquery');
var tip = require('../plugin/tip');
var debounce = require('lodash/debounce');
var debounceFn = debounce(function(cardNo, formModel) {
formModel.bankCode = '';
formModel.bankName = '';
// 获取银行信息
$.get('/home/installment/bank-info', {cardNo: cardNo}).then(function(result) {
if (result.code === 200) {
if (result.data.bankCode) {
formModel.bankCode = result.data.bankCode;
formModel.bankName = result.data.bankName;
// 设置银行名称
$('#bank-name').text(result.data.bankName);
// 设置银行图标
$('#bank-icon').show().attr('src',
window.STATIC_RESOURCE_PATH +
'/img/home/bank-icons/' + result.data.bankCode + '.png');
$('#bank-desc').show();
}
// 返回1不支持, 孟令阶
if (result && result.data && result.data.businessSupport === '1') {
$('#bank-name').text('暂不支持此银行卡');
$('#bank-desc').show();
$('#bank-icon').hide();
}
} else {
tip.show(result.message);
$('#bank-desc').hide();
}
});
}, 1000);
var checkCard = function(formModel) {
// 银行卡格式化
$('#cardNo').keyup(function() {
var value = $(this).val();
var cardNo = $(this).val().replace(/\s/g, '');
$(this).val(value.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ')).trigger('change');
if (cardNo && cardNo.length < 16) {
$('#bank-desc').hide();
}
}).blur(function() {
var cardNo = $(this).val().replace(/\s/g, '');
if (cardNo && cardNo.length >= 16) {
debounceFn(cardNo, formModel);
} else {
$('#bank-desc').hide();
}
});
};
module.exports = checkCard;