Merge branch 'feature/reSeckill' into 'release/5.5'
秒杀商品详情页公用商品详情页js See merge request !354
Showing
5 changed files
with
349 additions
and
1082 deletions
@@ -5,7 +5,8 @@ | @@ -5,7 +5,8 @@ | ||
5 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
6 | 6 | ||
7 | const detailModel = require('../models/detail'); | 7 | const detailModel = require('../models/detail'); |
8 | -const newDetailModel = require('../models/seckill-detail'); | 8 | +const seckillDetailModel = require('../models/seckill-detail'); |
9 | +const newDetailModel = require('../models/new-detail'); | ||
9 | const listModel = require('../models/list'); | 10 | const listModel = require('../models/list'); |
10 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 11 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
11 | const helpers = global.yoho.helpers; | 12 | const helpers = global.yoho.helpers; |
@@ -164,7 +165,7 @@ const newDetail = { | @@ -164,7 +165,7 @@ const newDetail = { | ||
164 | // 获取秒杀信息 | 165 | // 获取秒杀信息 |
165 | getSeckillData(req, res) { | 166 | getSeckillData(req, res) { |
166 | 167 | ||
167 | - newDetailModel.getSeckillData({ | 168 | + seckillDetailModel.getSeckillData({ |
168 | 169 | ||
169 | productskn: req.params.productskn | 170 | productskn: req.params.productskn |
170 | 171 |
@@ -3,396 +3,9 @@ | @@ -3,396 +3,9 @@ | ||
3 | */ | 3 | */ |
4 | 'use strict'; | 4 | 'use strict'; |
5 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
6 | -const commentModel = require('./consult-comment'); | ||
7 | -const bundle = require('./bundle'); | ||
8 | -const productProcess = require(`${utils}/product-process`); | ||
9 | - | ||
10 | - | ||
11 | const api = global.yoho.API; | 6 | const api = global.yoho.API; |
12 | -const helpers = global.yoho.helpers; | ||
13 | - | ||
14 | -const tool = { | ||
15 | - prodessDetailData(origin) { | ||
16 | - let dest = {}; // 结果输出 | ||
17 | - | ||
18 | - // 商品名称 | ||
19 | - if (!origin.product_name) { | ||
20 | - return dest; | ||
21 | - } | ||
22 | - | ||
23 | - dest.goodsName = origin.product_name; | ||
24 | - | ||
25 | - // 是否是虚拟商品 | ||
26 | - // dest.virtualGoods = (origin.attribute * 1 === 3); | ||
27 | - | ||
28 | - // 活动促销短语 | ||
29 | - origin.market_phrase && origin.market_phrase !== ' ' && (dest.marketPhrase = origin.market_phrase); | ||
30 | - | ||
31 | - // 商品促销短语 | ||
32 | - origin.sales_phrase && origin.sales_phrase !== ' ' && (dest.goodsSubtitle = origin.sales_phrase); | ||
33 | - | ||
34 | - // 商品标签 | ||
35 | - if (origin.tags) { | ||
36 | - let productTags = {}; | ||
37 | - | ||
38 | - _.forEach(origin.tags, function(value) { | ||
39 | - productTags[value] = true; | ||
40 | - }); | ||
41 | - | ||
42 | - dest.tags = productTags; | ||
43 | - } | ||
44 | - | ||
45 | - // 商品价格 | ||
46 | - let goodsPrice = { | ||
47 | - currentPrice: origin.format_sales_price === '0' ? origin.format_market_price : origin.format_sales_price | ||
48 | - }; | ||
49 | - | ||
50 | - if (origin.format_sales_price !== '0' && origin.format_market_price !== origin.format_sales_price) { | ||
51 | - goodsPrice.previousPrice = origin.format_market_price; | ||
52 | - } | ||
53 | - | ||
54 | - dest.goodsPrice = goodsPrice; | ||
55 | - | ||
56 | - // 商品返回 YOHO 币 | ||
57 | - // origin.yohoCoinNum && (dest.commodityReturn = origin.yohoCoinNum); | ||
58 | - | ||
59 | - // 上市期 | ||
60 | - origin.expect_arrival_time && (dest.periodOfMarket = origin.expect_arrival_time); | ||
61 | - | ||
62 | - | ||
63 | - // 品牌信息 | ||
64 | - if (origin.shop_id) { | ||
65 | - let extra = `?productSkn=${origin.product_skn}&shopId=${origin.shop_id}`; | ||
66 | - | ||
67 | - dest.preferenceUrl = `/product/detail/preference${extra}`; | ||
68 | - } | ||
69 | - | ||
70 | - // dest.brandId = origin.brand_info && origin.brand_info.brand_id || 0; | ||
71 | - dest.brandId = _.get(origin, 'brand_info.brand_id', 0); | ||
72 | - dest.productSkn = origin.product_skn; | ||
73 | - dest.id = origin.product_id; | ||
74 | - | ||
75 | - dest.goodsId = origin.goods_id; | ||
76 | - dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售 | ||
77 | - dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀 | ||
78 | - dest.isLimitBuy = origin.isLimitBuy; // 是否 限购 | ||
79 | - dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售 | ||
80 | - dest.bundleType = origin.bundle_type; // 商品活动标记 | ||
81 | - | ||
82 | - // 自定义 属性 | ||
83 | - dest.showCoupon = !( | ||
84 | - dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale | ||
85 | - ); // 商品有限购、秒杀、定金预售、普通预售 不显示领 | ||
86 | - | ||
87 | - // 20170113 要求关闭商品详情页面领券功能 | ||
88 | - // dest.showCoupon = false; | ||
89 | - | ||
90 | - // 商品信息 | ||
91 | - if (origin.goods_list.length) { | ||
92 | - let goodsGroup = []; | ||
93 | - | ||
94 | - // pagecache重构 | ||
95 | - _.forEach(origin.goods_list, function(value) { | ||
96 | - | ||
97 | - // 商品分组 | ||
98 | - if (value.images_list) { | ||
99 | - _.forEach(value.images_list, function(good) { | ||
100 | - goodsGroup.push({ | ||
101 | - goodsId: value.goods_id, | ||
102 | - img: good.image_url | ||
103 | - }); | ||
104 | - }); | ||
105 | - } | ||
106 | - }); | ||
107 | - | ||
108 | - | ||
109 | - // 商品图:多个 | ||
110 | - if (goodsGroup.length > 1) { | ||
111 | - let bannerList = []; | ||
112 | - | ||
113 | - _.forEach(goodsGroup, function(value) { | ||
114 | - value.img = _.replace(value.img, '/quality/80', '/quality/70'); | ||
115 | - | ||
116 | - bannerList.push({ | ||
117 | - img: value.img | ||
118 | - }); | ||
119 | - }); | ||
120 | - | ||
121 | - dest.bannerTop = { | ||
122 | - list: bannerList | ||
123 | - }; | ||
124 | - } else if (goodsGroup[0]) { | ||
125 | - dest.bannerTop = { | ||
126 | - img: goodsGroup[0].img | ||
127 | - }; | ||
128 | - } | ||
129 | - } | ||
130 | - | ||
131 | - // 底部简介URL链接 | ||
132 | - dest.introUrl = '/product/detail/intro/' + origin.product_skn; | ||
133 | - | ||
134 | - return dest; | ||
135 | - }, | ||
136 | - | ||
137 | - /** | ||
138 | - * 处理品牌关联店铺信息 | ||
139 | - * @param {array} | ||
140 | - * @return {array} | ||
141 | - */ | ||
142 | - processShopsInfo(data) { | ||
143 | - let enterStore = []; | ||
144 | - | ||
145 | - _.forEach(data, function(value) { | ||
146 | - let shopInfo = { | ||
147 | - img: value.brand_ico, | ||
148 | - storeName: value.brand_name | ||
149 | - }; | ||
150 | - | ||
151 | - if (value.shop_id) { | ||
152 | - shopInfo.url = helpers.urlFormat('/product/index/brand', { | ||
153 | - shop_id: value.shop_id | ||
154 | - }); | ||
155 | - } else { | ||
156 | - shopInfo.url = helpers.urlFormat('', null, value.brand_domain); | ||
157 | - } | ||
158 | - | ||
159 | - enterStore.push(shopInfo); | ||
160 | - }); | ||
161 | - return enterStore; | ||
162 | - }, | ||
163 | - | ||
164 | - /** | ||
165 | - * 处理商品 feedback | ||
166 | - * @param data feedback要处理数据 | ||
167 | - * { | ||
168 | - * comment, defaultConsult, userConsult | ||
169 | - * } | ||
170 | - * @param productId 商品id | ||
171 | - * @return feedback | ||
172 | - */ | ||
173 | - processFeedback(data, productId) { | ||
174 | - // let {comment, defaultConsult, userConsult} = data; | ||
175 | - let comment = data.comment; | ||
176 | - let defaultConsult = data.defaultConsult; | ||
177 | - let userConsult = data.userConsult; | ||
178 | - | ||
179 | - let feedbacks = {consults: [], consultsNum: 0}; | ||
180 | - | ||
181 | - Object.assign(feedbacks, comment); | ||
182 | - | ||
183 | - // 商品评价 | ||
184 | - feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', { | ||
185 | - product_id: productId | ||
186 | - }); | ||
187 | - | ||
188 | - /* 如果有用户咨询,显示用户咨询,否则显示常见问题 */ | ||
189 | - let obj = {}; | ||
190 | - | ||
191 | - if (userConsult.total) { | ||
192 | - obj = { | ||
193 | - commonConsults: false, | ||
194 | - consultsNum: parseInt(userConsult.total, 10), | ||
195 | - consults: _.take(userConsult.list, 2) | ||
196 | - }; | ||
197 | - } else if (!_.isEmpty(defaultConsult) && !_.get(comment, 'consultsNum', 0)) { | ||
198 | - obj = { | ||
199 | - commonConsults: true, | ||
200 | - consultsNum: true, | ||
201 | - consults: _.take(defaultConsult.faq, 2) | ||
202 | - }; | ||
203 | - } | ||
204 | - | ||
205 | - Object.assign(feedbacks, obj); | ||
206 | - | ||
207 | - if (_.get(feedbacks, 'consultsNum')) { | ||
208 | - feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', { | ||
209 | - product_id: productId, | ||
210 | - total: feedbacks.consultsNum | ||
211 | - }); | ||
212 | - } else { | ||
213 | - feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', { | ||
214 | - product_id: productId | ||
215 | - }); | ||
216 | - } | ||
217 | - return feedbacks; | ||
218 | - }, | ||
219 | - | ||
220 | - /** | ||
221 | - * 套餐数据处理 | ||
222 | - * @param bundleData | ||
223 | - * @param skn | ||
224 | - * @returns {{}} | ||
225 | - */ | ||
226 | - processBundle(bundleData, skn, gid) { | ||
227 | - let subPrice = _.get(bundleData, 'bundleInfo.subPrice', 0); | ||
228 | - | ||
229 | - return { | ||
230 | - title: '优惠套装', | ||
231 | - href: helpers.urlFormat('/product/bundle/detail', {skn: skn, gid: gid}), | ||
232 | - description: subPrice ? '立省¥' + subPrice : 0, | ||
233 | - productList: productProcess.processProductList(bundleData && bundleData.productList) | ||
234 | - }; | ||
235 | - }, | ||
236 | - | ||
237 | - /** | ||
238 | - * 处理量贩数据 | ||
239 | - * @param finalResult | ||
240 | - * @param bundleData | ||
241 | - */ | ||
242 | - processDiscount(finalResult, bundleData) { | ||
243 | - finalResult.discountBuy = { | ||
244 | - num: _.get(bundleData, 'bundleInfo.bundleCount', 1), | ||
245 | - promotionPhrase: _.get(bundleData, 'bundleInfo.promotionPhrase', ''), | ||
246 | - discount: _.get(bundleData, 'bundleInfo.discount', 1) | ||
247 | - }; | ||
248 | - | ||
249 | - let oldPromotion = finalResult.promotion; | ||
250 | - | ||
251 | - finalResult.promotion = [{ | ||
252 | - promotionTitle: _.get(bundleData, 'bundleInfo.promotionPhrase', ''), | ||
253 | - promotionType: '量贩' | ||
254 | - }]; | ||
255 | - | ||
256 | - _.forEach(oldPromotion, value => { | ||
257 | - finalResult.promotion.push(value); | ||
258 | - }); | ||
259 | - } | ||
260 | -}; | ||
261 | 7 | ||
262 | const newDetail = { | 8 | const newDetail = { |
263 | - getProductData(data) { | ||
264 | - let params = { | ||
265 | - method: 'app.product.data' | ||
266 | - }; | ||
267 | - | ||
268 | - if (data.id) { // 通过 productId 获取商品详情 | ||
269 | - Object.assign(params, { | ||
270 | - product_id: data.id | ||
271 | - }); | ||
272 | - } else if (data.productSkn) { // 通过 productSkn 获取商品详情 | ||
273 | - Object.assign(params, { | ||
274 | - product_skn: data.productSkn | ||
275 | - }); | ||
276 | - } | ||
277 | - | ||
278 | - return api.get('', params, { | ||
279 | - code: 200, | ||
280 | - cache: true | ||
281 | - }).then(result => { | ||
282 | - if (!result || result.code === 500 || !result.data) { | ||
283 | - return {}; | ||
284 | - } | ||
285 | - | ||
286 | - result.data.goods_id = data.goodsId; | ||
287 | - | ||
288 | - return tool.prodessDetailData(result.data); | ||
289 | - }); | ||
290 | - }, | ||
291 | - | ||
292 | - /* | ||
293 | - 获取 促销,评论,咨询,品牌信息 | ||
294 | - */ | ||
295 | - querySknData(params) { | ||
296 | - let brandId = params.brandId; | ||
297 | - let productId = params.productId; | ||
298 | - let skn = params.skn; | ||
299 | - let gid = params.gid; | ||
300 | - | ||
301 | - let apiArray = [ | ||
302 | - this.queryShopsByBrandId(brandId), // 0 品牌信息 | ||
303 | - commentModel.getCommentInfo({ | ||
304 | - productId: productId | ||
305 | - }), // 1 评论信息 | ||
306 | - commentModel.getCommonConsult(), // 2 默认咨询信息 | ||
307 | - commentModel.getConsults(productId, 1, 2), // 3 咨询列表 | ||
308 | - this.queryPromotion(skn), // 4 促销活动 | ||
309 | - ]; | ||
310 | - | ||
311 | - if (params.bundleType) { | ||
312 | - apiArray.push(bundle.getBundleBySkn(skn)); | ||
313 | - } | ||
314 | - | ||
315 | - return Promise.all(apiArray).then(info => { | ||
316 | - let finalResult = { | ||
317 | - promotion: null, | ||
318 | - enterStore: null, | ||
319 | - feedbacks: { | ||
320 | - consults: [], | ||
321 | - consultsNum: 0 | ||
322 | - }, | ||
323 | - }; | ||
324 | - | ||
325 | - finalResult.promotion = info[4]; | ||
326 | - finalResult.enterStore = info[0]; | ||
327 | - finalResult.feedbacks = tool.processFeedback({ | ||
328 | - comment: info[1], | ||
329 | - defaultConsult: info[2], | ||
330 | - userConsult: info[3] | ||
331 | - }, productId); | ||
332 | - | ||
333 | - let bundleData = _.get(info[5], 'data', null); | ||
334 | - | ||
335 | - /* 套装 */ | ||
336 | - if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 1) { | ||
337 | - finalResult.bundleData = tool.processBundle(bundleData, skn, gid); | ||
338 | - } | ||
339 | - | ||
340 | - /* 量贩 */ | ||
341 | - if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 2) { | ||
342 | - tool.processDiscount(finalResult, bundleData); | ||
343 | - } | ||
344 | - | ||
345 | - return finalResult; | ||
346 | - }); | ||
347 | - }, | ||
348 | - | ||
349 | - // ------------------------------接口 | ||
350 | - | ||
351 | - /* | ||
352 | - 接口: 根据BrandID, 查询品牌信息 | ||
353 | - */ | ||
354 | - queryShopsByBrandId(brandId) { | ||
355 | - let params = { | ||
356 | - method: 'app.shop.queryShopsByBrandId', | ||
357 | - brand_id: brandId | ||
358 | - }; | ||
359 | - | ||
360 | - let cacheConf = { | ||
361 | - cache: true | ||
362 | - }; | ||
363 | - | ||
364 | - return api.get('', params, cacheConf) | ||
365 | - .then(result => { | ||
366 | - if (result && result.code === 200) { | ||
367 | - return tool.processShopsInfo(result.data); | ||
368 | - } | ||
369 | - return []; | ||
370 | - }, () => []); | ||
371 | - }, | ||
372 | - | ||
373 | - /** | ||
374 | - * 接口: 商品 促销活动 | ||
375 | - */ | ||
376 | - queryPromotion(skn) { | ||
377 | - let params = { | ||
378 | - method: 'app.product.promotion', | ||
379 | - product_skn: skn | ||
380 | - }; | ||
381 | - | ||
382 | - let cacheConf = { | ||
383 | - cache: true | ||
384 | - }; | ||
385 | - | ||
386 | - return api.get('', params, cacheConf) | ||
387 | - .then(result => { | ||
388 | - if (result && result.code === 200) { | ||
389 | - return result.data; | ||
390 | - } | ||
391 | - | ||
392 | - return {}; | ||
393 | - }); | ||
394 | - }, | ||
395 | - | ||
396 | /** | 9 | /** |
397 | * 获取秒杀列表 | 10 | * 获取秒杀列表 |
398 | */ | 11 | */ |
@@ -410,7 +23,7 @@ const newDetail = { | @@ -410,7 +23,7 @@ const newDetail = { | ||
410 | .catch() | 23 | .catch() |
411 | .then(result => { | 24 | .then(result => { |
412 | let data = {}; | 25 | let data = {}; |
413 | - | 26 | + |
414 | if (result.data) { | 27 | if (result.data) { |
415 | data = result.data; | 28 | data = result.data; |
416 | if (data.storageSum > 0) { | 29 | if (data.storageSum > 0) { |
public/js/product/new-detail.js
0 → 100644
1 | +require('product/detail/detail.page.css'); | ||
2 | +var $ = require('yoho-jquery'); | ||
3 | +var productId = $('#productId').val(); | ||
4 | +var goodsId = $('#goodsId').val(); | ||
5 | +var productSkn = $('#productSkn').val(); | ||
6 | +var brandId = $('#brand-id').val(); | ||
7 | +var bundleType = $('#bundleType').val(); | ||
8 | + | ||
9 | +require('../common'); | ||
10 | + | ||
11 | +// 领券 | ||
12 | +require('./detail/brand-coupon'); | ||
13 | + | ||
14 | +// 页面底部异步加载的部分 | ||
15 | +require('./detail/desc'); | ||
16 | + | ||
17 | +// 为你优选 | ||
18 | +require('./detail/recommend-for-you-product-desc'); | ||
19 | + | ||
20 | +window.rePosFooter && window.rePosFooter(); | ||
21 | + | ||
22 | +setTimeout(() => { | ||
23 | + var Swiper = require('yoho-swiper'); | ||
24 | + | ||
25 | + // 顶部swiper | ||
26 | + var swiper = new Swiper('.banner-swiper', { | ||
27 | + preloadImages: false, | ||
28 | + lazyLoading: true, | ||
29 | + lazyLoadingInPrevNext: true, | ||
30 | + lazyLoadingOnTransitionStart: true, | ||
31 | + paginationClickable: true, | ||
32 | + pagination: '.banner-top .pagination-inner', | ||
33 | + nextButton: '.my-swiper-button-next', | ||
34 | + prevButton: '.my-swiper-button-prev', | ||
35 | + spaceBetween: 3 | ||
36 | + }); | ||
37 | + | ||
38 | + $('.banner-swiper').click(function() { | ||
39 | + $('.banner-top').toggleClass('hover'); | ||
40 | + swiper.onResize(); | ||
41 | + }); | ||
42 | + $('.banner-top-single').click(function() { | ||
43 | + $('.banner-top-single').toggleClass('hover'); | ||
44 | + }); | ||
45 | +}, 500); | ||
46 | + | ||
47 | + | ||
48 | +// 动态加载数据 | ||
49 | +(function() { | ||
50 | + function renderInfo(data) { | ||
51 | + if (!data) { | ||
52 | + return; | ||
53 | + } | ||
54 | + | ||
55 | + var dbClass = 'data-bind', | ||
56 | + infoDataHbs = require('product/detail/infodata.hbs'), | ||
57 | + priceDataHbs = require('product/detail/pricedata.hbs'); | ||
58 | + | ||
59 | + // 商品价格 | ||
60 | + if (data.goodsPrice) { | ||
61 | + $('.goods-price>.current-price').text(data.goodsPrice.currentPrice); | ||
62 | + $('.goods-price>.previous-price').text(data.goodsPrice.previousPrice); | ||
63 | + } | ||
64 | + | ||
65 | + // 限购码 | ||
66 | + if (!data.noLimitGoodsBtn) { | ||
67 | + if (data.canGetLimitCode) { | ||
68 | + $('.data-can-get-limit-code').removeClass(dbClass); | ||
69 | + } | ||
70 | + if (data.codeEmpty) { | ||
71 | + $('.data-code-empty').removeClass(dbClass); | ||
72 | + } | ||
73 | + if (data.gotCode) { | ||
74 | + $('.data-got-code').removeClass(dbClass); | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | + if (data.studentPrice) { | ||
79 | + data.studentPrice = Math.round(data.studentPrice.toString().replace('¥', '')); | ||
80 | + } | ||
81 | + $('#placeholder-pricedata').replaceWith(priceDataHbs(data)); | ||
82 | + | ||
83 | + $('#placeholder-infodata').replaceWith(infoDataHbs(data)); | ||
84 | + | ||
85 | + if (data.isDepositAdvance === 'Y') { | ||
86 | + // 定金预售商品 | ||
87 | + var tip = require('../plugin/tip'); | ||
88 | + | ||
89 | + setTimeout(function() { | ||
90 | + $('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() { | ||
91 | + tip.show('定金预售商品只能在APP端购买'); | ||
92 | + return false; | ||
93 | + }); | ||
94 | + }, 200); | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + if (productId && (goodsId || productSkn)) { | ||
99 | + setTimeout(() => { | ||
100 | + $.ajax({ | ||
101 | + type: 'POST', | ||
102 | + url: '/product/detail/newinfo', | ||
103 | + data: { | ||
104 | + id: productId, | ||
105 | + goodsId: goodsId, | ||
106 | + productSkn: productSkn, | ||
107 | + bundleType: bundleType | ||
108 | + }, | ||
109 | + success: (data) => { | ||
110 | + // 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页 | ||
111 | + var reg = /\/product\/show_([\d]+)/; | ||
112 | + var reg2 = /\/product\/([\d]+)/; | ||
113 | + var regPro = /\/product\/pro_([\d]+)_([\d]+)/; | ||
114 | + var regSeckill = /\/product\/seckill/; | ||
115 | + | ||
116 | + // var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/; | ||
117 | + var thisHref = window.location.href; | ||
118 | + var thisRefer = document.referrer; | ||
119 | + | ||
120 | + if (!regSeckill.test(thisRefer)) { | ||
121 | + if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref) || reg2.test(thisHref))) { | ||
122 | + window.location.replace('/product/seckill/show_' + productSkn + '.html'); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + // 如果秒杀商品没有吊牌价,显示原销售价 | ||
127 | + if (data.isSecKill === 'Y' && !data.cartInfo.price) { | ||
128 | + $('.previous-price').text(data.cartInfo.salePrice); | ||
129 | + } | ||
130 | + | ||
131 | + // 渲染动态数据 | ||
132 | + renderInfo(data); | ||
133 | + | ||
134 | + // 引入like事件 | ||
135 | + require('./detail/like'); | ||
136 | + | ||
137 | + // 设定购物bar | ||
138 | + var $cartBar = $('.cart-bar'); | ||
139 | + var timer = setInterval(function() { | ||
140 | + if ($cartBar) { | ||
141 | + window.reMarginFooter('.cart-bar'); | ||
142 | + clearInterval(timer); | ||
143 | + } else { | ||
144 | + $cartBar = $('.cart-bar'); | ||
145 | + } | ||
146 | + }, 500); | ||
147 | + | ||
148 | + // 限购 | ||
149 | + var dialog = require('../plugin/dialog'); | ||
150 | + | ||
151 | + $('#limit-sale').on('touchend', function(e) { | ||
152 | + var loginUrl = $('#loginUrl').val(), | ||
153 | + time, | ||
154 | + ifr; | ||
155 | + | ||
156 | + e.stopPropagation(); | ||
157 | + | ||
158 | + if (loginUrl) { | ||
159 | + window.location = loginUrl; | ||
160 | + } else { | ||
161 | + dialog.showDialog({ | ||
162 | + dialogText: '进入有货APP,获取限购码', | ||
163 | + hasFooter: { | ||
164 | + rightBtnText: '打开Yoho!Buy有货APP' | ||
165 | + } | ||
166 | + }, function() { | ||
167 | + var appUrl = $('input[name="limitCodeUrl"]').val(); | ||
168 | + | ||
169 | + ifr = document.createElement('iframe'); | ||
170 | + ifr.src = appUrl; | ||
171 | + ifr.style.display = 'none'; | ||
172 | + document.body.appendChild(ifr); | ||
173 | + window.location.href = appUrl; | ||
174 | + | ||
175 | + time = Date.now(); | ||
176 | + window.setTimeout(function() { | ||
177 | + document.body.removeChild(ifr); | ||
178 | + if (Date.now() - time < 3200) { | ||
179 | + window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; | ||
180 | + } | ||
181 | + }, 3000); | ||
182 | + | ||
183 | + }, null, true); | ||
184 | + | ||
185 | + $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) { | ||
186 | + para.stopPropagation(); | ||
187 | + if ($(para.target).hasClass('dialog-wrapper')) { | ||
188 | + dialog.hideDialog(); | ||
189 | + } | ||
190 | + }); | ||
191 | + } | ||
192 | + }); | ||
193 | + | ||
194 | + window.rePosFooter && window.rePosFooter(); | ||
195 | + } | ||
196 | + }); | ||
197 | + }, 150); | ||
198 | + } | ||
199 | +}()); | ||
200 | + | ||
201 | +/* | ||
202 | + * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化 | ||
203 | + */ | ||
204 | ++ (function(skn, productId, brandId) { // eslint-disable-line | ||
205 | + // 模版: 促销, feedback, 店铺 | ||
206 | + var promotionT = require('product/detail/promotion.hbs'); | ||
207 | + var feedbackT = require('product/detail/feedbacks.hbs'); | ||
208 | + var enterStoreT = require('product/detail/enterStore.hbs'); | ||
209 | + | ||
210 | + // placeholder | ||
211 | + var $feedbackStore = $('#placeholder-feedback-store'); | ||
212 | + var $promotion = $('#placeholder-promotion'); | ||
213 | + | ||
214 | + /** | ||
215 | + * 渲染 feedback, 店铺, 替换placeholder | ||
216 | + * @param data | ||
217 | + * { | ||
218 | + * enterStore, feedback | ||
219 | + * } | ||
220 | + * @param $placeholder | ||
221 | + */ | ||
222 | + function renderFeedbackStore(data, $placeholder) { | ||
223 | + var feedbackHtml = feedbackT({ | ||
224 | + feedbacks: data.feedbacks | ||
225 | + }); | ||
226 | + | ||
227 | + var enterStoreHtml = enterStoreT({ | ||
228 | + enterStore: data.enterStore | ||
229 | + }); | ||
230 | + | ||
231 | + return $placeholder.replaceWith([feedbackHtml, enterStoreHtml]); | ||
232 | + } | ||
233 | + | ||
234 | + | ||
235 | + /** | ||
236 | + * 渲染 促销, 替换placeholder | ||
237 | + * @param data | ||
238 | + * { | ||
239 | + * promotion | ||
240 | + * } | ||
241 | + * @param $placeholder | ||
242 | + */ | ||
243 | + function renderPromotion(data, $placeholder) { | ||
244 | + var promotionHtml = promotionT({ | ||
245 | + promotion: data.promotion | ||
246 | + }); | ||
247 | + | ||
248 | + return $placeholder.replaceWith(promotionHtml); | ||
249 | + } | ||
250 | + | ||
251 | + | ||
252 | + function promotionInit() { | ||
253 | + var $goodsDiscount = $('#goodsDiscount'); | ||
254 | + var $discountFirstItem = $goodsDiscount.find('.first-item'); | ||
255 | + var $discountFolder = $goodsDiscount.find('.discount-folder'); | ||
256 | + var $discountArrow = $goodsDiscount.find('.first-item span'); | ||
257 | + | ||
258 | + // 初始化goods-discount | ||
259 | + if ($discountFolder.children().length === 0) { | ||
260 | + $discountFolder.css('display', 'none'); | ||
261 | + $discountArrow.html(''); | ||
262 | + } | ||
263 | + | ||
264 | + // goods-discount下拉按钮点击事件 | ||
265 | + if ($goodsDiscount.length && $discountFolder.children().length > 0) { | ||
266 | + $goodsDiscount.on('click', function() { | ||
267 | + if ($discountFolder.is(':hidden')) { | ||
268 | + $discountFirstItem.removeClass('short-text'); | ||
269 | + $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); | ||
270 | + $discountFolder.slideDown(); | ||
271 | + } else { | ||
272 | + $discountFirstItem.addClass('short-text'); | ||
273 | + $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); | ||
274 | + $discountFolder.slideUp(); | ||
275 | + } | ||
276 | + }); | ||
277 | + } | ||
278 | + } | ||
279 | + | ||
280 | + // boot | ||
281 | + setTimeout(() => { | ||
282 | + $.get('/product/detail/sknData.json', { | ||
283 | + skn: skn, | ||
284 | + productId: productId, | ||
285 | + brandId: brandId, | ||
286 | + bundleType: bundleType, | ||
287 | + gid: goodsId | ||
288 | + }).done(function(info) { | ||
289 | + // step1: render dom | ||
290 | + renderFeedbackStore(info, $feedbackStore); | ||
291 | + renderPromotion(info, $promotion); | ||
292 | + | ||
293 | + if (info.bundleDatas && info.bundleDatas.length) { | ||
294 | + require('./detail/bundle').init(info.bundleDatas); | ||
295 | + $('.bundle').on('touchstart', function() { | ||
296 | + if (window._yas && window._yas.sendCustomInfo) { | ||
297 | + window._yas.sendCustomInfo({ | ||
298 | + op: 'YB_GDS_PACKAGE_C', | ||
299 | + param: JSON.stringify({ | ||
300 | + C_ID: window._ChannelVary[window.cookie('_Channel')], | ||
301 | + PRD_ID: productId | ||
302 | + }) | ||
303 | + }, true); | ||
304 | + } | ||
305 | + }); | ||
306 | + } | ||
307 | + | ||
308 | + // step2: init js | ||
309 | + require('./detail/comments-consults'); | ||
310 | + require('./detail/consultform'); // TODO | ||
311 | + promotionInit(); | ||
312 | + window.rePosFooter && window.rePosFooter(); | ||
313 | + }); | ||
314 | + }, 200); | ||
315 | + | ||
316 | + // 加载详情页的返回顶部按钮并注册事件 | ||
317 | + | ||
318 | + $(document).scroll(function() { | ||
319 | + if ($(document).scrollTop() >= $(document).height() - $(window).height() - 120) { | ||
320 | + var top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2; | ||
321 | + var left = $('.back-to-top').offset().left - $('.float-top').offset().left; | ||
322 | + | ||
323 | + $('.float-top').addClass('animation').css({ | ||
324 | + transform: 'translate(' + left + 'px, ' + top + 'px) scale(0, 0)', | ||
325 | + }); | ||
326 | + } else if ($('.product-detail').length && $(document).scrollTop() >= $('.product-detail').offset().top) { | ||
327 | + if (!$('.float-top').hasClass('hover') || $('.float-top').hasClass('animation')) { | ||
328 | + $('.float-top').addClass('hover').removeClass('animation').removeAttr('style'); | ||
329 | + } | ||
330 | + } else { | ||
331 | + if ($('.float-top').hasClass('hover')) { | ||
332 | + $('.float-top').removeClass('hover'); | ||
333 | + } | ||
334 | + } | ||
335 | + }); | ||
336 | + | ||
337 | + // 加载详情页的返回顶部按钮并注册事件-end | ||
338 | +}(productSkn, productId, brandId)); |
1 | -require('product/detail/detail.page.css'); | ||
2 | -var $ = require('yoho-jquery'); | ||
3 | -var productId = $('#productId').val(); | ||
4 | -var goodsId = $('#goodsId').val(); | ||
5 | -var productSkn = $('#productSkn').val(); | ||
6 | -var brandId = $('#brand-id').val(); | ||
7 | -var bundleType = $('#bundleType').val(); | ||
8 | - | ||
9 | -require('../common'); | ||
10 | - | ||
11 | -// 领券 | ||
12 | -require('./detail/brand-coupon'); | ||
13 | - | ||
14 | -// 页面底部异步加载的部分 | ||
15 | -require('./detail/desc'); | ||
16 | - | ||
17 | -// 为你优选 | ||
18 | -require('./detail/recommend-for-you-product-desc'); | ||
19 | - | ||
20 | -window.rePosFooter && window.rePosFooter(); | ||
21 | - | ||
22 | -setTimeout(() => { | ||
23 | - var Swiper = require('yoho-swiper'); | ||
24 | - | ||
25 | - // 顶部swiper | ||
26 | - var swiper = new Swiper('.banner-swiper', { | ||
27 | - preloadImages: false, | ||
28 | - lazyLoading: true, | ||
29 | - lazyLoadingInPrevNext: true, | ||
30 | - lazyLoadingOnTransitionStart: true, | ||
31 | - paginationClickable: true, | ||
32 | - pagination: '.banner-top .pagination-inner', | ||
33 | - nextButton: '.my-swiper-button-next', | ||
34 | - prevButton: '.my-swiper-button-prev', | ||
35 | - spaceBetween: 3 | ||
36 | - }); | ||
37 | - | ||
38 | - $('.banner-swiper').click(function() { | ||
39 | - $('.banner-top').toggleClass('hover'); | ||
40 | - swiper.onResize(); | ||
41 | - }); | ||
42 | - $('.banner-top-single').click(function() { | ||
43 | - $('.banner-top-single').toggleClass('hover'); | ||
44 | - }); | ||
45 | -}, 500); | ||
46 | - | ||
47 | - | ||
48 | -// 动态加载数据 | ||
49 | -(function() { | ||
50 | - function renderInfo(data) { | ||
51 | - if (!data) { | ||
52 | - return; | ||
53 | - } | ||
54 | - | ||
55 | - var dbClass = 'data-bind', | ||
56 | - infoDataHbs = require('product/detail/infodata.hbs'), | ||
57 | - priceDataHbs = require('product/detail/pricedata.hbs'); | ||
58 | - | ||
59 | - // 商品价格 | ||
60 | - if (data.goodsPrice) { | ||
61 | - $('.goods-price>.current-price').text(data.goodsPrice.currentPrice); | ||
62 | - $('.goods-price>.previous-price').text(data.goodsPrice.previousPrice); | ||
63 | - } | ||
64 | - | ||
65 | - // 限购码 | ||
66 | - if (!data.noLimitGoodsBtn) { | ||
67 | - if (data.canGetLimitCode) { | ||
68 | - $('.data-can-get-limit-code').removeClass(dbClass); | ||
69 | - } | ||
70 | - if (data.codeEmpty) { | ||
71 | - $('.data-code-empty').removeClass(dbClass); | ||
72 | - } | ||
73 | - if (data.gotCode) { | ||
74 | - $('.data-got-code').removeClass(dbClass); | ||
75 | - } | ||
76 | - } | ||
77 | - | ||
78 | - if (data.studentPrice) { | ||
79 | - data.studentPrice = Math.round(data.studentPrice.toString().replace('¥', '')); | ||
80 | - } | ||
81 | - $('#placeholder-pricedata').replaceWith(priceDataHbs(data)); | ||
82 | - | ||
83 | - $('#placeholder-infodata').replaceWith(infoDataHbs(data)); | ||
84 | - | ||
85 | - if (data.isDepositAdvance === 'Y') { | ||
86 | - // 定金预售商品 | ||
87 | - var tip = require('../plugin/tip'); | ||
88 | - | ||
89 | - setTimeout(function() { | ||
90 | - $('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() { | ||
91 | - tip.show('定金预售商品只能在APP端购买'); | ||
92 | - return false; | ||
93 | - }); | ||
94 | - }, 200); | ||
95 | - } | ||
96 | - } | ||
97 | - | ||
98 | - if (productId && (goodsId || productSkn)) { | ||
99 | - setTimeout(() => { | ||
100 | - $.ajax({ | ||
101 | - type: 'POST', | ||
102 | - url: '/product/detail/newinfo', | ||
103 | - data: { | ||
104 | - id: productId, | ||
105 | - goodsId: goodsId, | ||
106 | - productSkn: productSkn, | ||
107 | - bundleType: bundleType | ||
108 | - }, | ||
109 | - success: (data) => { | ||
110 | - // 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页 | ||
111 | - var reg = /\/product\/show_([\d]+)/; | ||
112 | - var reg2 = /\/product\/([\d]+)/; | ||
113 | - var regPro = /\/product\/pro_([\d]+)_([\d]+)/; | ||
114 | - var regSeckill = /\/product\/seckill/; | ||
115 | - | ||
116 | - // var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/; | ||
117 | - var thisHref = window.location.href; | ||
118 | - var thisRefer = document.referrer; | ||
119 | - | ||
120 | - if (!regSeckill.test(thisRefer)) { | ||
121 | - if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref) || reg2.test(thisHref))) { | ||
122 | - window.location.replace('/product/seckill/show_' + productSkn + '.html'); | ||
123 | - } | ||
124 | - } | ||
125 | - | ||
126 | - // 如果秒杀商品没有吊牌价,显示原销售价 | ||
127 | - if (data.isSecKill === 'Y' && !data.cartInfo.price) { | ||
128 | - $('.previous-price').text(data.cartInfo.salePrice); | ||
129 | - } | ||
130 | - | ||
131 | - // 渲染动态数据 | ||
132 | - renderInfo(data); | ||
133 | - | ||
134 | - // 引入like事件 | ||
135 | - require('./detail/like'); | ||
136 | - | ||
137 | - // 设定购物bar | ||
138 | - var $cartBar = $('.cart-bar'); | ||
139 | - var timer = setInterval(function() { | ||
140 | - if ($cartBar) { | ||
141 | - window.reMarginFooter('.cart-bar'); | ||
142 | - clearInterval(timer); | ||
143 | - } else { | ||
144 | - $cartBar = $('.cart-bar'); | ||
145 | - } | ||
146 | - }, 500); | ||
147 | - | ||
148 | - // 限购 | ||
149 | - var dialog = require('../plugin/dialog'); | ||
150 | - | ||
151 | - $('#limit-sale').on('touchend', function(e) { | ||
152 | - var loginUrl = $('#loginUrl').val(), | ||
153 | - time, | ||
154 | - ifr; | ||
155 | - | ||
156 | - e.stopPropagation(); | ||
157 | - | ||
158 | - if (loginUrl) { | ||
159 | - window.location = loginUrl; | ||
160 | - } else { | ||
161 | - dialog.showDialog({ | ||
162 | - dialogText: '进入有货APP,获取限购码', | ||
163 | - hasFooter: { | ||
164 | - rightBtnText: '打开Yoho!Buy有货APP' | ||
165 | - } | ||
166 | - }, function() { | ||
167 | - var appUrl = $('input[name="limitCodeUrl"]').val(); | ||
168 | - | ||
169 | - ifr = document.createElement('iframe'); | ||
170 | - ifr.src = appUrl; | ||
171 | - ifr.style.display = 'none'; | ||
172 | - document.body.appendChild(ifr); | ||
173 | - window.location.href = appUrl; | ||
174 | - | ||
175 | - time = Date.now(); | ||
176 | - window.setTimeout(function() { | ||
177 | - document.body.removeChild(ifr); | ||
178 | - if (Date.now() - time < 3200) { | ||
179 | - window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; | ||
180 | - } | ||
181 | - }, 3000); | ||
182 | - | ||
183 | - }, null, true); | ||
184 | - | ||
185 | - $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) { | ||
186 | - para.stopPropagation(); | ||
187 | - if ($(para.target).hasClass('dialog-wrapper')) { | ||
188 | - dialog.hideDialog(); | ||
189 | - } | ||
190 | - }); | ||
191 | - } | ||
192 | - }); | ||
193 | - | ||
194 | - window.rePosFooter && window.rePosFooter(); | ||
195 | - } | ||
196 | - }); | ||
197 | - }, 150); | ||
198 | - } | ||
199 | -}()); | ||
200 | - | ||
201 | -/* | ||
202 | - * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化 | ||
203 | - */ | ||
204 | -+ (function(skn, productId, brandId) { // eslint-disable-line | ||
205 | - // 模版: 促销, feedback, 店铺 | ||
206 | - var promotionT = require('product/detail/promotion.hbs'); | ||
207 | - var feedbackT = require('product/detail/feedbacks.hbs'); | ||
208 | - var enterStoreT = require('product/detail/enterStore.hbs'); | ||
209 | - | ||
210 | - // placeholder | ||
211 | - var $feedbackStore = $('#placeholder-feedback-store'); | ||
212 | - var $promotion = $('#placeholder-promotion'); | ||
213 | - | ||
214 | - /** | ||
215 | - * 渲染 feedback, 店铺, 替换placeholder | ||
216 | - * @param data | ||
217 | - * { | ||
218 | - * enterStore, feedback | ||
219 | - * } | ||
220 | - * @param $placeholder | ||
221 | - */ | ||
222 | - function renderFeedbackStore(data, $placeholder) { | ||
223 | - var feedbackHtml = feedbackT({ | ||
224 | - feedbacks: data.feedbacks | ||
225 | - }); | ||
226 | - | ||
227 | - var enterStoreHtml = enterStoreT({ | ||
228 | - enterStore: data.enterStore | ||
229 | - }); | ||
230 | - | ||
231 | - return $placeholder.replaceWith([feedbackHtml, enterStoreHtml]); | ||
232 | - } | ||
233 | - | ||
234 | - | ||
235 | - /** | ||
236 | - * 渲染 促销, 替换placeholder | ||
237 | - * @param data | ||
238 | - * { | ||
239 | - * promotion | ||
240 | - * } | ||
241 | - * @param $placeholder | ||
242 | - */ | ||
243 | - function renderPromotion(data, $placeholder) { | ||
244 | - var promotionHtml = promotionT({ | ||
245 | - promotion: data.promotion | ||
246 | - }); | ||
247 | - | ||
248 | - return $placeholder.replaceWith(promotionHtml); | ||
249 | - } | ||
250 | - | ||
251 | - | ||
252 | - function promotionInit() { | ||
253 | - var $goodsDiscount = $('#goodsDiscount'); | ||
254 | - var $discountFirstItem = $goodsDiscount.find('.first-item'); | ||
255 | - var $discountFolder = $goodsDiscount.find('.discount-folder'); | ||
256 | - var $discountArrow = $goodsDiscount.find('.first-item span'); | ||
257 | - | ||
258 | - // 初始化goods-discount | ||
259 | - if ($discountFolder.children().length === 0) { | ||
260 | - $discountFolder.css('display', 'none'); | ||
261 | - $discountArrow.html(''); | ||
262 | - } | ||
263 | - | ||
264 | - // goods-discount下拉按钮点击事件 | ||
265 | - if ($goodsDiscount.length && $discountFolder.children().length > 0) { | ||
266 | - $goodsDiscount.on('click', function() { | ||
267 | - if ($discountFolder.is(':hidden')) { | ||
268 | - $discountFirstItem.removeClass('short-text'); | ||
269 | - $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); | ||
270 | - $discountFolder.slideDown(); | ||
271 | - } else { | ||
272 | - $discountFirstItem.addClass('short-text'); | ||
273 | - $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); | ||
274 | - $discountFolder.slideUp(); | ||
275 | - } | ||
276 | - }); | ||
277 | - } | ||
278 | - } | ||
279 | - | ||
280 | - // boot | ||
281 | - setTimeout(() => { | ||
282 | - $.get('/product/detail/sknData.json', { | ||
283 | - skn: skn, | ||
284 | - productId: productId, | ||
285 | - brandId: brandId, | ||
286 | - bundleType: bundleType, | ||
287 | - gid: goodsId | ||
288 | - }).done(function(info) { | ||
289 | - // step1: render dom | ||
290 | - renderFeedbackStore(info, $feedbackStore); | ||
291 | - renderPromotion(info, $promotion); | ||
292 | - | ||
293 | - if (info.bundleDatas && info.bundleDatas.length) { | ||
294 | - require('./detail/bundle').init(info.bundleDatas); | ||
295 | - $('.bundle').on('touchstart', function() { | ||
296 | - if (window._yas && window._yas.sendCustomInfo) { | ||
297 | - window._yas.sendCustomInfo({ | ||
298 | - op: 'YB_GDS_PACKAGE_C', | ||
299 | - param: JSON.stringify({ | ||
300 | - C_ID: window._ChannelVary[window.cookie('_Channel')], | ||
301 | - PRD_ID: productId | ||
302 | - }) | ||
303 | - }, true); | ||
304 | - } | ||
305 | - }); | ||
306 | - } | ||
307 | - | ||
308 | - // step2: init js | ||
309 | - require('./detail/comments-consults'); | ||
310 | - require('./detail/consultform'); // TODO | ||
311 | - promotionInit(); | ||
312 | - window.rePosFooter && window.rePosFooter(); | ||
313 | - }); | ||
314 | - }, 200); | ||
315 | - | ||
316 | - // 加载详情页的返回顶部按钮并注册事件 | ||
317 | - | ||
318 | - $(document).scroll(function() { | ||
319 | - if ($(document).scrollTop() >= $(document).height() - $(window).height() - 120) { | ||
320 | - var top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2; | ||
321 | - var left = $('.back-to-top').offset().left - $('.float-top').offset().left; | ||
322 | - | ||
323 | - $('.float-top').addClass('animation').css({ | ||
324 | - transform: 'translate(' + left + 'px, ' + top + 'px) scale(0, 0)', | ||
325 | - }); | ||
326 | - } else if ($('.product-detail').length && $(document).scrollTop() >= $('.product-detail').offset().top) { | ||
327 | - if (!$('.float-top').hasClass('hover') || $('.float-top').hasClass('animation')) { | ||
328 | - $('.float-top').addClass('hover').removeClass('animation').removeAttr('style'); | ||
329 | - } | ||
330 | - } else { | ||
331 | - if ($('.float-top').hasClass('hover')) { | ||
332 | - $('.float-top').removeClass('hover'); | ||
333 | - } | ||
334 | - } | ||
335 | - }); | ||
336 | - | ||
337 | - // 加载详情页的返回顶部按钮并注册事件-end | ||
338 | -}(productSkn, productId, brandId)); | 1 | +require('./new-detail'); |
1 | -require('product/detail/detail.page.css'); | ||
2 | -var $ = require('yoho-jquery'); | ||
3 | -var productId = $('#productId').val(); | ||
4 | -var goodsId = $('#goodsId').val(); | ||
5 | -var productSkn = $('#productSkn').val(); | ||
6 | -var brandId = $('#brand-id').val(); | ||
7 | -var bundleType = $('#bundleType').val(); | 1 | +// 调用秒杀js |
2 | +$(window).on('seckill', function() { | ||
3 | + require('./tick'); | ||
4 | +}); | ||
8 | 5 | ||
9 | -require('../common'); | 6 | +// 调用新商品详情页js |
7 | +require('./new-detail'); | ||
10 | 8 | ||
11 | -// 领券 | ||
12 | -require('./detail/brand-coupon'); | ||
13 | - | ||
14 | -// 页面底部异步加载的部分 | ||
15 | -require('./detail/desc'); | ||
16 | - | ||
17 | -// 为你优选 | ||
18 | -require('./detail/recommend-for-you-product-desc'); | ||
19 | - | ||
20 | -window.rePosFooter && window.rePosFooter(); | ||
21 | - | ||
22 | -setTimeout(() => { | ||
23 | - var Swiper = require('yoho-swiper'); | ||
24 | - | ||
25 | - // 顶部swiper | ||
26 | - var swiper = new Swiper('.banner-swiper', { | ||
27 | - preloadImages: false, | ||
28 | - lazyLoading: true, | ||
29 | - lazyLoadingInPrevNext: true, | ||
30 | - lazyLoadingOnTransitionStart: true, | ||
31 | - paginationClickable: true, | ||
32 | - pagination: '.banner-top .pagination-inner', | ||
33 | - nextButton: '.my-swiper-button-next', | ||
34 | - prevButton: '.my-swiper-button-prev', | ||
35 | - spaceBetween: 3 | ||
36 | - }); | ||
37 | - | ||
38 | - $('.banner-swiper').click(function() { | ||
39 | - $('.banner-top').toggleClass('hover'); | ||
40 | - swiper.onResize(); | ||
41 | - }); | ||
42 | - $('.banner-top-single').click(function() { | ||
43 | - $('.banner-top-single').toggleClass('hover'); | ||
44 | - }); | ||
45 | -}, 500); | ||
46 | - | ||
47 | - | ||
48 | -// 动态加载数据 | ||
49 | -(function() { | ||
50 | - function renderInfo(data) { | ||
51 | - if (!data) { | ||
52 | - return; | ||
53 | - } | ||
54 | - | ||
55 | - var dbClass = 'data-bind', | ||
56 | - infoDataHbs = require('product/detail/infodata.hbs'), | ||
57 | - priceDataHbs = require('product/detail/pricedata.hbs'); | ||
58 | - | ||
59 | - // 商品价格 | ||
60 | - if (data.goodsPrice) { | ||
61 | - $('.goods-price>.current-price').text(data.goodsPrice.currentPrice); | ||
62 | - $('.goods-price>.previous-price').text(data.goodsPrice.previousPrice); | ||
63 | - } | ||
64 | - | ||
65 | - // 限购码 | ||
66 | - if (!data.noLimitGoodsBtn) { | ||
67 | - if (data.canGetLimitCode) { | ||
68 | - $('.data-can-get-limit-code').removeClass(dbClass); | ||
69 | - } | ||
70 | - if (data.codeEmpty) { | ||
71 | - $('.data-code-empty').removeClass(dbClass); | ||
72 | - } | ||
73 | - if (data.gotCode) { | ||
74 | - $('.data-got-code').removeClass(dbClass); | ||
75 | - } | ||
76 | - } | ||
77 | - | ||
78 | - if (data.studentPrice) { | ||
79 | - data.studentPrice = Math.round(data.studentPrice.toString().replace('¥', '')); | ||
80 | - } | ||
81 | - $('#placeholder-pricedata').replaceWith(priceDataHbs(data)); | ||
82 | - | ||
83 | - $('#placeholder-infodata').replaceWith(infoDataHbs(data)); | ||
84 | - | ||
85 | - if (data.isDepositAdvance === 'Y') { | ||
86 | - // 定金预售商品 | ||
87 | - var tip = require('../plugin/tip'); | ||
88 | - | ||
89 | - setTimeout(function() { | ||
90 | - $('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() { | ||
91 | - tip.show('定金预售商品只能在APP端购买'); | ||
92 | - return false; | ||
93 | - }); | ||
94 | - }, 200); | ||
95 | - } | ||
96 | - | ||
97 | - // 调用秒杀js | ||
98 | - require('./tick'); | ||
99 | - } | ||
100 | - | ||
101 | - if (productId && (goodsId || productSkn)) { | ||
102 | - setTimeout(() => { | ||
103 | - $.ajax({ | ||
104 | - type: 'POST', | ||
105 | - url: '/product/detail/newinfo', | ||
106 | - data: { | ||
107 | - id: productId, | ||
108 | - goodsId: goodsId, | ||
109 | - productSkn: productSkn, | ||
110 | - bundleType: bundleType | ||
111 | - }, | ||
112 | - success: (data) => { | ||
113 | - // 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页 | ||
114 | - var reg = /\/product\/show_([\d]+)/; | ||
115 | - var regPro = /\/product\/pro_([\d]+)_([\d]+)/; | ||
116 | - var regSeckill = /\/product\/seckill/; | ||
117 | - | ||
118 | - // var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/; | ||
119 | - var thisHref = window.location.href; | ||
120 | - var thisRefer = document.referrer; | ||
121 | - | ||
122 | - if (!regSeckill.test(thisRefer)) { | ||
123 | - if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) { | ||
124 | - window.location.replace('/product/seckill/show_' + productSkn + '.html'); | ||
125 | - } | ||
126 | - } | ||
127 | - | ||
128 | - // 如果秒杀商品没有吊牌价,显示原销售价 | ||
129 | - if (data.isSecKill === 'Y' && !data.cartInfo.price) { | ||
130 | - $('.previous-price').text(data.cartInfo.salePrice); | ||
131 | - } | ||
132 | - | ||
133 | - // 渲染动态数据 | ||
134 | - renderInfo(data); | ||
135 | - | ||
136 | - // 引入like事件 | ||
137 | - require('./detail/like'); | ||
138 | - | ||
139 | - // 设定购物bar | ||
140 | - var $cartBar = $('.cart-bar'); | ||
141 | - var timer = setInterval(function() { | ||
142 | - if ($cartBar) { | ||
143 | - window.reMarginFooter('.cart-bar'); | ||
144 | - clearInterval(timer); | ||
145 | - } else { | ||
146 | - $cartBar = $('.cart-bar'); | ||
147 | - } | ||
148 | - }, 500); | ||
149 | - | ||
150 | - // 限购 | ||
151 | - var dialog = require('../plugin/dialog'); | ||
152 | - | ||
153 | - $('#limit-sale').on('touchend', function(e) { | ||
154 | - var loginUrl = $('#loginUrl').val(), | ||
155 | - time, | ||
156 | - ifr; | ||
157 | - | ||
158 | - e.stopPropagation(); | ||
159 | - | ||
160 | - if (loginUrl) { | ||
161 | - window.location = loginUrl; | ||
162 | - } else { | ||
163 | - dialog.showDialog({ | ||
164 | - dialogText: '进入有货APP,获取限购码', | ||
165 | - hasFooter: { | ||
166 | - rightBtnText: '打开Yoho!Buy有货APP' | ||
167 | - } | ||
168 | - }, function() { | ||
169 | - var appUrl = $('input[name="limitCodeUrl"]').val(); | ||
170 | - | ||
171 | - ifr = document.createElement('iframe'); | ||
172 | - ifr.src = appUrl; | ||
173 | - ifr.style.display = 'none'; | ||
174 | - document.body.appendChild(ifr); | ||
175 | - window.location.href = appUrl; | ||
176 | - | ||
177 | - time = Date.now(); | ||
178 | - window.setTimeout(function() { | ||
179 | - document.body.removeChild(ifr); | ||
180 | - if (Date.now() - time < 3200) { | ||
181 | - window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; | ||
182 | - } | ||
183 | - }, 3000); | ||
184 | - | ||
185 | - }, null, true); | ||
186 | - | ||
187 | - $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) { | ||
188 | - para.stopPropagation(); | ||
189 | - if ($(para.target).hasClass('dialog-wrapper')) { | ||
190 | - dialog.hideDialog(); | ||
191 | - } | ||
192 | - }); | ||
193 | - } | ||
194 | - }); | ||
195 | - | ||
196 | - window.rePosFooter && window.rePosFooter(); | ||
197 | - } | ||
198 | - }); | ||
199 | - }, 150); | ||
200 | - } | ||
201 | -}()); | ||
202 | - | ||
203 | -/* | ||
204 | - * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化 | ||
205 | - */ | ||
206 | -+ (function(skn, productId, brandId) { // eslint-disable-line | ||
207 | - // 模版: 促销, feedback, 店铺 | ||
208 | - var promotionT = require('product/detail/promotion.hbs'); | ||
209 | - var feedbackT = require('product/detail/feedbacks.hbs'); | ||
210 | - var enterStoreT = require('product/detail/enterStore.hbs'); | ||
211 | - var bundleT = require('product/detail/bundle.hbs'); | ||
212 | - | ||
213 | - // placeholder | ||
214 | - var $feedbackStore = $('#placeholder-feedback-store'); | ||
215 | - var $promotion = $('#placeholder-promotion'); | ||
216 | - var $bundle = $('#placeholder-bundle'); | ||
217 | - | ||
218 | - /** | ||
219 | - * 渲染 feedback, 店铺, 替换placeholder | ||
220 | - * @param data | ||
221 | - * { | ||
222 | - * enterStore, feedback | ||
223 | - * } | ||
224 | - * @param $placeholder | ||
225 | - */ | ||
226 | - function renderFeedbackStore(data, $placeholder) { | ||
227 | - var feedbackHtml = feedbackT({ | ||
228 | - feedbacks: data.feedbacks | ||
229 | - }); | ||
230 | - | ||
231 | - var enterStoreHtml = enterStoreT({ | ||
232 | - enterStore: data.enterStore | ||
233 | - }); | ||
234 | - | ||
235 | - return $placeholder.replaceWith([feedbackHtml, enterStoreHtml]); | ||
236 | - } | ||
237 | - | ||
238 | - | ||
239 | - /** | ||
240 | - * 渲染 促销, 替换placeholder | ||
241 | - * @param data | ||
242 | - * { | ||
243 | - * promotion | ||
244 | - * } | ||
245 | - * @param $placeholder | ||
246 | - */ | ||
247 | - function renderPromotion(data, $placeholder) { | ||
248 | - var promotionHtml = promotionT({ | ||
249 | - promotion: data.promotion | ||
250 | - }); | ||
251 | - | ||
252 | - return $placeholder.replaceWith(promotionHtml); | ||
253 | - } | ||
254 | - | ||
255 | - /** | ||
256 | - * 渲染 套装,替换placeholder | ||
257 | - * @param data | ||
258 | - * @param $placeholder | ||
259 | - * @returns {*} | ||
260 | - */ | ||
261 | - function renderBundle(data, $placeholder) { | ||
262 | - var bundleHtml = bundleT({ | ||
263 | - bundleData: data.bundleData | ||
264 | - }); | ||
265 | - | ||
266 | - return $placeholder.replaceWith(bundleHtml); | ||
267 | - } | ||
268 | - | ||
269 | - function promotionInit() { | ||
270 | - var $goodsDiscount = $('#goodsDiscount'); | ||
271 | - var $discountFirstItem = $goodsDiscount.find('.first-item'); | ||
272 | - var $discountFolder = $goodsDiscount.find('.discount-folder'); | ||
273 | - var $discountArrow = $goodsDiscount.find('.first-item span'); | ||
274 | - | ||
275 | - // 初始化goods-discount | ||
276 | - if ($discountFolder.children().length === 0) { | ||
277 | - $discountFolder.css('display', 'none'); | ||
278 | - $discountArrow.html(''); | ||
279 | - } | ||
280 | - | ||
281 | - // goods-discount下拉按钮点击事件 | ||
282 | - if ($goodsDiscount.length && $discountFolder.children().length > 0) { | ||
283 | - $goodsDiscount.on('click', function() { | ||
284 | - if ($discountFolder.is(':hidden')) { | ||
285 | - $discountFirstItem.removeClass('short-text'); | ||
286 | - $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); | ||
287 | - $discountFolder.slideDown(); | ||
288 | - } else { | ||
289 | - $discountFirstItem.addClass('short-text'); | ||
290 | - $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); | ||
291 | - $discountFolder.slideUp(); | ||
292 | - } | ||
293 | - }); | ||
294 | - } | ||
295 | - } | ||
296 | - | ||
297 | - // boot | ||
298 | - setTimeout(() => { | ||
299 | - $.get('/product/detail/sknData.json', { | ||
300 | - skn: skn, | ||
301 | - productId: productId, | ||
302 | - brandId: brandId, | ||
303 | - bundleType: bundleType, | ||
304 | - gid: goodsId | ||
305 | - }).done(function(info) { | ||
306 | - // step1: render dom | ||
307 | - renderFeedbackStore(info, $feedbackStore); | ||
308 | - renderPromotion(info, $promotion); | ||
309 | - | ||
310 | - if (info.bundleData) { | ||
311 | - renderBundle(info, $bundle); | ||
312 | - $('.bundle').on('touchstart', function() { | ||
313 | - if (window._yas && window._yas.sendCustomInfo) { | ||
314 | - window._yas.sendCustomInfo({ | ||
315 | - op: 'YB_GDS_PACKAGE_C', | ||
316 | - param: JSON.stringify({ | ||
317 | - C_ID: window._ChannelVary[window.cookie('_Channel')], | ||
318 | - PRD_ID: productId | ||
319 | - }) | ||
320 | - }, true); | ||
321 | - } | ||
322 | - }); | ||
323 | - } | ||
324 | - | ||
325 | - // step2: init js | ||
326 | - require('./detail/comments-consults'); | ||
327 | - require('./detail/consultform'); // TODO | ||
328 | - require('./detail/bundle'); | ||
329 | - promotionInit(); | ||
330 | - window.rePosFooter && window.rePosFooter(); | ||
331 | - }); | ||
332 | - }, 200); | ||
333 | - | ||
334 | - // 加载详情页的返回顶部按钮并注册事件 | ||
335 | - | ||
336 | - $(document).scroll(function() { | ||
337 | - if ($(document).scrollTop() >= $(document).height() - $(window).height() - 120) { | ||
338 | - var top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2; | ||
339 | - var left = $('.back-to-top').offset().left - $('.float-top').offset().left; | ||
340 | - | ||
341 | - $('.float-top').addClass('animation').css({ | ||
342 | - transform: 'translate(' + left + 'px, ' + top + 'px) scale(0, 0)', | ||
343 | - }); | ||
344 | - } else if ($('.product-detail').length && $(document).scrollTop() >= $('.product-detail').offset().top) { | ||
345 | - if (!$('.float-top').hasClass('hover') || $('.float-top').hasClass('animation')) { | ||
346 | - $('.float-top').addClass('hover').removeClass('animation').removeAttr('style'); | ||
347 | - } | ||
348 | - } else { | ||
349 | - if ($('.float-top').hasClass('hover')) { | ||
350 | - $('.float-top').removeClass('hover'); | ||
351 | - } | ||
352 | - } | ||
353 | - }); | ||
354 | - | ||
355 | - // 加载详情页的返回顶部按钮并注册事件-end | ||
356 | -}(productSkn, productId, brandId)); |
-
Please register or login to post a comment