Authored by 王水玲

sale

... ... @@ -58,8 +58,9 @@ const processBreakingSort = (list) => {
list = list || [];
list = camelCase(list);
_.forEach(list, (data) => {
_.forEach(list, (data, index) => {
sortName.push(data.sortName);
data.sub.key = index;
sub.push(data.sub);
});
... ... @@ -72,9 +73,7 @@ const processBreakingSort = (list) => {
/**
* 商品搜索数据处理
*/
const processSearch = (data) => {
return camelCase(data);
const processSearch = () => {
// const goods = [];
// list = list || [];
... ... @@ -114,6 +113,22 @@ const processSearch = (data) => {
// });
};
/**
* 获取商品数据
*/
exports.getSearchData = (params) => {
return api.get('', sign.apiSign(Object.assign({
method: 'app.search.sales'
}, params))).then((result) => {
if (result && result.code === 200) {
return processSearch(result);
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
};
const getResources = (page) => {
const contentCode = {
sale: '7c2b77093421efa8ae9302c91460db73',
... ... @@ -147,23 +162,6 @@ const getBreakingSort = (yhChannel) => {
};
/**
* 获取商品数据
*/
exports.getSearchData = (params) => {
params = params || {};
return api.get('', sign.apiSign(Object.assign({
method: 'app.search.sales'
}, params))).then((result) => {
if (result && result.code === 200) {
return processSearch(result.data);
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return {};
}
});
};
/**
* 获取sale首页数据
* @param {[object]} params
* @return {[object]}
... ... @@ -202,10 +200,10 @@ exports.getSpecialData = (params) => {
}, params))).then((result) => {
if (result && result.code === 200) {
specialData.data = processSpecial(result.data);
return specialData;
} else {
logger.error('SALE 专题活动列表接口返回 code 不是 200');
return Promise.reject('error');
}
return specialData;
});
};
... ...
... ... @@ -23,54 +23,16 @@
</li>
</ul>
<div class="swiper-container" id="size-swiper">
<ul class="swiper-wrapper">
{{# sub}}
{{log this}}
<li class="swiper-slide" data-id="{{sizeId}}">{{sizeName}}</li>
{{/ sub}}
</ul>
</div>
{{# sub}}
<div class="swiper-container" id="size-swiper-{{key}}" {{#if @first}}style="display:block"{{/if}}>
<ul class="swiper-wrapper">
{{# this}}
<li class="swiper-slide" data-id="{{sizeId}}">{{sizeName}}</li>
{{/ this}}
</ul>
</div>
{{/ sub}}
{{/ nav}}
{{!-- <ul id="list-nav" class="list-nav clearfix">
<li class="new active">
<a href="javascript:void(0);">
<span class="span-test">上装</span>
</a>
</li>
<li class="price">
<a href="javascript:void(0);">
<span class="span-test">夏装</span>
</a>
</li>
<li class="discount">
<a href="javascript:void(0);">
<span class="span-test">鞋</span>
</a>
</li>
<li class="discount">
<a href="javascript:void(0);">
<span class="span-test">其他</span>
</a>
</li>
</ul> --}}
{{!-- <div class="swiper-container" id="size-swiper">
<ul class="swiper-wrapper">
<li class="swiper-slide on">XS码</li>
<li class="swiper-slide">S码</li>
<li class="swiper-slide">M码</li>
<li class="swiper-slide">L码</li>
<li class="swiper-slide">XL码</li>
<li class="swiper-slide">XXL码</li>
<li class="swiper-slide">S码</li>
<li class="swiper-slide">M码</li>
<li class="swiper-slide">L码</li>
<li class="swiper-slide">XL码</li>
<li class="swiper-slide">XXL码</li>
</ul>
</div> --}}
<div id="goods-container" class="goods-container">
<div class="new-goods container clearfix">
... ...
{{#if .}} {{!-- 剔除值为false的项 --}}
{{#productList}} {{!-- 剔除值为false的项 --}}
<div class="good-info" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
<div class="tag-container clearfix">
{{# tags}}
... ... @@ -47,4 +47,4 @@
{{/if}}
</div>
</div>
{{/if}}
\ No newline at end of file
{{/productList}}
\ No newline at end of file
... ...
... ... @@ -12,12 +12,318 @@ var $ = require('yoho-jquery'),
filter = require('../plugin/filter'),
loading = require('../plugin/loading');
var $listNav = $('#list-nav');
var $goodsContainer = $('#goods-container'),
$goodsChildren = $goodsContainer.children(),
$ngc = $($goodsChildren.get(0)),
$pgc = $($goodsChildren.get(1)),
$dgc = $($goodsChildren.get(2));
new Swiper('.swiper-container', {
slidesPerView: 'auto'
var winH = $(window).height(),
noResult = '<p class="no-result">未找到相关搜索结果</p>';
// 默认筛选条件
var defaultOpt = require('./query-param');
var $listNav = $('#list-nav'),
// 导航数据信息
navInfo = {
newest: {
order: 1,
reload: true,
page: 0,
end: false
},
price: {
order: 1,
reload: true,
page: 0,
end: false
},
discount: {
order: 1,
reload: true,
page: 0,
end: false
}
},
$pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
searching;
var swipers = [];
require('./suspend-cart'); // 悬浮购物车
require('../common');
ellipsis.init();
lazyLoad($('img.lazy'));
$.each($('.swiper-container'), function(key) {
swipers[key] = new Swiper('#size-swiper-' + key, {
slidesPerView: 'auto'
});
});
/**
* 筛选注册的回调,筛选子项点击后逻辑
* 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
* @param opt {type, id}
*/
function search(opt) {
var setting = {},
ext,
att,
nav, navType,
page;
if (searching) {
return;
}
if (opt) {
// 筛选项变更则重置reload为true
for (att in navInfo) {
if (navInfo.hasOwnProperty(att)) {
navInfo[att].reload = true;
}
}
// 处理active状态
$listNav.children('.active').removeClass('active');
$pre.addClass('active');
switch (opt.type) {
case 'gender':
ext = {
gender: opt.id
};
break;
case 'brand':
ext = {
brand: opt.id
};
break;
case 'sort':
ext = {
sort: opt.id
};
break;
case 'color':
ext = {
color: opt.id
};
break;
case 'size':
ext = {
size: opt.id
};
break;
case 'price':
ext = {
price: opt.id
};
break;
case 'discount':
ext = {
discount: opt.id
};
break;
default:
break;
}
$.extend(defaultOpt, ext); // 扩展筛选项
}
// 导航类别
if ($pre.hasClass('new')) {
navType = 'newest';
} else if ($pre.hasClass('price')) {
navType = 'price';
} else if ($pre.hasClass('discount')) {
navType = 'discount';
}
nav = navInfo[navType];
page = nav.page + 1;
if (nav.reload) {
page = 1;
} else if (nav.end) {
// 不需要重新加载并且数据请求结束
return;
}
$.extend(setting, defaultOpt, {
type: navType,
order: nav.order,
page: page
});
searching = true;
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/product/sale/search',
data: setting,
success: function(data) {
var $container,
num;
console.log(data);
switch (navType) {
case 'newest':
$container = $ngc;
break;
case 'price':
$container = $pgc;
break;
case 'discount':
$container = $dgc;
break;
default:
break;
}
if (data === ' ') {
nav.end = true;
if (nav.reload) {
$container.html(noResult);
}
} else {
if (nav.reload) {
$container.html(data);
lazyLoad($container.find('.lazy'));
} else {
num = $container.find('.good-info').length;
$container.append(data);
// lazy good-infos who append in
lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));
}
}
nav.reload = false;
nav.page = page;
searching = false;
loading.hideLoadingMask();
window.rePosFooter();
$('.good-detail-text .name').each(function() {
var $this = $(this),
$title = $this.find('a');
$title[0].mlellipsis(2);
});
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
loading.hideLoadingMask();
}
});
}
$.ajax({
type: 'GET',
url: '/product/newsale/filter',
data: defaultOpt,
success: function(data) {
$goodsContainer.append(data);
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: search,
hCbFn: function() {
// 切换active状态到$pre上
$pre.addClass('active');
$pre.siblings('.filter').removeClass('active');
},
missStatus: true
});
}
});
lazyLoad($('.lazy'));
$listNav.bind('contextmenu', function() {
return false;
});
$listNav.on('touchend touchcancel', function(e) {
var $this = $(e.target).closest('li'),
nav;
e.preventDefault();
if (typeof $this === 'undefined' || $this.length === 0) {
return;
}
if ($this.hasClass('filter')) {
// 筛选面板切换状态
if ($this.hasClass('active')) {
filter.hideFilter();
// 点击筛选钱的active项回复active
$pre.addClass('active');
$this.removeClass('active');
} else {
$pre = $this.siblings('.active');
$pre.removeClass('active');
$this.addClass('active');
filter.showFilter();
}
} else {
if ($this.hasClass('active')) {
return;
} else {
$this.siblings().removeClass('active');
$this.addClass('active');
$('.swiper-container').hide();
$('#size-swiper-' + $this.index()).show();
swipers[$this.index()].onResize();
}
if (nav.reload) {
search();
}
}
e.stopPropagation();
});
function scrollHandler() {
// 当scroll到1/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
$(document).height() - 0.25 * $goodsContainer.height() - 50) {
if (typeof($pre) !== 'undefined') {
search();
}
}
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// 初始请求最新第一页数据
search();
$listNav.on('touchstart', 'li', function() {
$(this).addClass('bytouch');
}).on('touchend touchcancel', function() {
... ...
... ... @@ -11,7 +11,10 @@
}
}
#size-swiper {
#size-swiper-0,
#size-swiper-1,
#size-swiper-2,
#size-swiper-3 {
width: 100%;
line-height: 50px;
color: #999;
... ... @@ -21,6 +24,7 @@
background: #f0f0f0;
padding: 0 22px;
box-sizing: border-box;
display: none;
ul {
width: 100%;
... ... @@ -53,4 +57,4 @@
display: block;
}
}
}
\ No newline at end of file
}
... ...