recommend-for-you-product-desc.js
2.38 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
/**
* 为您优选
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/11/16
*/
let lazyLoad = require('yoho-jquery-lazyload'),
$ = require('yoho-jquery');
let $recommendForYou = $('.recommend-for-you'),
preferenceUrl = $('#preferenceUrl').val(),
winH = $(window).height(),
end = false,
requesting = false;
let RECID = (new Date().getTime() + '_H5_YOHOBUY_' + Math.floor(Math.random() * 1000000 + 1000000) +
'_' + Math.floor(Math.random() * 1000000 + 1000000));
let goodid,
goodIds = [],
prdLoad;
function request() {
if (requesting || end) {
return;
}
requesting = true;
if (preferenceUrl) {
$.get(preferenceUrl, {yhChannel: window.cookie('_Channel') || 'boys'}).then(function(html) {
if (typeof html !== 'string') {
return;
}
$recommendForYou.html(html.replace(/https?:/gi, '')).show();
lazyLoad($recommendForYou.find('img.lazy'));
// 为你优选埋点- 加载
$('.new-goods.container').find('.good-info').each(function() {
goodid = $(this).data('good-id');
if (goodid) {
goodIds.push(goodid);
}
});
prdLoad = JSON.stringify(goodIds).replace(/\[|\]|/g, '');
window.givePoint({
REC_POSE: 100013,
REC_ID: RECID,
PRD_ID: prdLoad,
PRD_NUM: goodIds.length,
ACTION_ID: 0,
PAGE_NUM: 1
});
// 点击商品
$('.good-info').on('click', function() {
let PRD_ID = $(this).data('good-id'),
PRD_NUM = $(this).index();
window.givePoint({
REC_POSE: 100013,
REC_ID: RECID,
PRD_ID: PRD_ID,
PRD_NUM: PRD_NUM,
ACTION_ID: 1,
PAGE_NUM: 1
});
// return false;
});
window.rePosFooter && window.rePosFooter();
}).fail(function() {
$recommendForYou.hide();
});
}
}
function scrollHandler() {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
request();
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});