installment.order-detail.page.js
2.03 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
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({
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() {
const selection = repayment.getSelection();
let isSkipped = false;
let lastIndex = 0;
selection.forEach((sel)=> {
if (sel.index - lastIndex > 1) {
isSkipped = true;
} else {
lastIndex = sel.index;
}
});
if (isSkipped) {
setTimeout(()=> {
tip.show($(this).is(':checked') ? '请按时间顺序取消选择,不可以跨期' : '请按时间顺序添加还款,不可以跨期');
}, 0);
return false;
}
repayment.update();
});