|
|
const $ = require('yoho-jquery');
|
|
|
const tip = require('../plugin/tip');
|
|
|
var $ = require('yoho-jquery');
|
|
|
var tip = require('../plugin/tip');
|
|
|
|
|
|
const Timer = function() {
|
|
|
var Timer = function() {
|
|
|
this.counter = 0;
|
|
|
this.countdownTimer = null;
|
|
|
};
|
|
|
|
|
|
const FormModel = function() {
|
|
|
Object.assign(this, {
|
|
|
var FormModel = function() {
|
|
|
$.extend(this, {
|
|
|
userName: '',
|
|
|
identityCardNo: '',
|
|
|
cardNo: '',
|
...
|
...
|
@@ -17,7 +17,25 @@ const FormModel = function() { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const formModel = new FormModel();
|
|
|
var formModel = new FormModel();
|
|
|
|
|
|
/**
|
|
|
* 表单验证
|
|
|
*/
|
|
|
var validateForm = function() {
|
|
|
var applyButton = $('#apply-button');
|
|
|
|
|
|
if (formModel.userName &&
|
|
|
formModel.identityCardNo &&
|
|
|
formModel.cardNo &&
|
|
|
formModel.mobile &&
|
|
|
formModel.snsCheckCode &&
|
|
|
formModel.agreements === 'on') {
|
|
|
applyButton.prop('disabled', false);
|
|
|
} else {
|
|
|
applyButton.prop('disabled', true);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 倒计时
|
...
|
...
|
@@ -27,6 +45,8 @@ const formModel = new FormModel(); |
|
|
* @param complete 完成回调
|
|
|
*/
|
|
|
Timer.prototype.startCountdown = function(start, tick, complete) {
|
|
|
var self = this;
|
|
|
|
|
|
if (this.counter > 0 || this.countdownTimer) {
|
|
|
return;
|
|
|
} else {
|
...
|
...
|
@@ -43,47 +63,60 @@ Timer.prototype.startCountdown = function(start, tick, complete) { |
|
|
tick.call(this, this.counter);
|
|
|
}
|
|
|
|
|
|
this.complete = complete;
|
|
|
|
|
|
|
|
|
// 开始计时器
|
|
|
this.countdownTimer = setInterval(()=> {
|
|
|
this.counter--;
|
|
|
this.countdownTimer = setInterval(function() {
|
|
|
self.counter--;
|
|
|
|
|
|
if (this.counter <= 0) {
|
|
|
if (self.counter <= 0) {
|
|
|
if (complete) {
|
|
|
clearInterval(this.countdownTimer);
|
|
|
clearInterval(self.countdownTimer);
|
|
|
|
|
|
// 重置计时器
|
|
|
this.counter = 0;
|
|
|
this.countdownTimer = null;
|
|
|
complete.call(this);
|
|
|
self.counter = 0;
|
|
|
self.countdownTimer = null;
|
|
|
complete.call(self);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 完成回调
|
|
|
if (tick && this.counter > 0) {
|
|
|
tick.call(this, this.counter);
|
|
|
if (tick && self.counter > 0) {
|
|
|
tick.call(self, self.counter);
|
|
|
}
|
|
|
}, 1000);
|
|
|
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
Timer.prototype.reset = function() {
|
|
|
if (this.complete) {
|
|
|
this.complete();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 点击发送短信事件
|
|
|
*/
|
|
|
$('#send-sms').click(function() {
|
|
|
new Timer().startCountdown(function() {
|
|
|
$.get('/home/installment/starting-service/verify-code', {
|
|
|
mobile: formModel.mobile
|
|
|
}).then((result)=> {
|
|
|
if (result.code === 200) {
|
|
|
formModel.verifyId = result.data.verifyId;
|
|
|
}
|
|
|
});
|
|
|
}, function(counter) {
|
|
|
// 进度回调
|
|
|
$('#send-sms').text(counter + 's');
|
|
|
}, function() {
|
|
|
// 倒计时结束后再次显示 "获取验证码"
|
|
|
$('#send-sms').text('获取验证码');
|
|
|
$.get('/home/installment/starting-service/verify-code', {
|
|
|
mobile: formModel.mobile
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
formModel.verifyId = result.data.verifyId;
|
|
|
new Timer().startCountdown(function() {
|
|
|
}, function(counter) {
|
|
|
// 进度回调
|
|
|
$('#send-sms').text(counter + 's');
|
|
|
}, function() {
|
|
|
// 倒计时结束后再次显示 "获取验证码"
|
|
|
$('#send-sms').text('获取验证码');
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
tip.show(result.message);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return false;
|
...
|
...
|
@@ -93,14 +126,14 @@ $('#send-sms').click(function() { |
|
|
* 银行卡格式化
|
|
|
*/
|
|
|
$('#cardNo').keyup(function() {
|
|
|
const value = $(this).val();
|
|
|
var value = $(this).val();
|
|
|
var cardNo = $(this).val().replace(/\s/, '');
|
|
|
|
|
|
$(this).val(value.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ')).trigger('change');
|
|
|
}).change(function() {
|
|
|
const cardNo = $(this).val().replace(/\s/, '');
|
|
|
|
|
|
|
|
|
// 获取银行信息
|
|
|
$.get('/home/installment/bank-info', {cardNo: cardNo}).then((result)=> {
|
|
|
$.get('/home/installment/bank-info', {cardNo: cardNo}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
// 设置银行名称
|
|
|
$('#bank-name').text(result.data.bankName);
|
...
|
...
|
@@ -108,31 +141,16 @@ $('#cardNo').keyup(function() { |
|
|
// 设置银行图标
|
|
|
$('#bank-icon').attr('src', '/img/home/bank-icons/' + result.data.bankCode + '.png');
|
|
|
$('#bank-desc').show();
|
|
|
} else {
|
|
|
$('#bank-desc').hide();
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 表单验证
|
|
|
*/
|
|
|
const validateForm = function() {
|
|
|
const applyButton = $('#apply-button');
|
|
|
|
|
|
if (formModel.userName &&
|
|
|
formModel.identityCardNo &&
|
|
|
formModel.cardNo &&
|
|
|
formModel.mobile &&
|
|
|
formModel.snsCheckCode &&
|
|
|
formModel.agreements === 'on') {
|
|
|
applyButton.prop('disabled', false);
|
|
|
} else {
|
|
|
applyButton.prop('disabled', true);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 输入框改变时同时更新模型
|
|
|
$('input').on('change', function() {
|
|
|
const name = $(this).attr('name');
|
|
|
var name = $(this).attr('name');
|
|
|
|
|
|
if ($(this).is(':checkbox')) {
|
|
|
formModel[name] = $(this).is(':checked') ? $(this).val() : null;
|
...
|
...
|
@@ -145,23 +163,29 @@ $('input').on('change', function() { |
|
|
|
|
|
validateForm();
|
|
|
|
|
|
setInterval(()=> {
|
|
|
setInterval(function() {
|
|
|
validateForm();
|
|
|
}, 500);
|
|
|
|
|
|
/**
|
|
|
* 表单提交
|
|
|
*/
|
|
|
$('#apply-form').submit(function() {
|
|
|
$.post('/home/installment/activate-service', formModel).then((result)=> {
|
|
|
const params = { action: 'go.instalmentRepayment' };
|
|
|
|
|
|
$('#apply-button').click(function() {
|
|
|
$.post('/home/installment/activate-service', formModel).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
location.href = `/home/installment/review?openby:yohobuy=${encodeURIComponent(JSON.stringify(params))}`;
|
|
|
if (result.data.result === 'success') {
|
|
|
// 调用成功
|
|
|
$('#hidden-link').click(); // 点击一个隐藏的超链接才能触发APP的URL回调?到底什么鬼?
|
|
|
} else {
|
|
|
// 调用失败
|
|
|
if (result.data.resultMsgType === '1') {
|
|
|
tip.show(result.data.resultMsg);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
tip.show(result.message);
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
return false;
|
|
|
}); |
...
|
...
|
|