Authored by Aiden Xu

分期订单

... ... @@ -18,17 +18,17 @@
<div class="installment-box">
<div>分期应还</div>
<div>{{avgPrincipalAmt}}</div>
<div>¥{{avgPrincipalAmt}}</div>
</div>
<div class="installment-box">
<div>分期服务费</div>
<div>{{avgFeeAmt}}</div>
<div>¥{{avgFeeAmt}}</div>
</div>
<div class="installment-box">
<div>总计应还</div>
<div>{{amount}}</div>
<div>¥{{amount}}</div>
</div>
</div>
</div>
... ... @@ -37,24 +37,30 @@
{{#each packageList}}
<li>
{{#isPaymentIncomplete status}}
<input id="sort-{{@index}}" type="checkbox" class="installment-check-btn"/>
<input id="sort-{{@index}}" type="checkbox"
class="installment-check-btn installment-term"
data-order-code="{{../orderCode}}"
data-sort-id="{{sortId}}"
data-fee="{{currFeeAmt}}"
data-delay-fee="{{currDealyFeeAmt}}"
data-amount="{{currPrincipalAmt}}"/>
{{/isPaymentIncomplete}}
<label for="sort-{{@index}}">
{{#isPaymentComplete status}}
<span class="detail-index">{{sortId}}.</span>
{{/isPaymentComplete}}
<span class="amount">{{currAmt}}</span>
<span class="amount">¥{{currAmt}}</span>
<div class="fee">
{{currDate}}
本金:{{currPrincipalAmt}}
本金:¥{{currPrincipalAmt}}
{{#if currFeeAmt}}
服务费:{{currFeeAmt}}
服务费:¥{{currFeeAmt}}
{{/if}}
{{#if currDealyFeeAmt}}
逾期服务费:{{currDealyFeeAmt}}
逾期服务费:¥{{currDealyFeeAmt}}
{{/if}}
</div>
<div class="status">
... ...
... ... @@ -18,4 +18,4 @@
{{#if isCurrFee}}<p class="serve-price">含服务费¥<span class="curr-fee">{{round currFeeCount}}</span></p>{{/if}}
</label>
<a href="" class="repayment-btn">立即还款</a>
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -18,7 +18,7 @@
(function(d,c){var e=d.documentElement,a="orientationchange" in window?"orientationchange":"resize",b=function(){var f=e.clientWidth;if(!f){return}if(f>=640){e.style.fontSize="40px"}else{e.style.fontSize=40*(f/640)+"px"}};if(!d.addEventListener){return}b();c.addEventListener(a,b,false);d.addEventListener("DOMContentLoaded",b,false)})(document,window);
</script>
{{#if devEnv}}
<link rel="stylesheet" href="//172.16.6.180:5001/css/index.css">
<link rel="stylesheet" href="//localhost:5001/css/index.css">
{{^}}
<link rel="stylesheet" href="//cdn.yoho.cn/m-yohobuy-node/{{version}}/index.css">
{{/if}}
... ... @@ -41,8 +41,8 @@
<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
{{/wechatShare}}
{{#if devEnv}}
<script src="//172.16.6.180:5001/libs.js"></script>
<script src="//172.16.6.180:5001/{{module}}.{{page}}.js"></script>
<script src="//localhost:5001/libs.js"></script>
<script src="//localhost:5001/{{module}}.{{page}}.js"></script>
{{^}}
<script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/libs.js"></script>
<script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script>
... ...
const $ = require('yoho-jquery');
const Repayment = require('./repayment');
const CHECKBOX_SELECTOR = 'input.installment-term';
require('./overdue-notice');
/**
* 订单状态样式
*/
... ... @@ -14,3 +19,43 @@ $('.status').each(function() {
$(this).addClass('expired');
}
});
const repayment = new Repayment({
onGetSelection: function() {
const ret = [];
$(`${CHECKBOX_SELECTOR}:checked`).each(function() {
const input = $(this);
const data = {
index: input.data('sortId'),
orderCode: input.data('orderCode'),
termNo: input.data('sortId'),
amount: parseFloat(input.data('amount')),
fee: parseFloat(input.data('fee')) + parseFloat(input.data('delayFee'))
};
ret.push(data);
});
return ret;
},
onDeselectAll: function() {
$(`${CHECKBOX_SELECTOR}:checked`).prop('checked', false);
return [];
},
onSelectAll: function() {
$(`${CHECKBOX_SELECTOR}:not(:checked)`).prop('checked', true);
return this.getSelection();
}
});
repayment.setTotal(0);
repayment.setFee(0);
$(`${CHECKBOX_SELECTOR}:checkbox`).click(function() {
repayment.update();
});
... ...
... ... @@ -6,19 +6,10 @@
var $ = require('yoho-jquery');
var $notice = $('.installment-overdue-notice'),
$currAmt = $('.repayment-bottom').find('.curr-amt'),
var $currAmt = $('.repayment-bottom').find('.curr-amt'),
$currFee = $('.repayment-bottom').find('.curr-fee');
$('.repay-list .notice').on('click', function() {
$notice.show();
return false;
});
$('.think-ok, .mask-bg').on('click', function() {
$notice.hide();
});
require('./overdue-notice');
$('.repay-list .cont').on('click', function() {
var $input = $(this).parent().prev(),
... ...
const Repayment = function(options) {
this.settings = Object.assign({
onSelectAll: $.noop,
onDeselectAll: $.noop,
/**
* 获取选择
*
* @returns {Array}
*/
onGetSelection: function() {
return [];
}
}, options);
this.currAmt = $('.repayment-bottom').find('.curr-amt');
this.currFee = $('.repayment-bottom').find('.curr-fee');
this.total = 0;
this.fee = 0;
const self = this;
$('.repayment-btn').on('click', function() {
const path = location.pathname;
const params = {
action: 'go.instalmentRepayment',
params: {
amount: self.total
}
};
$(this).attr('href', path + '?openby:yohobuy=' + JSON.stringify(params));
});
$('#repayment-total').click(()=> {
const isChecked = $(this).data('checked');
if (!isChecked) {
this.settings.onSelectAll.bind(this)();
} else {
this.settings.onDeselectAll.bind(this)();
}
this.update();
$(this).data('checked', !$(this).data('checked'));
});
};
/**
* 格式化金额
*
* @param amount
* @returns {string}
* @private
*/
Repayment.prototype._formatCurrency = function(amount) {
const m = ('' + amount).match(/(\d+)\.?(\d+)?/);
const fixedPart = m[1], floatPart = m[2];
let ret = '0.00';
if (m && m.length === 3) {
ret = `${fixedPart}.${floatPart || '00'}`;
}
return ret;
};
/**
* 设置总金额
*
* @param total
*/
Repayment.prototype.setTotal = function(total) {
this.total = total;
this.currAmt.text(this._formatCurrency(this.total));
};
/**
* 设置费用
*
* @param fee
*/
Repayment.prototype.setFee = function(fee) {
this.fee = fee;
this.currFee.text(this._formatCurrency(this.fee));
};
Repayment.prototype.getSelection = function() {
return this.settings.onGetSelection();
};
Repayment.prototype.update = function() {
const values = this.getSelection();
this.total = 0;
this.fee = 0;
if (values && values.length) {
values.forEach((value)=> {
// 计算还款总额和费用
this.total += value.amount + value.fee;
this.fee += value.fee;
});
}
this.setTotal(this.total);
this.setFee(this.fee);
};
module.exports = Repayment;
... ...