seckill-detail.page.js
12.4 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
require('product/detail/detail.page.css');
var $ = require('yoho-jquery');
var productId = $('#productId').val();
var goodsId = $('#goodsId').val();
var productSkn = $('#productSkn').val();
var brandId = $('#brand-id').val();
var bundleType = $('#bundleType').val();
require('../common');
// 领券
require('./detail/brand-coupon');
// 页面底部异步加载的部分
require('./detail/desc');
// 为你优选
require('./detail/recommend-for-you-product-desc');
window.rePosFooter && window.rePosFooter();
setTimeout(() => {
var Swiper = require('yoho-swiper');
// 顶部swiper
var swiper = new Swiper('.banner-swiper', {
preloadImages: false,
lazyLoading: true,
lazyLoadingInPrevNext: true,
lazyLoadingOnTransitionStart: true,
paginationClickable: true,
pagination: '.banner-top .pagination-inner',
nextButton: '.my-swiper-button-next',
prevButton: '.my-swiper-button-prev',
spaceBetween: 3
});
$('.banner-swiper').click(function() {
$('.banner-top').toggleClass('hover');
swiper.onResize();
});
$('.banner-top-single').click(function() {
$('.banner-top-single').toggleClass('hover');
});
}, 500);
// 动态加载数据
(function() {
function renderInfo(data) {
if (!data) {
return;
}
var dbClass = 'data-bind',
infoDataHbs = require('product/detail/infodata.hbs'),
priceDataHbs = require('product/detail/pricedata.hbs');
// 商品价格
if (data.goodsPrice) {
$('.goods-price>.current-price').text(data.goodsPrice.currentPrice);
$('.goods-price>.previous-price').text(data.goodsPrice.previousPrice);
}
// 限购码
if (!data.noLimitGoodsBtn) {
if (data.canGetLimitCode) {
$('.data-can-get-limit-code').removeClass(dbClass);
}
if (data.codeEmpty) {
$('.data-code-empty').removeClass(dbClass);
}
if (data.gotCode) {
$('.data-got-code').removeClass(dbClass);
}
}
if (data.studentPrice) {
data.studentPrice = Math.round(data.studentPrice.toString().replace('¥', ''));
}
$('#placeholder-pricedata').replaceWith(priceDataHbs(data));
$('#placeholder-infodata').replaceWith(infoDataHbs(data));
if (data.isDepositAdvance === 'Y') {
// 定金预售商品
var tip = require('../plugin/tip');
setTimeout(function() {
$('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() {
tip.show('定金预售商品只能在APP端购买');
return false;
});
}, 200);
}
// 调用秒杀js
require('./tick');
}
if (productId && (goodsId || productSkn)) {
setTimeout(() => {
$.ajax({
type: 'POST',
url: '/product/detail/newinfo',
data: {
id: productId,
goodsId: goodsId,
productSkn: productSkn,
bundleType: bundleType
},
success: (data) => {
// 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页
var reg = /\/product\/show_([\d]+)/;
var regPro = /\/product\/pro_([\d]+)_([\d]+)/;
var regSeckill = /\/product\/seckill/;
// var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/;
var thisHref = window.location.href;
var thisRefer = document.referrer;
if (!regSeckill.test(thisRefer)) {
if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) {
window.location.replace('/product/seckill/show_' + productSkn + '.html');
}
}
// 如果秒杀商品没有吊牌价,显示原销售价
if (data.isSecKill === 'Y' && !data.cartInfo.price) {
$('.previous-price').text(data.cartInfo.salePrice);
}
// 渲染动态数据
renderInfo(data);
// 引入like事件
require('./detail/like');
// 设定购物bar
var $cartBar = $('.cart-bar');
var timer = setInterval(function() {
if ($cartBar) {
window.reMarginFooter('.cart-bar');
clearInterval(timer);
} else {
$cartBar = $('.cart-bar');
}
}, 500);
// 限购
var dialog = require('../plugin/dialog');
$('#limit-sale').on('touchend', function(e) {
var loginUrl = $('#loginUrl').val(),
time,
ifr;
e.stopPropagation();
if (loginUrl) {
window.location = loginUrl;
} else {
dialog.showDialog({
dialogText: '进入有货APP,获取限购码',
hasFooter: {
rightBtnText: '打开Yoho!Buy有货APP'
}
}, function() {
var appUrl = $('input[name="limitCodeUrl"]').val();
ifr = document.createElement('iframe');
ifr.src = appUrl;
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.location.href = appUrl;
time = Date.now();
window.setTimeout(function() {
document.body.removeChild(ifr);
if (Date.now() - time < 3200) {
window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
}
}, 3000);
}, null, true);
$('.dialog-wrapper').off('touchstart').on('touchstart', function(para) {
para.stopPropagation();
if ($(para.target).hasClass('dialog-wrapper')) {
dialog.hideDialog();
}
});
}
});
window.rePosFooter && window.rePosFooter();
}
});
}, 150);
}
}());
/*
* 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化
*/
+ (function(skn, productId, brandId) { // eslint-disable-line
// 模版: 促销, feedback, 店铺
var promotionT = require('product/detail/promotion.hbs');
var feedbackT = require('product/detail/feedbacks.hbs');
var enterStoreT = require('product/detail/enterStore.hbs');
var bundleT = require('product/detail/bundle.hbs');
// placeholder
var $feedbackStore = $('#placeholder-feedback-store');
var $promotion = $('#placeholder-promotion');
var $bundle = $('#placeholder-bundle');
/**
* 渲染 feedback, 店铺, 替换placeholder
* @param data
* {
* enterStore, feedback
* }
* @param $placeholder
*/
function renderFeedbackStore(data, $placeholder) {
var feedbackHtml = feedbackT({
feedbacks: data.feedbacks
});
var enterStoreHtml = enterStoreT({
enterStore: data.enterStore
});
return $placeholder.replaceWith([feedbackHtml, enterStoreHtml]);
}
/**
* 渲染 促销, 替换placeholder
* @param data
* {
* promotion
* }
* @param $placeholder
*/
function renderPromotion(data, $placeholder) {
var promotionHtml = promotionT({
promotion: data.promotion
});
return $placeholder.replaceWith(promotionHtml);
}
/**
* 渲染 套装,替换placeholder
* @param data
* @param $placeholder
* @returns {*}
*/
function renderBundle(data, $placeholder) {
var bundleHtml = bundleT({
bundleData: data.bundleData
});
return $placeholder.replaceWith(bundleHtml);
}
function promotionInit() {
var $goodsDiscount = $('#goodsDiscount');
var $discountFirstItem = $goodsDiscount.find('.first-item');
var $discountFolder = $goodsDiscount.find('.discount-folder');
var $discountArrow = $goodsDiscount.find('.first-item span');
// 初始化goods-discount
if ($discountFolder.children().length === 0) {
$discountFolder.css('display', 'none');
$discountArrow.html('');
}
// goods-discount下拉按钮点击事件
if ($goodsDiscount.length && $discountFolder.children().length > 0) {
$goodsDiscount.on('click', function() {
if ($discountFolder.is(':hidden')) {
$discountFirstItem.removeClass('short-text');
$discountArrow.removeClass('icon-down').addClass('icon-up').html('');
$discountFolder.slideDown();
} else {
$discountFirstItem.addClass('short-text');
$discountArrow.removeClass('icon-up').addClass('icon-down').html('');
$discountFolder.slideUp();
}
});
}
}
// boot
setTimeout(() => {
$.get('/product/detail/sknData.json', {
skn: skn,
productId: productId,
brandId: brandId,
bundleType: bundleType,
gid: goodsId
}).done(function(info) {
// step1: render dom
renderFeedbackStore(info, $feedbackStore);
renderPromotion(info, $promotion);
if (info.bundleData) {
renderBundle(info, $bundle);
$('.bundle').on('touchstart', function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_PACKAGE_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
PRD_ID: productId
})
}, true);
}
});
}
// step2: init js
require('./detail/comments-consults');
require('./detail/consultform'); // TODO
require('./detail/bundle');
promotionInit();
window.rePosFooter && window.rePosFooter();
});
}, 200);
// 加载详情页的返回顶部按钮并注册事件
$(document).scroll(function() {
if ($(document).scrollTop() >= $(document).height() - $(window).height() - 120) {
var top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2;
var left = $('.back-to-top').offset().left - $('.float-top').offset().left;
$('.float-top').addClass('animation').css({
transform: 'translate(' + left + 'px, ' + top + 'px) scale(0, 0)',
});
} else if ($('.product-detail').length && $(document).scrollTop() >= $('.product-detail').offset().top) {
if (!$('.float-top').hasClass('hover') || $('.float-top').hasClass('animation')) {
$('.float-top').addClass('hover').removeClass('animation').removeAttr('style');
}
} else {
if ($('.float-top').hasClass('hover')) {
$('.float-top').removeClass('hover');
}
}
});
// 加载详情页的返回顶部按钮并注册事件-end
}(productSkn, productId, brandId));