search.page.js
3.25 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
/**
* search
* @author: sefon 2016-7-12 15:28:22
*/
var $ = require('yoho-jquery');
var yas = require('../common/data-yas');
var lazyLoad = require('yoho-jquery-lazyload');
var product = require('./index/product');
var qs = {};
var $footPage = $('.foot-pager').data('total'),
$productIdArr = [],
$leftUl = $('.sort-container .sort-child-list'),
$leftLi = $leftUl.find('li.active');
var listType = $('.path-nav').attr('listType'),
brandId = $('.path-nav').attr('brandId');
var filterValue = yas.getFilterValue();
var commonParams = {};
$('.good-info .product-id').each(function() {
$productIdArr.push($(this).html());
});
require('../common');
require('../plugins/filter');
require('../plugins/sort-pager');
require('./detail/latest-walk');
product.init(4);
lazyLoad($('img.lazy'), {
failure_limit: 20
});
qs = window.queryString();
commonParams = {
PAGE_NUM: qs.pager || 1,
FILTER_VALUE: filterValue,
L1_SORT: $leftLi.length > 0 ? $leftLi.parent().prev().attr('title') : '',
L2_SORT: $leftLi.find('a').attr('title') || '',
SORT_TYPE: qs.order || 's_n_desc'
};
// 时间戳格式化
function getLocalTime(nS) {
return new Date(parseInt(nS, 10) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
}
/*
* 页面加载完
*/
$(function() {
var loadYas = {
RES_QTY: $footPage || 0,
PRD_LIST: $productIdArr.join(',')
};
var opt = '';
switch (listType) {
case 'search':
loadYas.KEYWORD = qs.query || '';
opt = 'YB_KEYWORD_GOODS_LIST_L';
break;
case 'brand':
loadYas.BRAND_ID = brandId;
opt = 'YB_BRAND_GOODS_LIST_L';
break;
case 'new':
loadYas.SHELF_TIME = 'ALL';
opt = 'YB_NEW_GOODS_LIST_L';
break;
default:// 品类查找sort
loadYas.CATEGORY_ID = qs.misort || qs.msort || '';
opt = 'YB_CATEGORY_GOODS_LIST_L';
break;
}
loadYas = $.extend(loadYas, commonParams);
// 关键词搜索结果页展示时
yas.givePoint(opt, loadYas);
});
// 点击搜索列表商品
$('.good-item-wrapper').click(function() {
var $this = $(this),
proId = $this.find('.product-id').html(),
aIndex = $this.attr('activeIndex'),
pageNum = qs.pager || 1,
limit = qs.limit || 60,
proNum = (parseInt(pageNum, 10) - 1) * limit + parseInt(aIndex, 10),
shelveTime = $this.find('.shelve-time').html();
var loadYas = {
PRD_ID: proId,
PRD_NUM: proNum
};
var opt = '';
switch (listType) {
case 'search':
loadYas.KEYWORD = qs.query || '';
opt = 'YB_KEYWORD_GOODS_LIST_C';
break;
case 'brand':
loadYas.BRAND_ID = brandId;
opt = 'YB_BRAND_GOODS_LIST_C';
break;
case 'new':
loadYas.SHELF_TIME = getLocalTime(shelveTime);
opt = 'YB_NEW_GOODS_LIST_C';
break;
default:// 品类查找sort
loadYas.CATEGORY_ID = qs.misort || qs.msort || '';
opt = 'YB_CATEGORY_GOODS_LIST_C';
break;
}
loadYas = $.extend(loadYas, commonParams);
// 点击搜索列表商品埋点
yas.givePoint(opt, loadYas);
});