installment.order-detail.page.js
3.09 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
let $ = require('yoho-jquery');
let Repayment = require('./repayment');
let CHECKBOX_SELECTOR = 'input.installment-term';
let tip = require('plugin/tip');
let bp = require('./burying-point');
let orderCode = ($('.info-box h4').html() || '').replace('订单编号: ', '');
let repayment = new Repayment({
onGetSelection: function() {
let ret = [];
$(CHECKBOX_SELECTOR + ':checked').each(function() {
let input = $(this);
let data = {
index: input.data('sortId'),
orderCode: input.data('orderCode'),
termNo: input.data('sortId'),
amount: parseFloat(input.data('currAmt')),
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() {
let text = $(this).text().trim();
let fade = text.match(/已退款|已结清|已取消/) || [];
let expire = text.match(/已逾期/) || [];
if (fade.length > 0) {
$(this).addClass('faded');
} else if (expire.length > 0) {
$(this).addClass('expired');
}
});
$(CHECKBOX_SELECTOR + ':checkbox').click(function() {
let selection = repayment.getSelection();
let isSkipped = false;
let isChecked = $(this).is(':checked');
let lastIndex = $('input:first').data('sortId');
let curSel = $(this).data('sortId');
let self = this;
selection.forEach(function(sel) {
let index = sel.index + 1;
if (index - lastIndex > 1) {
isSkipped = true;
} else {
lastIndex = index;
}
});
// 取消选择时候判断下标,只能先取消大的
if (selection && selection.length > 0 && !isChecked && curSel < selection[0].index) {
isSkipped = true;
}
if (isSkipped) {
setTimeout(function() {
tip.show($(self).is(':checked') ? '请按时间顺序取消选择,不可以跨期' : '请按时间顺序添加还款,不可以跨期');
}, 0);
return false;
}
repayment.update();
});
// 默认选择第一个
$(CHECKBOX_SELECTOR + ':checkbox:first').click();
$(window).load(function() {
// 统计:进入订单详情页时
bp.setContYas('YB_INST_ORDER_INFO', {
ORDER_CODE: orderCode
}, true);
$('.repayment-btn').on('click', function() {
// 统计:点击立即还款时
bp.setContYas({
op: 'YB_INST_ORDER_TOPAY',
appop: 'YB_H5_INST_ORDER_TOPAY_C'
}, {
ORDER_CODE: orderCode,
PERIODS: $(CHECKBOX_SELECTOR + ':checked').last().data('sortId')
}, true);
});
});