Authored by Aiden Xu

分期订单

... ... @@ -222,7 +222,7 @@ const startingService = (req, res) => {
const activateService = (req, res, next) => {
installmentModel.activateService({
uid: req.cookies.installmentUid || 4,
uid: req.cookies.installmentUid || 53289,
userName: req.body.userName,
identityCardNo: req.body.identityCardNo,
cardNo: req.body.cardNo,
... ...
... ... @@ -59,7 +59,8 @@
数据智能加密,保障您的用卡安全
</div>
<button id="apply-button" class="apply-button" type="submit">下一步</button>
<a href="/home/installment/starting-service?openby:yohobuy=%7B%22action%22%3A%22go.instalmentActivated%22%7D" id="apply-button" class="apply-button">下一步</a>
<a href="#" id="hidden-link"></a>
<div class="provider-mark">
Yoho!Buy信而富联合提供
</div>
... ...
const $ = require('yoho-jquery');
const Repayment = require('./repayment');
const CHECKBOX_SELECTOR = 'input.installment-term';
const tip = require('../plugin/tip');
require('./overdue-notice');
/**
* 订单状态样式
*/
$('.status').each(function() {
const text = $(this).text().trim();
const fade = text.match(/已还款|已退款|已结清|订单取消/) || [];
const expire = text.match(/逾期/) || [];
if (fade.length > 0) {
$(this).addClass('faded');
} else if (expire.length > 0) {
$(this).addClass('expired');
}
});
const repayment = new Repayment({
var $ = require('yoho-jquery');
var Repayment = require('./repayment');
var CHECKBOX_SELECTOR = 'input.installment-term';
var tip = require('../plugin/tip');
var repayment = new Repayment({
onGetSelection: function() {
const ret = [];
var ret = [];
$(`${CHECKBOX_SELECTOR}:checked`).each(function() {
const input = $(this);
$(CHECKBOX_SELECTOR + ':checked').each(function() {
var input = $(this);
const data = {
var data = {
index: input.data('sortId'),
orderCode: input.data('orderCode'),
termNo: input.data('sortId'),
... ... @@ -42,25 +23,43 @@ const repayment = new Repayment({
return ret;
},
onDeselectAll: function() {
$(`${CHECKBOX_SELECTOR}:checked`).prop('checked', false);
$(CHECKBOX_SELECTOR + ':checked').prop('checked', false);
return [];
},
onSelectAll: function() {
$(`${CHECKBOX_SELECTOR}:not(:checked)`).prop('checked', true);
$(CHECKBOX_SELECTOR + ':not(:checked)').prop('checked', true);
return this.getSelection();
}
});
require('./overdue-notice');
repayment.setTotal(0);
repayment.setFee(0);
$(`${CHECKBOX_SELECTOR}:checkbox`).click(function() {
const selection = repayment.getSelection();
let isSkipped = false;
let lastIndex = 0;
/**
* 订单状态样式
*/
$('.status').each(function() {
var text = $(this).text().trim();
var fade = text.match(/已还款|已退款|已结清|订单取消/) || [];
var expire = text.match(/逾期/) || [];
if (fade.length > 0) {
$(this).addClass('faded');
} else if (expire.length > 0) {
$(this).addClass('expired');
}
});
$(CHECKBOX_SELECTOR + ':checkbox').click(function() {
var selection = repayment.getSelection();
var isSkipped = false;
var lastIndex = 0;
var self = this;
selection.forEach((sel)=> {
selection.forEach(function(sel) {
if (sel.index - lastIndex > 1) {
isSkipped = true;
} else {
... ... @@ -69,8 +68,8 @@ $(`${CHECKBOX_SELECTOR}:checkbox`).click(function() {
});
if (isSkipped) {
setTimeout(()=> {
tip.show($(this).is(':checked') ? '请按时间顺序取消选择,不可以跨期' : '请按时间顺序添加还款,不可以跨期');
setTimeout(function() {
tip.show($(self).is(':checked') ? '请按时间顺序取消选择,不可以跨期' : '请按时间顺序添加还款,不可以跨期');
}, 0);
return false;
}
... ...
const $ = require('yoho-jquery');
const search = {
var $ = require('yoho-jquery');
var search = {
pageIndex: 1,
type: 1
};
... ... @@ -10,12 +10,12 @@ const search = {
*
* @param type
*/
const loadOrderList = (pageIndex, type)=> {
var loadOrderList = function(pageIndex, type) {
if (type) {
$.get('/home/installment/order.html', {
page: pageIndex,
type: type
}).then((result)=> {
}).then(function(result) {
if (type !== search.type) {
// 切换TAB时清空列表
$('#order-list').empty();
... ... @@ -26,7 +26,7 @@ const loadOrderList = (pageIndex, type)=> {
// 订单状态样式
$('.status').each(function() {
const text = $(this).text();
var text = $(this).text();
if (text.indexOf(/已还清|已取消|已退款|已结清|订单取消/)) {
$(this).addClass('faded');
... ... @@ -51,7 +51,7 @@ $('.header-tab a').click(function() {
loadOrderList(search.pageIndex, 1);
// TODO: 滚屏分页
$(window).scroll(()=> {
$(window).scroll(function() {
// var scrollTop = $(window).scrollTop();
... ...
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;
});
... ...
const Repayment = function(options) {
this.settings = Object.assign({
var Repayment = function(options) {
var self = this;
this.settings = $.extend({}, {
onSelectAll: $.noop,
... ... @@ -20,12 +22,11 @@ const Repayment = function(options) {
this.total = 0;
this.fee = 0;
const self = this;
$('.repayment-btn').on('click', function() {
const path = location.pathname;
var path = location.pathname;
const params = {
var params = {
action: 'go.instalmentRepayment',
list: self.getSelection()
};
... ... @@ -33,17 +34,17 @@ const Repayment = function(options) {
$(this).attr('href', path + '?openby:yohobuy=' + encodeURIComponent(JSON.stringify(params)));
});
$('#repayment-total').click(()=> {
const isChecked = $(this).data('checked');
$('#repayment-total').click(function() {
var isChecked = $(this).data('checked');
if (!isChecked) {
this.settings.onSelectAll.bind(this)();
self.settings.onSelectAll.bind(self)();
} else {
this.settings.onDeselectAll.bind(this)();
self.settings.onDeselectAll.bind(self)();
}
this.update();
$(this).data('checked', !$(this).data('checked'));
self.update();
$(self).data('checked', !$(self).data('checked'));
});
};
... ... @@ -55,13 +56,13 @@ const Repayment = function(options) {
* @private
*/
Repayment.prototype._formatCurrency = function(amount) {
const m = ('' + amount).match(/(\d+)\.?(\d+)?/);
const fixedPart = m[1], floatPart = m[2];
var m = ('' + amount).match(/(\d+)\.?(\d+)?/);
var fixedPart = m[1], floatPart = m[2];
let ret = '0.00';
var ret = '0.00';
if (m && m.length === 3) {
ret = `${fixedPart}.${floatPart || '00'}`;
ret = fixedPart + (floatPart || '00');
}
return ret;
... ... @@ -96,16 +97,17 @@ Repayment.prototype.getSelection = function() {
};
Repayment.prototype.update = function() {
const values = this.getSelection();
var values = this.getSelection();
var self = this;
this.total = 0;
this.fee = 0;
if (values && values.length) {
values.forEach((value)=> {
values.forEach(function(value) {
// 计算还款总额和费用
this.total += value.amount + value.fee;
this.fee += value.fee;
self.total += value.amount + value.fee;
self.fee += value.fee;
});
}
... ...
... ... @@ -22,6 +22,7 @@
font-size: 27px;
width: 473px;
height: 90px;
line-height: 90px;
margin: 0 auto;
display: block;
... ...