installment.starting-service.page.js
1.29 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
const $ = require('yoho-jquery');
const Timer = function() {
this.counter = 0;
this.countdownTimer = null;
};
/**
* 倒计时
*
* @param progress 进度回调
* @param complete 完成回调
*/
Timer.prototype.startCountdown = function(progress, complete) {
if (this.counter > 0 || this.countdownTimer) {
return;
} else {
this.counter = 59;
}
if (progress) {
progress.call(this, this.counter);
}
this.countdownTimer = setInterval(()=> {
this.counter--;
if (this.counter <= 0) {
if (complete) {
clearInterval(this.countdownTimer);
this.counter = 0;
this.countdownTimer = null;
complete.call(this);
}
}
if (progress && this.counter > 0) {
progress.call(this, this.counter);
}
}, 1000);
};
/**
* 点击发送短信事件
*/
$('#send-sms').click(function() {
new Timer().startCountdown(function(counter) {
$('#send-sms').text(counter + 's');
}, function() {
$('#send-sms').text('获取验证码');
});
return false;
});
$('#card-no').keydown(function() {
const value = $(this).val();
$(this).val(value.replace(/\s[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 '));
});