Authored by 刘传洋

m

@@ -375,7 +375,7 @@ const getRecommendProductAction = (req, res) => { @@ -375,7 +375,7 @@ const getRecommendProductAction = (req, res) => {
375 'data': { 375 'data': {
376 'header': '\u4e3a\u60a8\u4f18\u9009', 376 'header': '\u4e3a\u60a8\u4f18\u9009',
377 'hasPrev': false, 377 'hasPrev': false,
378 - 'hasNext': true, 378 + 'hasNext': false,
379 'item': [{ 379 'item': [{
380 'id': 493102, 380 'id': 493102,
381 'skn': 51295054, 381 'skn': 51295054,
@@ -831,8 +831,8 @@ const getRecommendProduct = (channel, uid, udid, page) => { @@ -831,8 +831,8 @@ const getRecommendProduct = (channel, uid, udid, page) => {
831 }); 831 });
832 832
833 Object.assign(result.data, { 833 Object.assign(result.data, {
834 - hasPrev: page > 1,  
835 - hasNext: plist.length >= end, 834 + // hasPrev: page > 1,
  835 + // hasNext: plist.length >= end,
836 item: items 836 item: items
837 }); 837 });
838 838
@@ -311,59 +311,29 @@ @@ -311,59 +311,29 @@
311 </div> 311 </div>
312 312
313 {{#unless @root.pc.product.removeRecentView}} 313 {{#unless @root.pc.product.removeRecentView}}
314 - <div class="lazy-load-object">  
315 - <textarea class="datalazyload" style="visibility: hidden;"> 314 + <div>
  315 + <textarea class="lazy-load-object" style="visibility: hidden;">
316 <script> 316 <script>
317 - fetchRecommend(); 317 + loadFineProduct();
  318 + fetchLatestWalk();
318 </script> 319 </script>
319 </textarea> 320 </textarea>
320 </div> 321 </div>
321 322
322 <div class="bottom-tab bottom-tab-slide"> 323 <div class="bottom-tab bottom-tab-slide">
323 - <span class="bottom-title {{#if cart.deleteShop}}cur{{/if}} {{#unless cart.deleteShop}}none{{/unless}}">凑单商品</span>  
324 - <span class="bottom-title {{#unless cart.deleteShop}}cur{{/unless}}">为您优选</span>  
325 - <span class="bottom-title">最近浏览</span> 324 + {{!--<span class="bottom-title {{#if cart.deleteShop}}cur{{/if}}
  325 + {{#unless cart.deleteShop}}none{{/unless}}">凑单商品</span>--}}
  326 + <span class="bottom-title cur" data-type="fine">为您优选</span>
  327 + <span class="bottom-title" data-role="latestWalk-tab">最近浏览</span>
326 <span class="change">换一批 328 <span class="change">换一批
327 <span class="iconfont change-icon">&#xe639;</span> 329 <span class="iconfont change-icon">&#xe639;</span>
328 </span> 330 </span>
329 </div> 331 </div>
330 332
331 - <div class="individual-slide">  
332 - <div data-role="together-slide"></div>  
333 - <div data-role="fine-slide"></div>  
334 - <div data-role="latestWalk-slide"></div>  
335 -  
336 -  
337 - <!--<div class="individual-item individual-item-togetherGoods {{#unless cart.deleteShop}}none{{/unless}}">  
338 - <input id="" type="hidden" value="">  
339 - <ul id="" class="goods clearfix img-list">  
340 - {{>individual-slide}}  
341 - </ul>  
342 - <div class="img-brand-switch">  
343 - <a class="prev iconfont" href="javascript:;"></a>  
344 - <a class="next iconfont" href="javascript:;"></a>  
345 - </div>  
346 - </div>  
347 - <div class="individual-item individual-item-recommendGoods {{#if cart.deleteShop}}none{{/if}}">  
348 - <input id="" type="hidden" value="{{latestWalk}}">  
349 - <ul id="" class="goods img-list clearfix">  
350 - {{>individual-slide}}  
351 - </ul>  
352 - <div class="img-brand-switch">  
353 - <a class="prev iconfont " href="javascript:;"></a>  
354 - <a class="next iconfont" href="javascript:;"></a>  
355 - </div>  
356 - </div>  
357 - <div class="individual-item individual-item-latestWalk">  
358 - <input id="latest-walk-count" type="hidden" value="">  
359 - <ul id="latest-walk-goods" class="goods clearfix img-list">  
360 - {{>individual-slide}}  
361 - </ul>  
362 - <div class="img-brand-switch">  
363 - <a class="prev iconfont" href="javascript:;"></a>  
364 - <a class="next iconfont" href="javascript:;"></a>  
365 - </div>  
366 - </div>--> 333 + <div class="individual-slide bottom-slide-content">
  334 + <!--<div data-role="together-slide" class="slide-panel"></div>-->
  335 + <div data-role="fine-slide" class="slide-panel"></div>
  336 + <div data-role="latestWalk-slide" class="slide-panel" style="display:none;"></div>
367 </div> 337 </div>
368 {{> cart-together-tpl }} 338 {{> cart-together-tpl }}
369 {{/unless}} 339 {{/unless}}
@@ -380,8 +350,6 @@ @@ -380,8 +350,6 @@
380 350
381 351
382 <script type="text/javascript"> 352 <script type="text/javascript">
383 -  
384 -  
385 /*<textarea data-role="gifts-cansel" class="hide" data-promotionid="{{promotionId}}">{{{giftGoodsListStr}}}</textarea>*/ 353 /*<textarea data-role="gifts-cansel" class="hide" data-promotionid="{{promotionId}}">{{{giftGoodsListStr}}}</textarea>*/
386 </script> 354 </script>
387 355
@@ -8,9 +8,11 @@ @@ -8,9 +8,11 @@
8 <a class="name" href="{{href}}" target="_blank">{{title}}</a> 8 <a class="name" href="{{href}}" target="_blank">{{title}}</a>
9 <p class="price"> 9 <p class="price">
10 <span class="sale-price">{{price}}</span> 10 <span class="sale-price">{{price}}</span>
11 - <span class="market-price">{{marketPrice}}</span> 11 + {{#if marketPrice}}<span class="market-price">{{marketPrice}}</span>{{/if}}
12 </p> 12 </p>
13 - <a class="btn-add-cart">加入购物车</a> 13 + {{#if ../showAdd2Cart}}
  14 + <a class="btn-add-cart" data-role="add2cart">加入购物车</a>
  15 + {{/if}}
14 </li> 16 </li>
15 {{/each}} 17 {{/each}}
16 </ul> 18 </ul>
@@ -298,7 +298,9 @@ function getFineProduct(page) { @@ -298,7 +298,9 @@ function getFineProduct(page) {
298 type: 'GET', 298 type: 'GET',
299 dataType: 'json', 299 dataType: 'json',
300 url: '/cart/data/recommendProduct', 300 url: '/cart/data/recommendProduct',
301 - data: page 301 + data: {
  302 + page: page
  303 + }
302 }).then(function(d) { 304 }).then(function(d) {
303 305
304 // 为您优选埋点 306 // 为您优选埋点
@@ -2,127 +2,111 @@ @@ -2,127 +2,111 @@
2 * Created by yoho on 2017-01-13. 2 * Created by yoho on 2017-01-13.
3 */ 3 */
4 4
  5 +var lazyLoad = require('yoho-jquery-lazyload');
  6 +var dataLazyLoad = require('../plugins/lazy-load')(document);
  7 +
5 var capi = require('./cart-api'); 8 var capi = require('./cart-api');
6 var togetherTpl = require('hbs/cart/cart-together-item.hbs'); 9 var togetherTpl = require('hbs/cart/cart-together-item.hbs');
7 var $togetherSlide = $('[data-role=together-slide]'); 10 var $togetherSlide = $('[data-role=together-slide]');
8 var $fineSlide = $('[data-role=fine-slide]'); 11 var $fineSlide = $('[data-role=fine-slide]');
  12 +var $latestWalkSlide = $('[data-role=latestWalk-slide]');
9 13
10 -// 推荐、优选、浏览切换  
11 -$(function() {  
12 - var $togetherGoods = $('.individual-item-togetherGoods'),  
13 - $recommendGoods = $('.individual-item-recommendGoods'),  
14 - $latestWalk = $('.individual-item-latestWalk'); 14 +function loadTogetherProduct(page) {
  15 + capi.getTogetherProduct(page).done(function(togetherInfo) {
15 16
16 - if ($togetherGoods.hasClass('none')) {  
17 - $recommendGoods.show(); 17 + if (togetherInfo && togetherInfo.code === 200) {
  18 + $togetherSlide.html(togetherTpl(togetherInfo.data));
18 } 19 }
  20 + });/* .fail(function() {
19 21
20 - $('.bottom-tab-slide').on('click', '.bottom-title', function() {  
21 - var $this = $(this),  
22 - index = $this.index();  
23 - console.log(index);  
24 - $togetherGoods.hide();  
25 - $recommendGoods.hide(); 22 + });*/
  23 +}
26 24
27 - if ($this.hasClass('change')) {  
28 - return;  
29 - }  
30 - if ($this.hasClass('cur')) {  
31 - return;  
32 - } 25 +function loadFineProduct(page) {
  26 + capi.getFineProduct(page).done(function(fineInfo) {
  27 + if (fineInfo && fineInfo.code === 200) {
  28 + $fineSlide.html(togetherTpl($.extend({
  29 + showAdd2Cart: true
  30 + }, fineInfo.data)));
33 31
34 - $this.addClass('cur');  
35 - $this.siblings('.cur').removeClass('cur');  
36 -  
37 - switch (index) {  
38 - case 0: {  
39 - $togetherGoods.slideDown();  
40 - $recommendGoods.hide();  
41 - $latestWalk.hide();  
42 - break;  
43 - }  
44 - case 1: {  
45 - $togetherGoods.hide();  
46 - $recommendGoods.slideDown();  
47 - $latestWalk.hide();  
48 - break;  
49 - }  
50 - case 2: {  
51 - $togetherGoods.hide();  
52 - $recommendGoods.hide();  
53 - $latestWalk.slideDown();  
54 - break; 32 + lazyLoad($fineSlide.find('.lazy'));
55 } 33 }
56 - }  
57 - });  
58 -}); 34 + });/* .fail(function() {
  35 +
  36 + });*/
  37 +}
59 38
  39 +function fetchLatestWalk(num) {
60 40
61 -// 凑单 底部 轮播  
62 -function loadSlideGoods() {  
63 $.ajax({ 41 $.ajax({
64 - type: 'GET',  
65 - url: '', 42 + url: 'http://www.yohobuy.com/common/recentReview',
  43 + dataType: 'jsonp',
66 data: { 44 data: {
67 - // skn: skn,  
68 - size: 20,  
69 - num: 1 45 + limit: num || 15
  46 + },
  47 + success: function(data) {
  48 + var latestWalk = [],
  49 + res, i, cur;
  50 +
  51 + if (data.code === 200) {
  52 + res = data.data;
  53 +
  54 + // 若无最近浏览,请隐藏容器
  55 + if (res.length === 0) {
  56 + $latestWalkSlide.hide();
  57 + $('[data-role=latestWalk-tab]').hide();
  58 + return;
70 } 59 }
71 - }).then(function(data) {  
72 - // var pro = data.data.products;  
73 60
74 - // if (data.code === 200) {  
75 - // if (pro.length === 0) {  
76 - // return;  
77 - // } 61 + for (i = 0; i < res.length; i++) {
  62 + cur = res[i];
  63 +
  64 + latestWalk.push({
  65 + href: cur.url,
  66 + img: cur.pic_url,
  67 + title: cur.product_name,
  68 + price: cur.price,
  69 + marketPrice: cur.market_price
  70 + });
  71 + }
78 72
79 - $('#recommend-shop').removeClass('none'); 73 + $latestWalkSlide.html(togetherTpl({
  74 + item: latestWalk,
  75 + hasNext: latestWalk && latestWalk.length > 5,
  76 + hasPrev: latestWalk && latestWalk.length > 5
  77 + }));
  78 + lazyLoad($latestWalkSlide.find('.lazy'));
80 79
81 - $('.individual-item ').slider2({ 80 + $latestWalkSlide.find('.individual-item').slider2({
82 shownum: 5, 81 shownum: 5,
83 isCircle: true 82 isCircle: true
84 }); 83 });
85 -  
86 - // } else {  
87 - // $('.bottom-title').filter('.change').addClass('none');  
88 - // } 84 + }
  85 + }
89 }); 86 });
90 } 87 }
91 -loadSlideGoods();  
92 88
93 -function loadTogetherProduct(page) {  
94 - capi.getTogetherProduct(page).done(function(togetherInfo) { 89 +// 凑单商品翻页
  90 +$togetherSlide.on('click', '.pagenext, .pageprev', function() {
  91 + loadTogetherProduct(Math.ceil(Math.random() * 100) + 1);
  92 +});
95 93
96 - if (togetherInfo && togetherInfo.code === 200) {  
97 - $togetherSlide.html(togetherTpl(togetherInfo.data));  
98 - }  
99 - });/* .fail(function() { 94 +$('.bottom-tab-slide .change').on('click', function(){
100 95
101 - });*/  
102 -} 96 + var pageNum = Number($fineSlide.data('pagenum') || 1);
103 97
104 -function loadFineProduct(page) {  
105 - capi.getFineProduct(page).done(function(fineInfo) {  
106 - if (fineInfo && fineInfo.code === 200) {  
107 - $fineSlide.html(togetherTpl(fineInfo.data)); 98 + if (pageNum !== 3) {
  99 + pageNum++;
  100 + } else {
  101 + pageNum = 1;
108 } 102 }
109 - });/* .fail(function() {  
110 -  
111 - });*/  
112 -}  
113 -  
114 -setTimeout(function() {  
115 - loadTogetherProduct(1);  
116 - loadFineProduct(1);  
117 -}, 0);  
118 103
119 -// 凑单商品翻页  
120 -$togetherSlide.on('click', '.pagenext, .pageprev', function() {  
121 - loadTogetherProduct(Math.ceil(Math.random() * 100) + 1); 104 + $fineSlide.data('pagenum', pageNum);
  105 + loadFineProduct(pageNum);
122 }); 106 });
123 107
124 // 为您优选翻页 108 // 为您优选翻页
125 -$fineSlide.on('click', '.pagenext, .pageprev', function() { 109 +/*$fineSlide.on('click', '.pagenext, .pageprev', function() {
126 110
127 var pageNum = Number($fineSlide.data('pagenum') || 1); 111 var pageNum = Number($fineSlide.data('pagenum') || 1);
128 112
@@ -138,4 +122,41 @@ $fineSlide.on('click', '.pagenext, .pageprev', function() { @@ -138,4 +122,41 @@ $fineSlide.on('click', '.pagenext, .pageprev', function() {
138 122
139 $fineSlide.data('pagenum', pageNum); 123 $fineSlide.data('pagenum', pageNum);
140 loadFineProduct(pageNum); 124 loadFineProduct(pageNum);
  125 +});*/
  126 +
  127 +// 推荐、优选、浏览切换
  128 +$('.bottom-tab-slide').on('click', '.bottom-title', function() {
  129 + var $this = $(this),
  130 + $triggers = $('.bottom-tab-slide .bottom-title'),
  131 + index = $this.index(),
  132 + $panels = $('.bottom-slide-content .slide-panel'),
  133 + $curPanel = $panels.eq(index),
  134 + $chgBtn = $('.bottom-tab-slide .change');
  135 +
  136 + $panels.hide();
  137 + $panels.eq(index).show();
  138 +
  139 + if ($this.hasClass('cur')) {
  140 + return;
  141 + }
  142 +
  143 + $triggers.removeClass('cur');
  144 + $this.addClass('cur');
  145 +
  146 + if($this.data('type') === 'fine') {
  147 + $chgBtn.show();
  148 + } else {
  149 + $chgBtn.hide();
  150 + }
  151 +
  152 + $panels.hide();
  153 + $curPanel.slideDown();
141 }); 154 });
  155 +
  156 +
  157 +window.loadTogetherProduct = loadTogetherProduct;
  158 +window.loadFineProduct = loadFineProduct;
  159 +window.fetchLatestWalk = fetchLatestWalk;
  160 +
  161 +// 数据懒加载
  162 +dataLazyLoad.init({cls: '.lazy-load-object', threshold: 700});