repayment-list.page.js
3.4 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* 分期还款
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/04
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip');
var $currAmt = $('.repayment-bottom').find('.curr-amt'),
$currFee = $('.repayment-bottom').find('.curr-fee');
require('./overdue-notice');
// 选择分期统计
function totalChecked(index) {
var total = 0;
// 按时间顺序选择还款,不可以跨期
$('.repay-list input').each(function(key, item) {
if (key < index && $(item).is(':checked')) {
total++;
}
});
return total;
}
// 取消分期统计
function totalCancelChecked(index) {
var total = 0;
$('.repay-list input').each(function(key, item) {
if (key > index && $(item).is(':checked')) {
total++;
}
});
return total;
}
$('.repay-list label').on('click', function() {
var li = $(this).parents('li'),
index = li.index(),
$input = $(this).prev(),
currAmt = +$currAmt.html(),
currFee = +$currFee.html(),
amt = +li.attr('data-curramt'),
fee = +li.attr('data-currfee'),
count = 0,
total = 0;
if ($input.is(':checked')) {
total = totalCancelChecked(index);
if (total === 0) {
$currAmt.html((currAmt - amt).toFixed(2));
$currFee.html((currFee - fee).toFixed(2));
} else {
tip.show('请按时间顺序取消选择,不可以跨期');
return false;
}
} else {
total = totalChecked(index);
if (total === index) {
$currAmt.html((amt + currAmt).toFixed(2));
$currFee.html((fee + currFee).toFixed(2));
} else {
tip.show('请按时间顺序添加还款,不可以跨期');
return false;
}
}
setTimeout(function() {
count = $('.repay-list input:checked').length;
$('#repayment-total').prop('checked', count === $('.repay-list li').length);
}, 0);
});
// 全选||全不选
$('.repayment-bottom label').on('click', function() {
var totalAmt = 0;
var totalFee = 0;
if ($(this).prev().is(':checked')) {
$('.repay-list input').prop('checked', false);
$currAmt.html('0.00');
$currFee.html('0.00');
} else {
$('.repay-list input').prop('checked', true);
$('.repay-list li').each(function() {
totalAmt += (+$(this).attr('data-curramt'));
totalFee += (+$(this).attr('data-currfee'));
});
$currAmt.html(totalAmt.toFixed(2));
$currFee.html(totalFee.toFixed(2));
}
});
$('.repayment-btn').on('click', function() {
var path = location.pathname;
var list = [];
$('.repay-list li').each(function(key, item) {
if ($(item).find('input').is(':checked')) {
list.push({
index: key, // 分期列表序号
orderCode: $(item).attr('data-billno'), // 订单号
termNo: $(item).attr('data-termNo') // 第几期还款
});
}
});
$(this).attr('href',
path + '?openby:yohobuy={"action":"go.instalmentRepayment","params":{"list":' +
encodeURIComponent(JSON.stringify(list)) + ',"amount":' + (+$currAmt.html()) + '}}');
});
// 跳转到还款详情
window.jumpDetail = function(id) {
location.href = '/home/installment/repay/detail?id=' + id;
};