good-slide.js
2.87 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
/**
* 你可能喜欢
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2017/03/03
*/
'use strict';
var lazyLoad = require('yoho-jquery-lazyload');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var $ = require('yoho-jquery');
var recommendTpl = require('hbs/product/good-slide.hbs');
var $recommendSlide = $('[data-role="recommend-slide"]');
var yas = require('../common/data-yas');
var $goodsIdArr = [];
require('../plugins/slider');
require('../common/center-slider');
function randomString(len) {
var $chars = 'ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-';
var maxPos = $chars.length,
pwd = '',
i;
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function getSearchRecommend() {
$.ajax({
url: 'http://search.yohobuy.com/product/search/less/recommend',
dataType: 'json',
success: function(data) {
var res;
if (data.code === 200) {
res = data.data.item;
// 若无最近浏览,请隐藏容器
if (res === null) {
$('.bottom-tab-line').hide();
$('[data-role="recommend-slide"]').closest('.goods-slide').hide();
return;
}
$recommendSlide.html(recommendTpl({
item: res,
hasNext: res && res.length > 5,
hasPrev: res && res.length > 5
}));
lazyLoad($recommendSlide.find('.lazy'));
$recommendSlide.find('.goods-slide-item').slider2({
shownum: 5,
isCircle: true
});
$('.recommend-slider .img-item').each(function() {
$goodsIdArr.push($(this).data('id'));
});
initPageYas(); // eslint-disable-line
}
}
});
}
window.getSearchRecommend = getSearchRecommend;
/*
* 页面加载完
*/
function initPageYas() {
var loadYas = {
REC_POSE: 100101,
REC_ID: randomString(40),
PRD_ID: $goodsIdArr.join(','),
PRD_NUM: $goodsIdArr.length,
ACTION_ID: 0,
PAGE_NUM: 1
};
// 关键词搜索结果页展示时
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', loadYas);
}
// 点击你可能喜欢的商品埋点
$('.recommend-slider').on('click', '.img-item', function() {
var $this = $(this);
var proId = $this.data('id');
var loadYas = {
REC_POSE: 100101,
REC_ID: randomString(40),
PRD_ID: proId,
PRD_NUM: $goodsIdArr.indexOf(proId) + 1,
ACTION_ID: 1,
PAGE_NUM: 1
};
// 关键词搜索结果页展示时
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', loadYas);
});
// 数据懒加载
dataLazyLoad.init({cls: '.lazy-load-object-2', threshold: 700});