Authored by 陈轩

save

@@ -49,13 +49,14 @@ const newDetail = { @@ -49,13 +49,14 @@ const newDetail = {
49 sknData(req, res, next) { 49 sknData(req, res, next) {
50 let brandId = req.query.brandId; 50 let brandId = req.query.brandId;
51 let productId = req.query.productId; 51 let productId = req.query.productId;
  52 + let skn = req.query.skn;
52 53
53 if ([brandId, productId].some(val => !val)) { 54 if ([brandId, productId].some(val => !val)) {
54 return next(); 55 return next();
55 } 56 }
56 57
57 - detailModel.querySknData({  
58 - brandId, productId 58 + newDetailModel.querySknData({
  59 + skn, brandId, productId
59 }).then(result => { 60 }).then(result => {
60 if (_.isEmpty(result)) { 61 if (_.isEmpty(result)) {
61 return next(); 62 return next();
@@ -7,6 +7,7 @@ const comment = require('./consult-comment'); @@ -7,6 +7,7 @@ const comment = require('./consult-comment');
7 7
8 8
9 const api = global.yoho.API; 9 const api = global.yoho.API;
  10 +const helpers = global.yoho.helpers;
10 11
11 const tool = { 12 const tool = {
12 prodessDetailData(origin) { 13 prodessDetailData(origin) {
@@ -107,6 +108,33 @@ const tool = { @@ -107,6 +108,33 @@ const tool = {
107 dest.introUrl = '/product/detail/intro/' + origin.product_skn; 108 dest.introUrl = '/product/detail/intro/' + origin.product_skn;
108 109
109 return dest; 110 return dest;
  111 + },
  112 +
  113 + /**
  114 + * 处理品牌关联店铺信息
  115 + * @param {array}
  116 + * @return {array}
  117 + */
  118 + processShopsInfo(data) {
  119 + let enterStore = [];
  120 +
  121 + _.forEach(data, function(value) {
  122 + let shopInfo = {
  123 + img: value.brand_ico,
  124 + storeName: value.brand_name
  125 + };
  126 +
  127 + if (value.shop_id) {
  128 + shopInfo.url = helpers.urlFormat('/product/index/brand', {
  129 + shop_id: value.shop_id
  130 + });
  131 + } else {
  132 + shopInfo.url = helpers.urlFormat('', null, value.brand_domain);
  133 + }
  134 +
  135 + enterStore.push(shopInfo);
  136 + });
  137 + return enterStore;
110 } 138 }
111 }; 139 };
112 140
@@ -149,20 +177,22 @@ const newDetail = { @@ -149,20 +177,22 @@ const newDetail = {
149 let skn = params.skn; 177 let skn = params.skn;
150 178
151 return Promise.all([ 179 return Promise.all([
152 - this.queryShopsByBrandId(brandId), // 0 品牌信息  
153 - comment.getCommentInfo({productId: productId}), // 1 评论信息  
154 - comment.getCommonConsult(), // 2 默认咨询信息  
155 - comment.getConsults(productId, 1, 2), // 3 咨询列表  
156 - this.queryPromotion(skn) // 4 促销活动 180 + this.queryShopsByBrandId(brandId), // 0 品牌信息
  181 + comment.getCommentInfo({
  182 + productId: productId
  183 + }), // 1 评论信息
  184 + comment.getCommonConsult(), // 2 默认咨询信息
  185 + comment.getConsults(productId, 1, 2), // 3 咨询列表
  186 + this.queryPromotion(skn) // 4 促销活动
157 ]).then(info => { 187 ]).then(info => {
158 let finalResult = { 188 let finalResult = {
159 promotion: null, 189 promotion: null,
160 - enterStroe: null, 190 + enterStore: null,
161 feedbacks: null, 191 feedbacks: null,
162 }; 192 };
163 193
164 finalResult.promotion = info[4]; 194 finalResult.promotion = info[4];
165 - finalResult.enterStroe = info[0]; 195 + finalResult.enterStore = info[0];
166 finalResult.feedbacks = info[1]; 196 finalResult.feedbacks = info[1];
167 197
168 let feedback = {}; 198 let feedback = {};
@@ -202,7 +232,13 @@ const newDetail = { @@ -202,7 +232,13 @@ const newDetail = {
202 cache: true 232 cache: true
203 }; 233 };
204 234
205 - return api.get('', params, cacheConf); 235 + return api.get('', params, cacheConf)
  236 + .then(result => {
  237 + if (result.code === 200) {
  238 + return tool.processShopsInfo(result.data);
  239 + }
  240 + return [];
  241 + }, () => []);
206 }, 242 },
207 243
208 /** 244 /**
@@ -64,6 +64,9 @@ @@ -64,6 +64,9 @@
64 <i class="iconfont font-quan">&#xe900;</i><span>领取优惠券</span> 64 <i class="iconfont font-quan">&#xe900;</i><span>领取优惠券</span>
65 </div> 65 </div>
66 66
  67 + {{!-- 占位: 用户反馈, 店铺入口 --}}
  68 + <div id="placeholder-feedback-store"></div>
  69 +
67 <div id="product-desc" {{#if limit}}class="limit"{{/if}}> </div> 70 <div id="product-desc" {{#if limit}}class="limit"{{/if}}> </div>
68 {{> detail/recommend-for-you}} 71 {{> detail/recommend-for-you}}
69 72
@@ -86,7 +89,5 @@ @@ -86,7 +89,5 @@
86 <input id="brand-id" type="hidden" value="{{brandId}}"> 89 <input id="brand-id" type="hidden" value="{{brandId}}">
87 <input id="product-limit" type="hidden" value="{{isLimitBuy}}"> 90 <input id="product-limit" type="hidden" value="{{isLimitBuy}}">
88 91
89 - {{!-- 占位: 用户反馈, 店铺入口 --}}  
90 - <div></div>  
91 </div> 92 </div>
92 {{/ result}} 93 {{/ result}}
@@ -84,7 +84,7 @@ module.exports = { @@ -84,7 +84,7 @@ module.exports = {
84 port: '4444' // influxdb port 84 port: '4444' // influxdb port
85 }, 85 },
86 console: { 86 console: {
87 - level: 'debug', 87 + level: 'info',
88 colorize: 'all', 88 colorize: 'all',
89 prettyPrint: true 89 prettyPrint: true
90 } 90 }
  1 +{{# enterStore}}
  2 +<div id="enter-store" class="enter-store page-block tap-hightlight">
  3 + <a class="store-logo" href="{{url}}" style="">
  4 + <img class="lazy" src="{{image img 47 47}}" alt="{{storeName}}">
  5 + </a>
  6 + <a class="store-name" href="{{url}}">{{storeName}}</a>
  7 + <a class="store-link" href="{{url}}">进入店铺<span class="iconfont">&#xe604;</span></a>
  8 +</div>
  9 +{{/ enterStore}}
  1 +<ul id="nav-tab" class="nav-tab clearfix">
  2 + <li class="comment-nav tap-hightlight">商品评价(<span class="comments-num">{{commentsNum}}</span>)</li>
  3 + {{#if commonConsults}}
  4 + <li class="consult-nav tap-hightlight">常见问题</li>
  5 + {{^}}
  6 + <li class="consult-nav tap-hightlight">购买咨询(<span class="consults-num">{{consultsNum}}</span>)</li>
  7 + {{/if}}
  8 +</ul>
  9 +<div id="feedback-content" >
  10 + <div class="comment-content content ">
  11 + {{#if commentsNum}}
  12 + <div class="comment-content-main content-main">
  13 + {{# comments}}
  14 + <span class="user-name">
  15 + {{userName}}
  16 + </span>
  17 + <span class="goods-spec">
  18 + 购买了{{desc}}
  19 + </span>
  20 + <p class="detail-content">
  21 + {{content}}
  22 + </p>
  23 + <span class="comment-time">
  24 + {{time}}
  25 + </span>
  26 + {{/ comments}}
  27 + </div>
  28 + <a class="comment-content-footer tap-hightlight" href="{{commentsUrl}}">
  29 + 查看更多
  30 + <span class="iconfont">&#xe604;</span>
  31 + </a>
  32 + {{^}}
  33 + <div class="comment-content-main content-main no-item">
  34 + <span class="iconfont">&#xe63d;</span>暂无评论
  35 + </div>
  36 + {{/if}}
  37 + </div>
  38 +
  39 + <div class="consult-content content hide ">
  40 + {{#if consultsNum}}
  41 + <div class="consult-content-main content-main">
  42 + {{# consults}}
  43 + <div class="question">
  44 + <span class="iconfont">&#xe644;</span>
  45 + <p>
  46 + {{question}}<br>
  47 + <span class="time">{{time}}</span>
  48 + </p>
  49 + </div>
  50 +
  51 + <div class="answer">
  52 + <span class="iconfont">&#xe642;</span>
  53 + <p>{{answer}}</p>
  54 + </div>
  55 + {{/ consults}}
  56 + </div>
  57 + <a class="consult-content-footer tap-hightlight" href="{{consultsUrl}}">
  58 + 查看更多
  59 + <span class="iconfont">&#xe604;</span>
  60 + </a>
  61 + {{else}}
  62 + <div class="consult-content-main content-main no-item">
  63 + <span class="iconfont">&#xe63f;</span>暂无咨询
  64 + </div>
  65 +
  66 + <div class="consult-content-footer tap-hightlight">
  67 + <a href="{{consultsUrl}}">
  68 + 我要咨询
  69 + <span class="iconfont">&#xe604;</span></a>
  70 + </div>
  71 + {{/if}}
  72 + </div>
  73 +</div>
  1 +{{# feedbacks}}
  2 +<div class="feedback-list ">
  3 + {{#if commentsNum}}
  4 + {{> ./feedback-tab}}
  5 + {{else}}
  6 + {{#if consultsNum}}
  7 + {{> ./feedback-tab}}
  8 + {{else}}
  9 + <div class="nodata tap-hightlight" id="goto-consult">
  10 + <span>暂无商品评价和咨询</span>
  11 + <a href="{{consultsUrl}}" class="go-consult">我要咨询<span class="iconfont">&#xe604;</span></a>
  12 + </div>
  13 + {{/if}}
  14 + {{/if}}
  15 +</div>
  16 +{{/ feedbacks}}
  1 +/*
  2 + 商品详情页:异步获取品牌信息, 评论,
  3 +
  4 + */
  5 +'use strict';
1 var $ = require('yoho-jquery'), 1 var $ = require('yoho-jquery'),
  2 + lazyLoad = require('yoho-jquery-lazyload'),
2 Swiper = require('yoho-swiper'), 3 Swiper = require('yoho-swiper'),
3 tip = require('../plugin/tip'), 4 tip = require('../plugin/tip'),
4 chosePanel = require('../common/chose-panel'), 5 chosePanel = require('../common/chose-panel'),
@@ -18,6 +19,11 @@ new Swiper('.banner-swiper', { @@ -18,6 +19,11 @@ new Swiper('.banner-swiper', {
18 spaceBetween: 3 19 spaceBetween: 3
19 }); 20 });
20 21
  22 +var productId = $('#productId').val();
  23 +var goodsId = $('#goodsId').val();
  24 +var productSkn = $('#productSkn').val();
  25 +var brandId = $('#brand-id').val();
  26 +
21 // 领券 27 // 领券
22 require('./detail/brand-coupon'); 28 require('./detail/brand-coupon');
23 29
@@ -70,9 +76,6 @@ var renderInfo = function(data) { @@ -70,9 +76,6 @@ var renderInfo = function(data) {
70 76
71 // 动态加载数据 77 // 动态加载数据
72 var getInfoData = function() { 78 var getInfoData = function() {
73 - var productId = $('#productId').val();  
74 - var goodsId = $('#goodsId').val();  
75 - var productSkn = $('#productSkn').val();  
76 if (productId && (goodsId || productSkn)) { 79 if (productId && (goodsId || productSkn)) {
77 $.ajax({ 80 $.ajax({
78 type: 'POST', 81 type: 'POST',
@@ -91,6 +94,7 @@ var getInfoData = function() { @@ -91,6 +94,7 @@ var getInfoData = function() {
91 // var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/; 94 // var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/;
92 var thisHref = window.location.href; 95 var thisHref = window.location.href;
93 var thisRefer = document.referrer; 96 var thisRefer = document.referrer;
  97 +
94 if (!regSeckill.test(thisRefer)) { 98 if (!regSeckill.test(thisRefer)) {
95 if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) { 99 if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) {
96 window.location.replace('/product/seckill/show_' + $('#productSkn').val() + '.html'); 100 window.location.replace('/product/seckill/show_' + $('#productSkn').val() + '.html');
@@ -165,5 +169,53 @@ var getInfoData = function() { @@ -165,5 +169,53 @@ var getInfoData = function() {
165 } 169 }
166 }; 170 };
167 171
  172 +
  173 +/*
  174 + * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化
  175 + */
  176 ++(function(skn, productId, brandId) { // eslint-disable-line
  177 + // 模版: 促销, feedback, 店铺
  178 + // var promotion = require('product/detail/promotion.hbs');
  179 + var feedbackT = require('product/detail/feedbacks.hbs');
  180 + var enterStoreT = require('product/detail/enterStore.hbs');
  181 +
  182 + // placeholder
  183 + var $feedbackStore = $('#placeholder-feedback-store');
  184 +
  185 +
  186 + /**
  187 + * 渲染 feedback, 店铺, 替换placeholder
  188 + * @param data
  189 + * {
  190 + * enterStore, feedback
  191 + * }
  192 + * @param $placeholder
  193 + */
  194 + function renderFeedbackStore(data, $placeholder) {
  195 + var feedbackHtml = feedbackT({
  196 + feedbacks: data.feedbacks
  197 + });
  198 +
  199 + var enterStoreHtml = enterStoreT({
  200 + enterStore: data.enterStore
  201 + });
  202 +
  203 + return $placeholder.replaceWith([feedbackHtml, enterStoreHtml]);
  204 + }
  205 +
  206 +
  207 + $.get('/product/detail/sknData.json', {
  208 + skn: skn,
  209 + productId: productId,
  210 + brandId: brandId
  211 + }).done(function(info) {
  212 + renderFeedbackStore({
  213 + feedbacks: info.feedbacks,
  214 + enterStore: info.enterStore
  215 + }, $feedbackStore);
  216 + });
  217 +}(productSkn, productId, brandId));
  218 +
168 // 初始化执行 219 // 初始化执行
169 getInfoData(); 220 getInfoData();
  221 +