repay-record.page.js
1.66 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
/**
* 还款记录
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/04
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
var stopLoading = false,
winH = $(window).height(),
previousScrollTop = 0,
page = 0,
$recordList = $('.record-list');
function getListData(pageData) {
if (stopLoading) {
return;
}
stopLoading = true;
pageData++;
page = pageData;
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/home/installment/repay/get-record',
data: {
page: pageData
},
dataType: 'html',
success: function(data) {
stopLoading = false;
if (data === '') {
stopLoading = true;
if (pageData === 1) {
$('.no-result').show();
}
} else {
$('.no-result').hide();
$recordList.append(data);
}
loading.hideLoadingMask();
},
error: function() {
tip.show('网络断开连接了~');
stopLoading = false;
loading.hideLoadingMask();
}
});
}
function scrollHandler() {
var curScrollTop = $(window).scrollTop();
// 当scroll到1/4$repayList高度后继续请求下一页数据
if (curScrollTop > previousScrollTop &&
(curScrollTop + winH >
$(document).height() - 0.25 * $recordList.height() - 50)) {
getListData(page);
}
previousScrollTop = curScrollTop;
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
getListData(0);