...
|
...
|
@@ -5,24 +5,36 @@ const Timer = function() { |
|
|
this.countdownTimer = null;
|
|
|
};
|
|
|
|
|
|
const FormModel = function() {
|
|
|
};
|
|
|
|
|
|
const formModel = new FormModel();
|
|
|
|
|
|
/**
|
|
|
* 倒计时
|
|
|
*
|
|
|
* @param progress 进度回调
|
|
|
* @param start 启动回调
|
|
|
* @param tick 进度回调
|
|
|
* @param complete 完成回调
|
|
|
*/
|
|
|
Timer.prototype.startCountdown = function(progress, complete) {
|
|
|
Timer.prototype.startCountdown = function(start, tick, complete) {
|
|
|
if (this.counter > 0 || this.countdownTimer) {
|
|
|
return;
|
|
|
} else {
|
|
|
this.counter = 59;
|
|
|
}
|
|
|
|
|
|
if (progress) {
|
|
|
progress.call(this, this.counter);
|
|
|
|
|
|
// 启动回调
|
|
|
if (start) {
|
|
|
start.call(this);
|
|
|
}
|
|
|
|
|
|
if (tick) {
|
|
|
tick.call(this, this.counter);
|
|
|
}
|
|
|
|
|
|
// 开始计时器
|
|
|
this.countdownTimer = setInterval(()=> {
|
|
|
this.counter--;
|
|
|
|
...
|
...
|
@@ -30,14 +42,16 @@ Timer.prototype.startCountdown = function(progress, complete) { |
|
|
if (complete) {
|
|
|
clearInterval(this.countdownTimer);
|
|
|
|
|
|
// 重置计时器
|
|
|
this.counter = 0;
|
|
|
this.countdownTimer = null;
|
|
|
complete.call(this);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (progress && this.counter > 0) {
|
|
|
progress.call(this, this.counter);
|
|
|
// 完成回调
|
|
|
if (tick && this.counter > 0) {
|
|
|
tick.call(this, this.counter);
|
|
|
}
|
|
|
}, 1000);
|
|
|
};
|
...
|
...
|
@@ -47,17 +61,65 @@ Timer.prototype.startCountdown = function(progress, complete) { |
|
|
* 点击发送短信事件
|
|
|
*/
|
|
|
$('#send-sms').click(function() {
|
|
|
new Timer().startCountdown(function(counter) {
|
|
|
new Timer().startCountdown(function() {
|
|
|
$.get('/home/installment/starting-service/verify-code', {}).then((result)=> {
|
|
|
console.log(result);
|
|
|
});
|
|
|
}, function(counter) {
|
|
|
// 进度回调
|
|
|
$('#send-sms').text(counter + 's');
|
|
|
}, function() {
|
|
|
// 倒计时结束后再次显示 "获取验证码"
|
|
|
$('#send-sms').text('获取验证码');
|
|
|
});
|
|
|
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
$('#card-no').keydown(function() {
|
|
|
/**
|
|
|
* 银行卡格式化
|
|
|
*/
|
|
|
$('#cardNo').keyup(function() {
|
|
|
const value = $(this).val();
|
|
|
|
|
|
$(this).val(value.replace(/\s[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 '));
|
|
|
$(this).val(value.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ')).trigger('change');
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 表单验证
|
|
|
*/
|
|
|
const validateForm = function() {
|
|
|
const applyButton = $('#apply-button');
|
|
|
|
|
|
if (formModel.userName &&
|
|
|
formModel.identityCardNo &&
|
|
|
formModel.cardNo &&
|
|
|
formModel.mobilePhone &&
|
|
|
formModel.verifyCode &&
|
|
|
formModel.agreements === 'on') {
|
|
|
applyButton.prop('disabled', false);
|
|
|
} else {
|
|
|
applyButton.prop('disabled', true);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 输入框改变时同时更新模型
|
|
|
$('input').on('change', function() {
|
|
|
const name = $(this).attr('name');
|
|
|
|
|
|
if ($(this).is(':checkbox')) {
|
|
|
formModel[name] = $(this).is(':checked') ? $(this).val() : null;
|
|
|
} else {
|
|
|
formModel[name] = $(this).val();
|
|
|
}
|
|
|
|
|
|
validateForm();
|
|
|
});
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 表单提交
|
|
|
*/
|
|
|
$('#apply-form').submit(function() {
|
|
|
console.log(formModel);
|
|
|
}); |
...
|
...
|
|