installment.order.page.js
3.71 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var $ = require('yoho-jquery');
var debounce = require('lodash/debounce');
var loading = require('../plugin/loading');
var bp = require('./burying-point');
var hasEnd = false;
var search = {
pageIndex: 1,
type: null
};
/**
* 加载订单明细
*
* @param type
*/
var loadOrderList = function(pageIndex, type) {
if (type && type !== search.type) {
hasEnd = false;
}
if (hasEnd) {
// 没有更多页了
return;
}
if (type && type !== search.type || pageIndex !== search.pageIndex) {
$.get('/home/installment/order.html', {
page: pageIndex,
type: type
}).then(function(result) {
if (result && result.replace(/\s/g, '')) {
search.pageIndex = pageIndex;
} else {
hasEnd = true;
}
if (type !== search.type) {
// 切换TAB时清空列表
$('#order-list').empty();
search.type = type;
}
$('#order-list').append(result);
$('#order-list li').on('click', function() {
loading.showLoadingMask();
});
// 订单状态样式
$('.status').each(function() {
var text = $(this).text();
if (text.indexOf(/已还清|已取消|已退款|已结清|订单取消/)) {
$(this).addClass('faded');
}
});
if ($('#order-list li').length === 0) {
$('#no-result').show();
$('#order-list').hide();
} else {
$('#order-list').show();
$('#no-result').hide();
}
});
}
};
var lastScrollTop = 0;
var windowHeight = $(window).height();
var scrollFn = debounce(function() {
var scrollTop = $(window).scrollTop();
// 当scroll到1/4列表高度后继续请求下一页数据
if (scrollTop > lastScrollTop &&
(scrollTop + windowHeight >
$(document).height() - 0.25 * $('#order-list').height() - 50)) {
loadOrderList(search.pageIndex + 1, search.type);
}
lastScrollTop = scrollTop;
}, 100);
/**
* 顶部TAB
*/
$('.header-tab a').click(function() {
$(this).parent().addClass('active');
$(this).parent().siblings().removeClass('active');
loadOrderList(1, $(this).data('type'));
// 统计: tab 切换
bp.setContYas({
op: 'YB_INST_ORDER_TAB',
appop: 'YB_H5_INST_ORDER_TAB_C'
}, {
LAB_ID: $(this).parent().index()
}, true);
return false;
});
// 默认加载第一页
loadOrderList(search.pageIndex, 1);
// 滚屏分页
$(window).scroll(function() {
scrollFn();
});
((function() {
var tick = 0;
// 显示加载进度条
$(document).ajaxStart(function() {
tick = new Date().getTime();
setTimeout(function() {
if (tick > 0) { // 超过100ms请求仍未结束则显示
loading.showLoadingMask();
}
}, 100);
});
$(document).ajaxStop(function() {
tick = 0;
loading.hideLoadingMask();
});
})());
$(window).load(function() {
// 统计:分期主页点击分期订单进入订单列表页时
bp.setContYas({
op: 'YB_INST_REPAYMENT',
appop: 'YB_H5_INST_REPAYMENT_C'
}, {
POS_ID: $('.installment-order-page').data('posId')
}, true);
$(document).on('click', '.order-list a', function() {
// 统计:点击各个订单时
bp.setContYas({
op: 'YB_INST_ORDER_CLICK',
appop: 'YB_H5_INST_ORDER_C'
}, {
LAB_ID: $('.header-tab .active').index(),
ORDER_CODE: $(this).data('code')
}, false);
});
});