plusstar-index.page.js
10.5 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
Swiper = require('yoho-swiper'),
loading = require('../plugin/loading'),
debounce = require('lodash/debounce');
var plusstar = {},
$footer = $('#yoho-footer');
var windowHeight = $(window).height();
var scrollFn,
scrollTop,
RECPOSE,
isApp,
searching = false,
speckParamApp = {
udid: '',
apt: '',
sid: ''
};
require('yoho-jquery-lazyload');
require('../common');
plusstar = {
common: {
codeDefault: '',
page: 1,
pagesize: 20,
pageTotal: 1,
productSkns: []
},
init: function() {
var that = this,
$liDom,
$tabUlDom;
$tabUlDom = $('.plusstar-page .tab-nav ul');
$tabUlDom.find('li').css({
width: 100 / $tabUlDom.find('li').length + '%'
});
$tabUlDom.find('li').each(function() {
// 重新进入滑动位置清除
window.setCookie($(this).data('code'), 0);
});
// 事情委托机制
$tabUlDom.bind('click', function(event) {
$liDom = $(event.target).closest('li');
if ($liDom.hasClass('focus')) {
return true;
}
$(this).find('li').removeClass('focus');
$liDom.addClass('focus');
that.ParentLiDom = $liDom;// 保留当前tab先中的对象
that.tabNav($liDom.data('code'));
// 点击潮流优选上方的TAB按钮时
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_FASHION_TAB_C',
param: JSON.stringify($.extend({
TAB_ID: $liDom.index() + 1
}, speckParamApp))
}, true);
window._yas.sendCustomInfo({
op: 'YB_FASHION_HOME_L',
param: JSON.stringify($.extend({
TAB_ID: that.ParentLiDom.index() + 1
}, speckParamApp))
}, true);
}
});
// start -- 默认选中
$liDom = $tabUlDom.find('li.focus');
if ($liDom.length <= 0) {
// 默认第一个
$liDom = $('.plusstar-page .tab-nav ul li:eq(0)');
}
$tabUlDom.find('li').removeClass('focus');
$liDom.addClass('focus');
that.ParentLiDom = $liDom;// 保留当前tab先中的对象
that.tabNav($liDom.data('code'));
// ent -- 默认选中
setTimeout(function() {
that._yas();
}, 1000);
},
_yas: function() {
// http://redmine.yoho.cn/issues/12224
var that = this;
if (!window._yas || !window._yas.sendCustomInfo) {
return false;
}
RECPOSE = that.ParentLiDom.index() !== 0 ? 100015 : 100014;
$('.plusstar-resources').bind('click', function(event) {
var $dom, $domA, index;
if ($(event.target).closest('.good-info').length > 0) {
// 商品单击埋点
$dom = $(event.target).closest('.good-info');
index = $dom.index() + 1;
window.givePoint($.extend({
REC_POSE: RECPOSE,
PRD_ID: $dom.data('good-id'),
ORDER_CODE: '',
PRD_NUM: index % that.common.pagesize === 0 ? that.common.pagesize : index % that.common.pagesize,
ACTION_ID: 1,
page_num: Math.ceil(index / that.common.pagesize)
}, speckParamApp));
} else if ($(event.target).closest('.banner-top').length > 0) {
// 头部banner楼层埋点
$dom = $(event.target).closest('li');
index = $dom.index() + 1;
window._yas.sendCustomInfo({
op: 'YB_FASHION_FLR_C',
param: JSON.stringify($.extend({
TAB_ID: that.ParentLiDom.index() + 1,
F_ID: $dom.closest('ul').data('id'),
F_NAME: '焦点图',
F_URL: encodeURIComponent($dom.find('a').attr('href').replace(/\"/g, '\\"')),
F_INDEX: 1,
I_INDEX: index % 2 + 1// banner,li是双倍的
}, speckParamApp))
}, true);
} else if ($(event.target).closest('.speck-title-image a').length > 0) {
// 各楼层埋点
$dom = $(event.target).closest('.speck-title-image');
$domA = $(event.target).closest('.speck-title-image a');
window._yas.sendCustomInfo({
op: 'YB_FASHION_FLR_C',
param: JSON.stringify($.extend({
TAB_ID: that.ParentLiDom.index() + 1,
F_ID: $dom.data('fid'),
F_NAME: $dom.data('name'),
F_URL: encodeURIComponent($domA.attr('href').replace(/\"/g, '\\"')),
F_INDEX: $dom.index() + 1,
I_INDEX: $domA.hasClass('more') ? 0 : ($domA.index() + 1)
}, speckParamApp))
}, true);
}
});
// 潮流优选首页加载时
window._yas.sendCustomInfo({
op: 'YB_FASHION_HOME_L',
param: JSON.stringify($.extend({
TAB_ID: that.ParentLiDom.index() + 1
}, speckParamApp))
}, true);
},
tabNav: function(code) {
var that = this;
this.common.codeDefault = code;// 记住最后一次的tab code
this.common.page = 1;// 商品列表从第一页开始
searching = false;// 初始化翻页
$.ajax({
type: 'GET',
url: '/guang/plusstar/resources-template',
data: {
code: code,
uid: window.queryString.uid,
app_version: isApp,
yh_channel: that.ParentLiDom.index() + 1
},
dataType: 'html',
success: function(data) {
var productSkns = '';
$('.plusstar-resources').html(data);
if (data === '') {
tip.show('没有更多内容了');
return true;
}
// 记录切换tab位置
$(document).scrollTop(window.cookie(code) || 0);
that.resInit();
$('.plusstar-resources').find('img.lazy').lazyload();
productSkns = $(data).find('.product-skns').val();
if (productSkns) {
that.common.productSkns = productSkns.split(',');
}
that.common.pageTotal = Math.ceil(that.common.productSkns.length / that.common.pagesize);
},
error: function() {
tip.show('网络断开连接了~');
}
});
},
resInit: function() {
// 头部banner轮播
if ($('.banner-swiper').find('li').size() > 1) {
new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
},
goodsList: function() {
var that = this,
skn = [];
if (searching) {
return;
}
searching = true;
if (that.common.page > that.common.pageTotal) {
return false;
}
loading.showLoadingMask();
skn = that.common.productSkns.slice((that.common.page - 1) * that.common.pagesize, that.common.page * that.common.pagesize);
$.ajax({
type: 'POST',
url: '/guang/plusstar/resources-goodsList',
timeout: 5000,
data: {
productSkn: skn.join(','),
app_version: isApp
},
dataType: 'html',
success: function(data) {
skn = [];
loading.hideLoadingMask();
searching = false;
that.common.page++;
if (data === '') {
return true;
}
$.each($(data).siblings('.good-info'), function() {
skn.push($(this).data('good-id'));
});
window.givePoint($.extend({
REC_POSE: RECPOSE,
PRD_ID: skn.join(','),
ORDER_CODE: '',
PRD_NUM: that.common.pagesize,
ACTION_ID: 0,
page_num: that.common.page - 1
}, speckParamApp));
$('.plusstar-resources .goods').append(data);
$('.plusstar-resources .goods').find('img.lazy:not([src])').lazyload();
$('.resources .goods .page-total').remove();
},
error: function() {
searching = false;
tip.show('网络断开连接了~');
loading.hideLoadingMask();
}
});
}
};
scrollFn = debounce(function() {
scrollTop = $(document).scrollTop();
// 保留滑动位置,产品要求
window.setCookie(plusstar.common.codeDefault, $(this).scrollTop());
// 当scroll到最后一列商品的高度后继续请求下一页数据
if (400 + scrollTop >= $(document).height() - windowHeight) {
plusstar.goodsList();
}
}, 200);
$(function() {
isApp = window.queryString.app_version || window.queryString.appVersion;
if (isApp) {
speckParamApp = {
udid: window.queryString.udid || window.queryString.anbiudid || '',
apt: window.queryString.client_type || '',
sid: window.queryString.session_id || '',
};
}
// 男:1,女:2,潮童:3,创意生活:4
speckParamApp.CID = window.queryString.yh_channel || window._ChannelVary[window.cookie('_Channel')] || 1;
if (!isApp) {
$('.tab-nav').css({
position: 'relative'
});
$footer.css({
'max-width': '650px'
}).before(
'<div style="height: ' + parseInt($footer.css('height'), 0) + 'px"></div>'
);
}
plusstar.init();
// 滚动翻页
$(window).scroll(function() {
scrollFn();
});
});