Authored by 陈轩

save

... ... @@ -49,13 +49,14 @@ const newDetail = {
sknData(req, res, next) {
let brandId = req.query.brandId;
let productId = req.query.productId;
let skn = req.query.skn;
if ([brandId, productId].some(val => !val)) {
return next();
}
detailModel.querySknData({
brandId, productId
newDetailModel.querySknData({
skn, brandId, productId
}).then(result => {
if (_.isEmpty(result)) {
return next();
... ...
... ... @@ -7,6 +7,7 @@ const comment = require('./consult-comment');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const tool = {
prodessDetailData(origin) {
... ... @@ -107,6 +108,33 @@ const tool = {
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;
}
};
... ... @@ -149,20 +177,22 @@ const newDetail = {
let skn = params.skn;
return Promise.all([
this.queryShopsByBrandId(brandId), // 0 品牌信息
comment.getCommentInfo({productId: productId}), // 1 评论信息
comment.getCommonConsult(), // 2 默认咨询信息
comment.getConsults(productId, 1, 2), // 3 咨询列表
this.queryPromotion(skn) // 4 促销活动
this.queryShopsByBrandId(brandId), // 0 品牌信息
comment.getCommentInfo({
productId: productId
}), // 1 评论信息
comment.getCommonConsult(), // 2 默认咨询信息
comment.getConsults(productId, 1, 2), // 3 咨询列表
this.queryPromotion(skn) // 4 促销活动
]).then(info => {
let finalResult = {
promotion: null,
enterStroe: null,
enterStore: null,
feedbacks: null,
};
finalResult.promotion = info[4];
finalResult.enterStroe = info[0];
finalResult.enterStore = info[0];
finalResult.feedbacks = info[1];
let feedback = {};
... ... @@ -202,7 +232,13 @@ const newDetail = {
cache: true
};
return api.get('', params, cacheConf);
return api.get('', params, cacheConf)
.then(result => {
if (result.code === 200) {
return tool.processShopsInfo(result.data);
}
return [];
}, () => []);
},
/**
... ...
... ... @@ -64,6 +64,9 @@
<i class="iconfont font-quan">&#xe900;</i><span>领取优惠券</span>
</div>
{{!-- 占位: 用户反馈, 店铺入口 --}}
<div id="placeholder-feedback-store"></div>
<div id="product-desc" {{#if limit}}class="limit"{{/if}}> </div>
{{> detail/recommend-for-you}}
... ... @@ -86,7 +89,5 @@
<input id="brand-id" type="hidden" value="{{brandId}}">
<input id="product-limit" type="hidden" value="{{isLimitBuy}}">
{{!-- 占位: 用户反馈, 店铺入口 --}}
<div></div>
</div>
{{/ result}}
... ...
... ... @@ -84,7 +84,7 @@ module.exports = {
port: '4444' // influxdb port
},
console: {
level: 'debug',
level: 'info',
colorize: 'all',
prettyPrint: true
}
... ...
{{# enterStore}}
<div id="enter-store" class="enter-store page-block tap-hightlight">
<a class="store-logo" href="{{url}}" style="">
<img class="lazy" src="{{image img 47 47}}" alt="{{storeName}}">
</a>
<a class="store-name" href="{{url}}">{{storeName}}</a>
<a class="store-link" href="{{url}}">进入店铺<span class="iconfont">&#xe604;</span></a>
</div>
{{/ enterStore}}
\ No newline at end of file
... ...
<ul id="nav-tab" class="nav-tab clearfix">
<li class="comment-nav tap-hightlight">商品评价(<span class="comments-num">{{commentsNum}}</span>)</li>
{{#if commonConsults}}
<li class="consult-nav tap-hightlight">常见问题</li>
{{^}}
<li class="consult-nav tap-hightlight">购买咨询(<span class="consults-num">{{consultsNum}}</span>)</li>
{{/if}}
</ul>
<div id="feedback-content" >
<div class="comment-content content ">
{{#if commentsNum}}
<div class="comment-content-main content-main">
{{# comments}}
<span class="user-name">
{{userName}}
</span>
<span class="goods-spec">
购买了{{desc}}
</span>
<p class="detail-content">
{{content}}
</p>
<span class="comment-time">
{{time}}
</span>
{{/ comments}}
</div>
<a class="comment-content-footer tap-hightlight" href="{{commentsUrl}}">
查看更多
<span class="iconfont">&#xe604;</span>
</a>
{{^}}
<div class="comment-content-main content-main no-item">
<span class="iconfont">&#xe63d;</span>暂无评论
</div>
{{/if}}
</div>
<div class="consult-content content hide ">
{{#if consultsNum}}
<div class="consult-content-main content-main">
{{# consults}}
<div class="question">
<span class="iconfont">&#xe644;</span>
<p>
{{question}}<br>
<span class="time">{{time}}</span>
</p>
</div>
<div class="answer">
<span class="iconfont">&#xe642;</span>
<p>{{answer}}</p>
</div>
{{/ consults}}
</div>
<a class="consult-content-footer tap-hightlight" href="{{consultsUrl}}">
查看更多
<span class="iconfont">&#xe604;</span>
</a>
{{else}}
<div class="consult-content-main content-main no-item">
<span class="iconfont">&#xe63f;</span>暂无咨询
</div>
<div class="consult-content-footer tap-hightlight">
<a href="{{consultsUrl}}">
我要咨询
<span class="iconfont">&#xe604;</span></a>
</div>
{{/if}}
</div>
</div>
\ No newline at end of file
... ...
{{# feedbacks}}
<div class="feedback-list ">
{{#if commentsNum}}
{{> ./feedback-tab}}
{{else}}
{{#if consultsNum}}
{{> ./feedback-tab}}
{{else}}
<div class="nodata tap-hightlight" id="goto-consult">
<span>暂无商品评价和咨询</span>
<a href="{{consultsUrl}}" class="go-consult">我要咨询<span class="iconfont">&#xe604;</span></a>
</div>
{{/if}}
{{/if}}
</div>
{{/ feedbacks}}
\ No newline at end of file
... ...
/*
商品详情页:异步获取品牌信息, 评论,
*/
'use strict';
... ...
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper'),
tip = require('../plugin/tip'),
chosePanel = require('../common/chose-panel'),
... ... @@ -18,6 +19,11 @@ new Swiper('.banner-swiper', {
spaceBetween: 3
});
var productId = $('#productId').val();
var goodsId = $('#goodsId').val();
var productSkn = $('#productSkn').val();
var brandId = $('#brand-id').val();
// 领券
require('./detail/brand-coupon');
... ... @@ -70,9 +76,6 @@ var renderInfo = function(data) {
// 动态加载数据
var getInfoData = function() {
var productId = $('#productId').val();
var goodsId = $('#goodsId').val();
var productSkn = $('#productSkn').val();
if (productId && (goodsId || productSkn)) {
$.ajax({
type: 'POST',
... ... @@ -91,6 +94,7 @@ var getInfoData = function() {
// 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').val() + '.html');
... ... @@ -165,5 +169,53 @@ var getInfoData = function() {
}
};
/*
* 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化
*/
+(function(skn, productId, brandId) { // eslint-disable-line
// 模版: 促销, feedback, 店铺
// var promotion = 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');
/**
* 渲染 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]);
}
$.get('/product/detail/sknData.json', {
skn: skn,
productId: productId,
brandId: brandId
}).done(function(info) {
renderFeedbackStore({
feedbacks: info.feedbacks,
enterStore: info.enterStore
}, $feedbackStore);
});
}(productSkn, productId, brandId));
// 初始化执行
getInfoData();
... ...