installment.order-detail.page.js
2.23 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
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() {
var ret = [];
$(CHECKBOX_SELECTOR + ':checked').each(function() {
var input = $(this);
var 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;
},
onGetSelectableCount: function() {
return $(CHECKBOX_SELECTOR).length;
},
onDeselectAll: function() {
$(CHECKBOX_SELECTOR + ':checked').prop('checked', false);
return [];
},
onSelectAll: function() {
$(CHECKBOX_SELECTOR + ':not(:checked)').prop('checked', true);
return this.getSelection();
}
});
require('./overdue-notice');
repayment.setTotal(0);
repayment.setFee(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 = $('input:first').data('sortId');
var self = this;
selection.forEach(function(sel) {
if (sel.index - lastIndex > 1) {
isSkipped = true;
} else {
lastIndex = sel.index;
}
});
if (isSkipped) {
setTimeout(function() {
tip.show($(self).is(':checked') ? '请按时间顺序取消选择,不可以跨期' : '请按时间顺序添加还款,不可以跨期');
}, 0);
return false;
}
repayment.update();
});
// 默认选择第一个
$(CHECKBOX_SELECTOR + ':checkbox:first').click();