Authored by 陈峰

Merge branch 'feature/reSeckill' into 'release/5.5'

秒杀商品详情页公用商品详情页js



See merge request !354
... ... @@ -5,7 +5,8 @@
const _ = require('lodash');
const detailModel = require('../models/detail');
const newDetailModel = require('../models/seckill-detail');
const seckillDetailModel = require('../models/seckill-detail');
const newDetailModel = require('../models/new-detail');
const listModel = require('../models/list');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const helpers = global.yoho.helpers;
... ... @@ -164,7 +165,7 @@ const newDetail = {
// 获取秒杀信息
getSeckillData(req, res) {
newDetailModel.getSeckillData({
seckillDetailModel.getSeckillData({
productskn: req.params.productskn
... ...
... ... @@ -3,396 +3,9 @@
*/
'use strict';
const _ = require('lodash');
const commentModel = require('./consult-comment');
const bundle = require('./bundle');
const productProcess = require(`${utils}/product-process`);
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const tool = {
prodessDetailData(origin) {
let dest = {}; // 结果输出
// 商品名称
if (!origin.product_name) {
return dest;
}
dest.goodsName = origin.product_name;
// 是否是虚拟商品
// dest.virtualGoods = (origin.attribute * 1 === 3);
// 活动促销短语
origin.market_phrase && origin.market_phrase !== ' ' && (dest.marketPhrase = origin.market_phrase);
// 商品促销短语
origin.sales_phrase && origin.sales_phrase !== ' ' && (dest.goodsSubtitle = origin.sales_phrase);
// 商品标签
if (origin.tags) {
let productTags = {};
_.forEach(origin.tags, function(value) {
productTags[value] = true;
});
dest.tags = productTags;
}
// 商品价格
let goodsPrice = {
currentPrice: origin.format_sales_price === '0' ? origin.format_market_price : origin.format_sales_price
};
if (origin.format_sales_price !== '0' && origin.format_market_price !== origin.format_sales_price) {
goodsPrice.previousPrice = origin.format_market_price;
}
dest.goodsPrice = goodsPrice;
// 商品返回 YOHO 币
// origin.yohoCoinNum && (dest.commodityReturn = origin.yohoCoinNum);
// 上市期
origin.expect_arrival_time && (dest.periodOfMarket = origin.expect_arrival_time);
// 品牌信息
if (origin.shop_id) {
let extra = `?productSkn=${origin.product_skn}&shopId=${origin.shop_id}`;
dest.preferenceUrl = `/product/detail/preference${extra}`;
}
// dest.brandId = origin.brand_info && origin.brand_info.brand_id || 0;
dest.brandId = _.get(origin, 'brand_info.brand_id', 0);
dest.productSkn = origin.product_skn;
dest.id = origin.product_id;
dest.goodsId = origin.goods_id;
dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售
dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀
dest.isLimitBuy = origin.isLimitBuy; // 是否 限购
dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售
dest.bundleType = origin.bundle_type; // 商品活动标记
// 自定义 属性
dest.showCoupon = !(
dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale
); // 商品有限购、秒杀、定金预售、普通预售 不显示领
// 20170113 要求关闭商品详情页面领券功能
// dest.showCoupon = false;
// 商品信息
if (origin.goods_list.length) {
let goodsGroup = [];
// pagecache重构
_.forEach(origin.goods_list, function(value) {
// 商品分组
if (value.images_list) {
_.forEach(value.images_list, function(good) {
goodsGroup.push({
goodsId: value.goods_id,
img: good.image_url
});
});
}
});
// 商品图:多个
if (goodsGroup.length > 1) {
let bannerList = [];
_.forEach(goodsGroup, function(value) {
value.img = _.replace(value.img, '/quality/80', '/quality/70');
bannerList.push({
img: value.img
});
});
dest.bannerTop = {
list: bannerList
};
} else if (goodsGroup[0]) {
dest.bannerTop = {
img: goodsGroup[0].img
};
}
}
// 底部简介URL链接
dest.introUrl = '/product/detail/intro/' + origin.product_skn;
return dest;
},
/**
* 处理品牌关联店铺信息
* @param {array}
* @return {array}
*/
processShopsInfo(data) {
let enterStore = [];
_.forEach(data, function(value) {
let shopInfo = {
img: value.brand_ico,
storeName: value.brand_name
};
if (value.shop_id) {
shopInfo.url = helpers.urlFormat('/product/index/brand', {
shop_id: value.shop_id
});
} else {
shopInfo.url = helpers.urlFormat('', null, value.brand_domain);
}
enterStore.push(shopInfo);
});
return enterStore;
},
/**
* 处理商品 feedback
* @param data feedback要处理数据
* {
* comment, defaultConsult, userConsult
* }
* @param productId 商品id
* @return feedback
*/
processFeedback(data, productId) {
// let {comment, defaultConsult, userConsult} = data;
let comment = data.comment;
let defaultConsult = data.defaultConsult;
let userConsult = data.userConsult;
let feedbacks = {consults: [], consultsNum: 0};
Object.assign(feedbacks, comment);
// 商品评价
feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', {
product_id: productId
});
/* 如果有用户咨询,显示用户咨询,否则显示常见问题 */
let obj = {};
if (userConsult.total) {
obj = {
commonConsults: false,
consultsNum: parseInt(userConsult.total, 10),
consults: _.take(userConsult.list, 2)
};
} else if (!_.isEmpty(defaultConsult) && !_.get(comment, 'consultsNum', 0)) {
obj = {
commonConsults: true,
consultsNum: true,
consults: _.take(defaultConsult.faq, 2)
};
}
Object.assign(feedbacks, obj);
if (_.get(feedbacks, 'consultsNum')) {
feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', {
product_id: productId,
total: feedbacks.consultsNum
});
} else {
feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', {
product_id: productId
});
}
return feedbacks;
},
/**
* 套餐数据处理
* @param bundleData
* @param skn
* @returns {{}}
*/
processBundle(bundleData, skn, gid) {
let subPrice = _.get(bundleData, 'bundleInfo.subPrice', 0);
return {
title: '优惠套装',
href: helpers.urlFormat('/product/bundle/detail', {skn: skn, gid: gid}),
description: subPrice ? '立省¥' + subPrice : 0,
productList: productProcess.processProductList(bundleData && bundleData.productList)
};
},
/**
* 处理量贩数据
* @param finalResult
* @param bundleData
*/
processDiscount(finalResult, bundleData) {
finalResult.discountBuy = {
num: _.get(bundleData, 'bundleInfo.bundleCount', 1),
promotionPhrase: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
discount: _.get(bundleData, 'bundleInfo.discount', 1)
};
let oldPromotion = finalResult.promotion;
finalResult.promotion = [{
promotionTitle: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
promotionType: '量贩'
}];
_.forEach(oldPromotion, value => {
finalResult.promotion.push(value);
});
}
};
const newDetail = {
getProductData(data) {
let params = {
method: 'app.product.data'
};
if (data.id) { // 通过 productId 获取商品详情
Object.assign(params, {
product_id: data.id
});
} else if (data.productSkn) { // 通过 productSkn 获取商品详情
Object.assign(params, {
product_skn: data.productSkn
});
}
return api.get('', params, {
code: 200,
cache: true
}).then(result => {
if (!result || result.code === 500 || !result.data) {
return {};
}
result.data.goods_id = data.goodsId;
return tool.prodessDetailData(result.data);
});
},
/*
获取 促销,评论,咨询,品牌信息
*/
querySknData(params) {
let brandId = params.brandId;
let productId = params.productId;
let skn = params.skn;
let gid = params.gid;
let apiArray = [
this.queryShopsByBrandId(brandId), // 0 品牌信息
commentModel.getCommentInfo({
productId: productId
}), // 1 评论信息
commentModel.getCommonConsult(), // 2 默认咨询信息
commentModel.getConsults(productId, 1, 2), // 3 咨询列表
this.queryPromotion(skn), // 4 促销活动
];
if (params.bundleType) {
apiArray.push(bundle.getBundleBySkn(skn));
}
return Promise.all(apiArray).then(info => {
let finalResult = {
promotion: null,
enterStore: null,
feedbacks: {
consults: [],
consultsNum: 0
},
};
finalResult.promotion = info[4];
finalResult.enterStore = info[0];
finalResult.feedbacks = tool.processFeedback({
comment: info[1],
defaultConsult: info[2],
userConsult: info[3]
}, productId);
let bundleData = _.get(info[5], 'data', null);
/* 套装 */
if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 1) {
finalResult.bundleData = tool.processBundle(bundleData, skn, gid);
}
/* 量贩 */
if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 2) {
tool.processDiscount(finalResult, bundleData);
}
return finalResult;
});
},
// ------------------------------接口
/*
接口: 根据BrandID, 查询品牌信息
*/
queryShopsByBrandId(brandId) {
let params = {
method: 'app.shop.queryShopsByBrandId',
brand_id: brandId
};
let cacheConf = {
cache: true
};
return api.get('', params, cacheConf)
.then(result => {
if (result && result.code === 200) {
return tool.processShopsInfo(result.data);
}
return [];
}, () => []);
},
/**
* 接口: 商品 促销活动
*/
queryPromotion(skn) {
let params = {
method: 'app.product.promotion',
product_skn: skn
};
let cacheConf = {
cache: true
};
return api.get('', params, cacheConf)
.then(result => {
if (result && result.code === 200) {
return result.data;
}
return {};
});
},
/**
* 获取秒杀列表
*/
... ... @@ -410,7 +23,7 @@ const newDetail = {
.catch()
.then(result => {
let data = {};
if (result.data) {
data = result.data;
if (data.storageSum > 0) {
... ...
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);
}
}
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 reg2 = /\/product\/([\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) || reg2.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');
// placeholder
var $feedbackStore = $('#placeholder-feedback-store');
var $promotion = $('#placeholder-promotion');
/**
* 渲染 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);
}
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('&#xe608;');
$discountFolder.slideDown();
} else {
$discountFirstItem.addClass('short-text');
$discountArrow.removeClass('icon-up').addClass('icon-down').html('&#xe609;');
$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.bundleDatas && info.bundleDatas.length) {
require('./detail/bundle').init(info.bundleDatas);
$('.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
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));
\ No newline at end of file
... ...
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);
}
}
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 reg2 = /\/product\/([\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) || reg2.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');
// placeholder
var $feedbackStore = $('#placeholder-feedback-store');
var $promotion = $('#placeholder-promotion');
/**
* 渲染 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);
}
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('&#xe608;');
$discountFolder.slideDown();
} else {
$discountFirstItem.addClass('short-text');
$discountArrow.removeClass('icon-up').addClass('icon-down').html('&#xe609;');
$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.bundleDatas && info.bundleDatas.length) {
require('./detail/bundle').init(info.bundleDatas);
$('.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
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));
require('./new-detail');
... ...
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();
// 调用秒杀js
$(window).on('seckill', function() {
require('./tick');
});
require('../common');
// 调用新商品详情页js
require('./new-detail');
// 领券
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('&#xe608;');
$discountFolder.slideDown();
} else {
$discountFirstItem.addClass('short-text');
$discountArrow.removeClass('icon-up').addClass('icon-down').html('&#xe609;');
$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));
... ...