Authored by 陈轩

Merge branch 'feature/newDetail' of http://git.yoho.cn/fe/yohobuywap-node into feature/newDetail

@@ -958,7 +958,7 @@ let _getPromotionInfo = (skn) => { @@ -958,7 +958,7 @@ let _getPromotionInfo = (skn) => {
958 */ 958 */
959 let _getFavorite = (productId, uid) => { 959 let _getFavorite = (productId, uid) => {
960 if (!uid) { 960 if (!uid) {
961 - return Promise.resolve({}); 961 + return Promise.resolve(false);
962 } 962 }
963 return singleAPI.get('favorite', { 963 return singleAPI.get('favorite', {
964 method: 'app.favorite.isFavoriteNew', 964 method: 'app.favorite.isFavoriteNew',
@@ -969,7 +969,7 @@ let _getFavorite = (productId, uid) => { @@ -969,7 +969,7 @@ let _getFavorite = (productId, uid) => {
969 return result.data; 969 return result.data;
970 } 970 }
971 971
972 - return {}; 972 + return false;
973 }); 973 });
974 }; 974 };
975 975
@@ -1489,7 +1489,7 @@ const _cartCount = (uid, shoppingKey) => { @@ -1489,7 +1489,7 @@ const _cartCount = (uid, shoppingKey) => {
1489 } 1489 }
1490 return count; 1490 return count;
1491 } 1491 }
1492 - return Promise.resolve(0); 1492 + return 0;
1493 }); 1493 });
1494 }; 1494 };
1495 1495
@@ -63,6 +63,8 @@ @@ -63,6 +63,8 @@
63 <i class="iconfont font-right pull-right">&#xe614;</i> 63 <i class="iconfont font-right pull-right">&#xe614;</i>
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 + {{!--占位: 促销--}}
  67 + <div id="placeholder-promotion"></div>
66 68
67 {{!-- 占位: 用户反馈, 店铺入口 --}} 69 {{!-- 占位: 用户反馈, 店铺入口 --}}
68 <div id="placeholder-feedback-store"></div> 70 <div id="placeholder-feedback-store"></div>
1 {{# cartInfo}} 1 {{# cartInfo}}
2 <div class="chose-panel"> 2 <div class="chose-panel">
3 <div class="main"> 3 <div class="main">
4 - <div class="infos"> 4 + <div class="infos {{#if @root.tickets}} tickets-info {{/if}}">
5 <div class="basic-info" > 5 <div class="basic-info" >
6 {{#each thumbs}} 6 {{#each thumbs}}
7 - {{#if @first}}  
8 - <img class="thumb" src="{{img}}">  
9 - {{/if}} 7 + <img class="thumb {{#unless @first}}hide{{/unless}}" src="{{img}}">
10 {{/each}} 8 {{/each}}
11 <div class="text-info"> 9 <div class="text-info">
12 <p class="name">{{name}}</p> 10 <p class="name">{{name}}</p>
13 <p class="price"> 11 <p class="price">
  12 + {{#if price}}
  13 + <span class="sale-price">{{salePrice}}</span>
  14 + <span class="market-price">{{price}}</span>
  15 + {{else}}
  16 + {{# isY isSecKill}}
14 <span class="sale-price">{{salePrice}}</span> 17 <span class="sale-price">{{salePrice}}</span>
15 - <span class="market-price data-bind"></span> 18 + <span class="market-price">{{salePrice}}</span>
  19 + {{else}}
  20 + <span class="sale-price no-price">{{salePrice}}</span>
  21 + {{/ isY}}
  22 + {{/if}}
16 </p> 23 </p>
17 </div> 24 </div>
18 </div> 25 </div>
19 <div class="chose-items"> 26 <div class="chose-items">
20 <div class="color-list block-list"> 27 <div class="color-list block-list">
21 - <span class="name">颜色</span>  
22 -  
23 -  
24 - <ul id="" data-index="" class="size-row clearfix ">  
25 - <li class="block" data-num="">  
26 - </li> 28 + <span class="name">{{#if @root.tickets}}日期{{else}}颜色{{/if}}</span>
  29 + {{#each colors}}
  30 + <ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/unless}}">
  31 + {{#each color}}
  32 + <li class="block {{#if chosed}} chosed{{/if}} {{#unless colorNum}} zero-stock{{/unless}}" data-num="{{colorNum}}">{{name}}</li>
  33 + {{/each}}
27 </ul> 34 </ul>
  35 + {{/each}}
28 </div> 36 </div>
29 -  
30 - <div class="size-list block-list">  
31 - <span class="name">尺码</span>  
32 - <ul class="size-row clearfix">  
33 - <li class="block " data-num="" data-id="" data-skuid="">  
34 - </li> 37 + <div class="size-list block-list {{#if @root.single}} hide{{/if}}">
  38 + <span class="name">{{#if @root.tickets}}区域{{else}}尺码{{/if}}</span>
  39 + {{#each sizes}}
  40 + <ul class="size-row clearfix {{#unless @first}}hide{{/unless}}">
  41 + {{#each size}}
  42 + <li class="block {{#if chosed}} chosed{{/if}} {{#unless sizeNum}} zero-stock {{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}" data-skuid="{{skuId}}">{{name}}</li>
  43 + {{/each}}
35 </ul> 44 </ul>
  45 + {{/each}}
36 </div> 46 </div>
37 -  
38 <div class="num"> 47 <div class="num">
39 <span class="name">数量</span> 48 <span class="name">数量</span>
40 <div class="clearfix"> 49 <div class="clearfix">
41 <a class="btn btn-minus" href="javascript:void(0);"> 50 <a class="btn btn-minus" href="javascript:void(0);">
42 - <span class="iconfont ">&#xe625;</span> 51 + <span class="iconfont {{#if promotionId}}disabled{{/if}}">&#xe625;</span>
43 </a> 52 </a>
44 <input id="good-num" class="good-num disabled" type="text" value="1" disabled="true"> 53 <input id="good-num" class="good-num disabled" type="text" value="1" disabled="true">
45 <a class="btn btn-plus" href="javascript:void(0);"> 54 <a class="btn btn-plus" href="javascript:void(0);">
46 - <span class="iconfont ">&#xe624;</span> 55 + <span class="iconfont {{#if promotionId}}disabled{{/if}}">&#xe624;</span>
47 </a> 56 </a>
48 </div> 57 </div>
49 <span class="left-num"></span> 58 <span class="left-num"></span>
50 <input id="left-num" type="hidden" value="0"> 59 <input id="left-num" type="hidden" value="0">
51 - <input id="limitNum" type="hidden" value=""> 60 + <input id="limitNum" type="hidden" value="{{limit}}">
52 </div> 61 </div>
53 -  
54 </div> 62 </div>
55 </div> 63 </div>
56 <div class="btn-wrap"> 64 <div class="btn-wrap">
57 - <button id="chose-btn-sure" class="btn btn-sure"></button> 65 + <button id="chose-btn-sure" class="btn btn-sure">{{#if @root.tickets}}立即购买{{else}}加入购物车{{/if}}</button>
58 </div> 66 </div>
59 </div> 67 </div>
60 - <input id="promotionId" type="hidden" value="">  
61 - <input id="single" type="hidden" value=""> 68 + <input id="promotionId" type="hidden" value="{{promotionId}}">
  69 + <input id="single" type="hidden" value="{{@root.single}}">
62 </div> 70 </div>
63 <div class="cart-bar"> 71 <div class="cart-bar">
64 {{#unless @root.wap.common.removeCartCount}} 72 {{#unless @root.wap.common.removeCartCount}}
  1 +{{!-- 商品促销 --}}
  2 +{{#if promotion}}
  3 +<div class="goods-discount" id="goodsDiscount">
  4 + {{#each promotion}}
  5 + {{#if @first}}
  6 + <h1 class="first-item short-text tap-hightlight">{{promotionTitle}}<span class="icon-down iconfont dropdown">&#xe609;</span></h1>
  7 + {{else}}
  8 + <div class="discount-folder">
  9 + <h1 class="folder-item tap-hightlight">{{promotionTitle}}</h1>
  10 + </div>
  11 + {{/if}}
  12 + {{/each}}
  13 +</div>
  14 +{{/if}}
@@ -178,11 +178,12 @@ function checkColorSizeNum() { @@ -178,11 +178,12 @@ function checkColorSizeNum() {
178 function show(html, cb) { 178 function show(html, cb) {
179 if (html) { 179 if (html) {
180 $chosePanel.html(html); 180 $chosePanel.html(html);
  181 + init();
  182 + }
  183 +
181 if ($('#promotionId').val() !== '') { 184 if ($('#promotionId').val() !== '') {
182 disableNumEdit(); 185 disableNumEdit();
183 } 186 }
184 - init();  
185 - }  
186 187
187 $('.chose-panel').show(); 188 $('.chose-panel').show();
188 $num = $('#good-num'); 189 $num = $('#good-num');
@@ -558,7 +559,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -558,7 +559,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
558 $chosed = $('.block-list>ul>li.chosed'); 559 $chosed = $('.block-list>ul>li.chosed');
559 560
560 if ($chosed.length === 2 && $chosed.closest('.zero-stock').length === 0) { 561 if ($chosed.length === 2 && $chosed.closest('.zero-stock').length === 0) {
561 - isSecKills = $('.seckill-time').length;// 秒杀标记 562 + isSecKills = $('.seckill-time').length; // 秒杀标记
562 563
563 productSku = $curSizeBlock.data('skuid'); 564 productSku = $curSizeBlock.data('skuid');
564 promotionId = $('#promotionId').val(); 565 promotionId = $('#promotionId').val();
@@ -591,7 +592,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -591,7 +592,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
591 url = '/cart/index/modify'; 592 url = '/cart/index/modify';
592 593
593 } else if (limitProductCode) { 594 } else if (limitProductCode) {
594 - isSecKills = $('.seckill-time').length;// 秒杀标记 595 + isSecKills = $('.seckill-time').length; // 秒杀标记
595 $(this).css('background-color', '#ccc').removeAttr('id'); 596 $(this).css('background-color', '#ccc').removeAttr('id');
596 597
597 // 当前面板选择的是限购商品 598 // 当前面板选择的是限购商品
  1 +/**
  2 + * 判断是否是Y,应对接口经常返回Y/N做boolean
  3 + * @param string value
  4 + */
  5 +module.exports = function(value, options) {
  6 + if (value === 'Y') {
  7 + return options.fn(this);
  8 + } else {
  9 + return options.inverse(this);
  10 + }
  11 +};
1 -/*  
2 - 商品详情页:异步获取品牌信息, 评论,  
3 -  
4 - */  
5 -'use strict';  
@@ -2,9 +2,9 @@ var $ = require('yoho-jquery'), @@ -2,9 +2,9 @@ var $ = require('yoho-jquery'),
2 lazyLoad = require('yoho-jquery-lazyload'), 2 lazyLoad = require('yoho-jquery-lazyload'),
3 Swiper = require('yoho-swiper'), 3 Swiper = require('yoho-swiper'),
4 tip = require('../plugin/tip'), 4 tip = require('../plugin/tip'),
5 - chosePanel = require('../common/chose-panel'),  
6 - dialog = require('../plugin/dialog'),  
7 - dbClass = 'data-bind'; 5 + dialog = require('../plugin/dialog');
  6 +
  7 +var dbClass = 'data-bind';
8 8
9 require('../common'); 9 require('../common');
10 10
@@ -37,7 +37,9 @@ var infoDataHbs = require('product/detail/infodata.hbs'); @@ -37,7 +37,9 @@ var infoDataHbs = require('product/detail/infodata.hbs');
37 var priceDataHbs = require('product/detail/pricedata.hbs'); 37 var priceDataHbs = require('product/detail/pricedata.hbs');
38 38
39 var renderInfo = function(data) { 39 var renderInfo = function(data) {
40 - if (!data) { return; } 40 + if (!data) {
  41 + return;
  42 + }
41 43
42 // 商品价格 44 // 商品价格
43 if (data.goodsPrice) { 45 if (data.goodsPrice) {
@@ -69,8 +71,6 @@ var renderInfo = function(data) { @@ -69,8 +71,6 @@ var renderInfo = function(data) {
69 return false; 71 return false;
70 }); 72 });
71 }, 200); 73 }, 200);
72 - } else {  
73 - chosePanel(data);  
74 } 74 }
75 }; 75 };
76 76
@@ -140,6 +140,8 @@ var getInfoData = function() { @@ -140,6 +140,8 @@ var getInfoData = function() {
140 rightBtnText: '打开Yoho!Buy有货APP' 140 rightBtnText: '打开Yoho!Buy有货APP'
141 } 141 }
142 }, function() { 142 }, function() {
  143 + var appUrl = $('input[name="limitCodeUrl"]').val();
  144 +
143 ifr = document.createElement('iframe'); 145 ifr = document.createElement('iframe');
144 ifr.src = appUrl; 146 ifr.src = appUrl;
145 ifr.style.display = 'none'; 147 ifr.style.display = 'none';
@@ -173,15 +175,16 @@ var getInfoData = function() { @@ -173,15 +175,16 @@ var getInfoData = function() {
173 /* 175 /*
174 * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化 176 * 获取商品 相关数据: 1. 促销 2. feedback 3. 店铺, 并初始化
175 */ 177 */
176 -+(function(skn, productId, brandId) { // eslint-disable-line 178 ++
  179 +(function(skn, productId, brandId) { // eslint-disable-line
177 // 模版: 促销, feedback, 店铺 180 // 模版: 促销, feedback, 店铺
178 - // var promotion = require('product/detail/promotion.hbs'); 181 + var promotionT = require('product/detail/promotion.hbs');
179 var feedbackT = require('product/detail/feedbacks.hbs'); 182 var feedbackT = require('product/detail/feedbacks.hbs');
180 var enterStoreT = require('product/detail/enterStore.hbs'); 183 var enterStoreT = require('product/detail/enterStore.hbs');
181 184
182 // placeholder 185 // placeholder
183 var $feedbackStore = $('#placeholder-feedback-store'); 186 var $feedbackStore = $('#placeholder-feedback-store');
184 - 187 + var $promotion = $('#placeholder-promotion');
185 188
186 /** 189 /**
187 * 渲染 feedback, 店铺, 替换placeholder 190 * 渲染 feedback, 店铺, 替换placeholder
@@ -204,18 +207,67 @@ var getInfoData = function() { @@ -204,18 +207,67 @@ var getInfoData = function() {
204 } 207 }
205 208
206 209
  210 + /**
  211 + * 渲染 促销, 替换placeholder
  212 + * @param data
  213 + * {
  214 + * promotion
  215 + * }
  216 + * @param $placeholder
  217 + */
  218 + function renderPromotion(data, $placeholder) {
  219 + var promotionHtml = promotionT({
  220 + promotion: data.promotion
  221 + });
  222 +
  223 + return $placeholder.replaceWith(promotionHtml);
  224 + }
  225 +
  226 + function promotionInit() {
  227 + var $goodsDiscount = $('#goodsDiscount');
  228 + var $discountFirstItem = $goodsDiscount.find('.first-item');
  229 + var $discountFolder = $goodsDiscount.find('.discount-folder');
  230 + var $discountArrow = $goodsDiscount.find('.first-item span');
  231 +
  232 + // 初始化goods-discount
  233 + if ($discountFolder.children().length === 0) {
  234 + $discountFolder.css('display', 'none');
  235 + $discountArrow.html('');
  236 + }
  237 +
  238 + // goods-discount下拉按钮点击事件
  239 + if ($goodsDiscount.length && $discountFolder.children().length > 0) {
  240 + $goodsDiscount.on('click', function() {
  241 + if ($discountFolder.is(':hidden')) {
  242 + $discountFirstItem.removeClass('short-text');
  243 + $discountArrow.removeClass('icon-down').addClass('icon-up').html('&#xe608;');
  244 + $discountFolder.slideDown();
  245 + } else {
  246 + $discountFirstItem.addClass('short-text');
  247 + $discountArrow.removeClass('icon-up').addClass('icon-down').html('&#xe609;');
  248 + $discountFolder.slideUp();
  249 + }
  250 + });
  251 + }
  252 + }
  253 +
  254 +
  255 + // boot
207 $.get('/product/detail/sknData.json', { 256 $.get('/product/detail/sknData.json', {
208 skn: skn, 257 skn: skn,
209 productId: productId, 258 productId: productId,
210 brandId: brandId 259 brandId: brandId
211 }).done(function(info) { 260 }).done(function(info) {
212 - renderFeedbackStore({  
213 - feedbacks: info.feedbacks,  
214 - enterStore: info.enterStore  
215 - }, $feedbackStore); 261 + // step1: render dom
  262 + renderFeedbackStore(info, $feedbackStore);
  263 + renderPromotion(info, $promotion);
  264 +
  265 + // step2: init js
  266 + require('./detail/comments-consults');
  267 + require('./detail/consultform'); // TODO
  268 + promotionInit();
216 }); 269 });
217 }(productSkn, productId, brandId)); 270 }(productSkn, productId, brandId));
218 271
219 // 初始化执行 272 // 初始化执行
220 getInfoData(); 273 getInfoData();
221 -