installment.order-detail.page.js
2.96 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
var $ = require('yoho-jquery');
var Repayment = require('./repayment');
var CHECKBOX_SELECTOR = 'input.installment-term';
var tip = require('../plugin/tip');
var bp = require('./burying-point');
var orderCode = $('.info-box h4').html().replace('订单编号: ', '');
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('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() {
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 isChecked = $(this).is(':checked');
var lastIndex = $('input:first').data('sortId');
var curSel = $(this).data('sortId');
var self = this;
selection.forEach(function(sel) {
var 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();
setTimeout(function() {
// 统计:进入订单详情页时
bp.setContYas({
ORDER_CODE: orderCode
}, true);
}, 3000);
$('.repayment-btn').on('click', function() {
// 统计:点击立即还款时
bp.setContYas({
ORDER_CODE: orderCode,
PERIODS: $(CHECKBOX_SELECTOR + ':checked').last().data('sortId')
}, true);
return false;
});