Authored by yyq

Merge branch 'feature/shoppingCart' of git.yoho.cn:fe/yohobuy-node into feature/shoppingCart

... ... @@ -375,7 +375,7 @@ const getRecommendProductAction = (req, res) => {
'data': {
'header': '\u4e3a\u60a8\u4f18\u9009',
'hasPrev': false,
'hasNext': true,
'hasNext': false,
'item': [{
'id': 493102,
'skn': 51295054,
... ...
... ... @@ -831,8 +831,8 @@ const getRecommendProduct = (channel, uid, udid, page) => {
});
Object.assign(result.data, {
hasPrev: page > 1,
hasNext: plist.length >= end,
// hasPrev: page > 1,
// hasNext: plist.length >= end,
item: items
});
... ...
... ... @@ -329,59 +329,29 @@
</div>
{{#unless @root.pc.product.removeRecentView}}
<div class="lazy-load-object">
<textarea class="datalazyload" style="visibility: hidden;">
<script>
fetchRecommend();
</script>
</textarea>
<div>
<textarea class="lazy-load-object" style="visibility: hidden;">
<script>
loadFineProduct();
fetchLatestWalk();
</script>
</textarea>
</div>
<div class="bottom-tab bottom-tab-slide">
<span class="bottom-title {{#if cart.deleteShop}}cur{{/if}} {{#unless cart.deleteShop}}none{{/unless}}">凑单商品</span>
<span class="bottom-title {{#unless cart.deleteShop}}cur{{/unless}}">为您优选</span>
<span class="bottom-title">最近浏览</span>
{{!--<span class="bottom-title {{#if cart.deleteShop}}cur{{/if}}
{{#unless cart.deleteShop}}none{{/unless}}">凑单商品</span>--}}
<span class="bottom-title cur" data-type="fine">为您优选</span>
<span class="bottom-title" data-role="latestWalk-tab">最近浏览</span>
<span class="change">换一批
<span class="iconfont change-icon">&#xe639;</span>
</span>
<span class="iconfont change-icon">&#xe639;</span>
</span>
</div>
<div class="individual-slide">
<div data-role="together-slide"></div>
<div data-role="fine-slide"></div>
<div data-role="latestWalk-slide"></div>
<!--<div class="individual-item individual-item-togetherGoods {{#unless cart.deleteShop}}none{{/unless}}">
<input id="" type="hidden" value="">
<ul id="" class="goods clearfix img-list">
{{>individual-slide}}
</ul>
<div class="img-brand-switch">
<a class="prev iconfont" href="javascript:;"></a>
<a class="next iconfont" href="javascript:;"></a>
</div>
</div>
<div class="individual-item individual-item-recommendGoods {{#if cart.deleteShop}}none{{/if}}">
<input id="" type="hidden" value="{{latestWalk}}">
<ul id="" class="goods img-list clearfix">
{{>individual-slide}}
</ul>
<div class="img-brand-switch">
<a class="prev iconfont " href="javascript:;"></a>
<a class="next iconfont" href="javascript:;"></a>
</div>
</div>
<div class="individual-item individual-item-latestWalk">
<input id="latest-walk-count" type="hidden" value="">
<ul id="latest-walk-goods" class="goods clearfix img-list">
{{>individual-slide}}
</ul>
<div class="img-brand-switch">
<a class="prev iconfont" href="javascript:;"></a>
<a class="next iconfont" href="javascript:;"></a>
</div>
</div>-->
<div class="individual-slide bottom-slide-content">
<!--<div data-role="together-slide" class="slide-panel"></div>-->
<div data-role="fine-slide" class="slide-panel"></div>
<div data-role="latestWalk-slide" class="slide-panel" style="display:none;"></div>
</div>
{{> cart-together-tpl }}
{{/unless}}
... ... @@ -401,8 +371,6 @@
<script type="text/javascript">
/*<textarea data-role="gifts-cansel" class="hide" data-promotionid="{{promotionId}}">{{{giftGoodsListStr}}}</textarea>*/
</script>
... ...
... ... @@ -8,9 +8,11 @@
<a class="name" href="{{href}}" target="_blank">{{title}}</a>
<p class="price">
<span class="sale-price">{{price}}</span>
<span class="market-price">{{marketPrice}}</span>
{{#if marketPrice}}<span class="market-price">{{marketPrice}}</span>{{/if}}
</p>
<a class="btn-add-cart">加入购物车</a>
{{#if ../showAdd2Cart}}
<a class="btn-add-cart" data-role="add2cart">加入购物车</a>
{{/if}}
</li>
{{/each}}
</ul>
... ...
... ... @@ -298,7 +298,9 @@ function getFineProduct(page) {
type: 'GET',
dataType: 'json',
url: '/cart/data/recommendProduct',
data: page
data: {
page: page
}
}).then(function(d) {
// 为您优选埋点
... ...
... ... @@ -2,93 +2,14 @@
* Created by yoho on 2017-01-13.
*/
var lazyLoad = require('yoho-jquery-lazyload');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var capi = require('./cart-api');
var togetherTpl = require('hbs/cart/cart-together-item.hbs');
var $togetherSlide = $('[data-role=together-slide]');
var $fineSlide = $('[data-role=fine-slide]');
// 推荐、优选、浏览切换
$(function() {
var $togetherGoods = $('.individual-item-togetherGoods'),
$recommendGoods = $('.individual-item-recommendGoods'),
$latestWalk = $('.individual-item-latestWalk');
if ($togetherGoods.hasClass('none')) {
$recommendGoods.show();
}
$('.bottom-tab-slide').on('click', '.bottom-title', function() {
var $this = $(this),
index = $this.index();
console.log(index);
$togetherGoods.hide();
$recommendGoods.hide();
if ($this.hasClass('change')) {
return;
}
if ($this.hasClass('cur')) {
return;
}
$this.addClass('cur');
$this.siblings('.cur').removeClass('cur');
switch (index) {
case 0: {
$togetherGoods.slideDown();
$recommendGoods.hide();
$latestWalk.hide();
break;
}
case 1: {
$togetherGoods.hide();
$recommendGoods.slideDown();
$latestWalk.hide();
break;
}
case 2: {
$togetherGoods.hide();
$recommendGoods.hide();
$latestWalk.slideDown();
break;
}
}
});
});
// 凑单 底部 轮播
function loadSlideGoods() {
$.ajax({
type: 'GET',
url: '',
data: {
// skn: skn,
size: 20,
num: 1
}
}).then(function(data) {
// var pro = data.data.products;
// if (data.code === 200) {
// if (pro.length === 0) {
// return;
// }
$('#recommend-shop').removeClass('none');
$('.individual-item ').slider2({
shownum: 5,
isCircle: true
});
// } else {
// $('.bottom-title').filter('.change').addClass('none');
// }
});
}
loadSlideGoods();
var $latestWalkSlide = $('[data-role=latestWalk-slide]');
function loadTogetherProduct(page) {
capi.getTogetherProduct(page).done(function(togetherInfo) {
... ... @@ -104,25 +25,88 @@ function loadTogetherProduct(page) {
function loadFineProduct(page) {
capi.getFineProduct(page).done(function(fineInfo) {
if (fineInfo && fineInfo.code === 200) {
$fineSlide.html(togetherTpl(fineInfo.data));
$fineSlide.html(togetherTpl($.extend({
showAdd2Cart: true
}, fineInfo.data)));
lazyLoad($fineSlide.find('.lazy'));
}
});/* .fail(function() {
});*/
}
setTimeout(function() {
loadTogetherProduct(1);
loadFineProduct(1);
}, 0);
function fetchLatestWalk(num) {
$.ajax({
url: 'http://www.yohobuy.com/common/recentReview',
dataType: 'jsonp',
data: {
limit: num || 15
},
success: function(data) {
var latestWalk = [],
res, i, cur;
if (data.code === 200) {
res = data.data;
// 若无最近浏览,请隐藏容器
if (res.length === 0) {
$latestWalkSlide.hide();
$('[data-role=latestWalk-tab]').hide();
return;
}
for (i = 0; i < res.length; i++) {
cur = res[i];
latestWalk.push({
href: cur.url,
img: cur.pic_url,
title: cur.product_name,
price: cur.price,
marketPrice: cur.market_price
});
}
$latestWalkSlide.html(togetherTpl({
item: latestWalk,
hasNext: latestWalk && latestWalk.length > 5,
hasPrev: latestWalk && latestWalk.length > 5
}));
lazyLoad($latestWalkSlide.find('.lazy'));
$latestWalkSlide.find('.individual-item').slider2({
shownum: 5,
isCircle: true
});
}
}
});
}
// 凑单商品翻页
$togetherSlide.on('click', '.pagenext, .pageprev', function() {
loadTogetherProduct(Math.ceil(Math.random() * 100) + 1);
});
$('.bottom-tab-slide .change').on('click', function(){
var pageNum = Number($fineSlide.data('pagenum') || 1);
if (pageNum !== 3) {
pageNum++;
} else {
pageNum = 1;
}
$fineSlide.data('pagenum', pageNum);
loadFineProduct(pageNum);
});
// 为您优选翻页
$fineSlide.on('click', '.pagenext, .pageprev', function() {
/*$fineSlide.on('click', '.pagenext, .pageprev', function() {
var pageNum = Number($fineSlide.data('pagenum') || 1);
... ... @@ -138,4 +122,41 @@ $fineSlide.on('click', '.pagenext, .pageprev', function() {
$fineSlide.data('pagenum', pageNum);
loadFineProduct(pageNum);
});*/
// 推荐、优选、浏览切换
$('.bottom-tab-slide').on('click', '.bottom-title', function() {
var $this = $(this),
$triggers = $('.bottom-tab-slide .bottom-title'),
index = $this.index(),
$panels = $('.bottom-slide-content .slide-panel'),
$curPanel = $panels.eq(index),
$chgBtn = $('.bottom-tab-slide .change');
$panels.hide();
$panels.eq(index).show();
if ($this.hasClass('cur')) {
return;
}
$triggers.removeClass('cur');
$this.addClass('cur');
if($this.data('type') === 'fine') {
$chgBtn.show();
} else {
$chgBtn.hide();
}
$panels.hide();
$curPanel.slideDown();
});
window.loadTogetherProduct = loadTogetherProduct;
window.loadFineProduct = loadFineProduct;
window.fetchLatestWalk = fetchLatestWalk;
// 数据懒加载
dataLazyLoad.init({cls: '.lazy-load-object', threshold: 700});
... ...