installment-goods.js
3.17 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
/**
* ajax 请求分期专享商品|还款记录
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/17
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
bp = require('./burying-point'),
loading = require('../plugin/loading');
var ListData = function(opt) {
var self = this;
var _scrollHandler = function() {
var curScrollTop = $(window).scrollTop();
// 当scroll到1/4$repayList高度后继续请求下一页数据
if (curScrollTop > this.opt.previousScrollTop &&
(curScrollTop + this.opt.winH >
$(document).height() - 0.25 * this.opt.boxArea.height() - 50)) {
this.getListData();
}
self.opt.previousScrollTop = curScrollTop;
};
self.opt = $.extend({}, {
stopLoading: false,
winH: $(window).height(),
previousScrollTop: 0
}, opt);
$(window).scroll(function() {
window.requestAnimationFrame(_scrollHandler.bind(self));
});
};
require('yoho-jquery-lazyload');
ListData.prototype.getListData = function(page) {
var self = this;
if (page) {
self.opt.page = page;
}
if (self.opt.stopLoading) {
return;
}
self.opt.stopLoading = true;
self.opt.page ++;
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com' + self.opt.url,
data: {
page: this.opt.page
},
xhrFields: {
withCredentials: true
},
dataType: 'html',
success: function(data) {
var $this, $title;
self.opt.stopLoading = false;
if (data === '') {
if (self.opt.noResult && self.opt.page === 1) {
$('.no-result').show();
}
self.opt.stopLoading = true;
} else {
self.opt.boxArea.append(data);
if (self.opt.noResult) {
$('.no-result').hide();
}
if (!self.opt.noResult) { // 有商品列表
// 统计:商品翻页时
bp.setContYas({
op: 'YB_INST_HOME_GDS_LIST',
appop: 'YB_H5_INST_HOME_GDS_LIST_C'
}, {
PRD_NUM: $('.installment-only .good-info').length,
PRD_ID: bp.countGoodsId(),
ACTION_ID: 0,
REC_ID: self.opt.uuid
}, true);
$('img.lazy').lazyload({
effect: 'fadeIn'
});
}
}
if ($('.good-detail-text').length > 0) {
$('.good-detail-text .name').each(function() {
$this = $(this);
$title = $this.find('a');
$title[0].mlellipsis(2);
});
}
loading.hideLoadingMask();
},
error: function() {
tip.show('网络断开连接了~');
self.opt.stopLoading = false;
loading.hideLoadingMask();
}
});
};
module.exports = ListData;