Authored by 梁志锋

update

/**
* 折扣专区
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/23
* 商品列表页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/20
*/
var $ = require('yoho.zepto'),
Swiper = require('yoho.iswiper'),
lazyLoad = require('yoho.zeptolazyload');
var swiper;
var filter = require('../../plugin/filter');
var $goodsContainer = $('#goods-container'),
$ngc = $($goodsContainer.children().get(0)),
$pgc = $($goodsContainer.children().get(1)),
$dgc = $($goodsContainer.children().get(2)),
$all = $($goodsContainer.children().get(3));
$ngc = $goodsContainer.children('.new-goods'),
$pgc = $goodsContainer.children('.price-goods'),
$dgc = $goodsContainer.children('.discount-goods');
var winH = $(window).height();
... ... @@ -25,35 +27,26 @@ var defaultOpt = {
color: $('#color').val(),
size: $('#size').val(),
price: $('#price').val(),
discount: $('#discount').val(),
limit: $('#limit').val(),
channel: $('#channel').val(),
p_d: $('#p_d').val()
discount: $('#discount').val()
};
var $listNav = $('#list-nav'),
//导航数据信息
navInfo = {
discount13: {
order: 0,
reload: true,
page: 0,
end: false
},
discount46: {
order: 0,
newest: {
order: 1,
reload: true,
page: 0,
end: false
},
discount79: {
price: {
order: 0,
reload: true,
page: 0,
end: false
},
all: {
discount: {
order: 0,
reload: true,
page: 0,
... ... @@ -63,9 +56,10 @@ var $listNav = $('#list-nav'),
$pre, //纪录进入筛选前的active项
searching;
$pgc.addClass('hide');
$dgc.addClass('hide');
$all.addClass('hide');
swiper = new Swiper('.swiper-container', {
lazyLoading: true,
pagination: '.swiper-pagination'
});
/**
* 筛选注册的回调,筛选子项点击后逻辑
... ... @@ -128,21 +122,6 @@ function search(opt) {
discount: opt.id
};
break;
case 'limit':
ext = {
limit: opt.id
};
break;
case 'channel':
ext = {
channel: opt.id
};
break;
case 'p_d':
ext = {
p_d: opt.id
};
break;
}
$.extend(defaultOpt, ext); //扩展筛选项
... ... @@ -153,14 +132,12 @@ function search(opt) {
}
//导航类别
if ($pre === undefined || $pre.hasClass('discount13')) {
navType = 'discount13';
} else if ($pre.hasClass('discount46')) {
navType = 'discount46';
} else if ($pre.hasClass('discount79')) {
navType = 'discount79';
} else if ($pre.hasClass('all')) {
navType = 'all';
if ($pre === undefined || $pre.hasClass('new')) {
navType = 'newest';
} else if ($pre.hasClass('price')) {
navType = 'price';
} else if ($pre.hasClass('discount')) {
navType = 'discount';
}
nav = navInfo[navType];
... ... @@ -175,6 +152,7 @@ function search(opt) {
}
$.extend(setting, defaultOpt, {
type: navType,
order: nav.order,
page: page
});
... ... @@ -190,18 +168,15 @@ function search(opt) {
$container;
switch (navType) {
case 'discount13':
case 'newest':
$container = $ngc;
break;
case 'discount46':
case 'price':
$container = $pgc;
break;
case 'discount79':
case 'discount':
$container = $dgc;
break;
case 'all':
$container = $all;
break;
}
if (data === ' ') {
... ... @@ -264,26 +239,31 @@ $listNav.delegate('li', 'touchstart', function() {
}
} else {
if ($this.hasClass('discount13')) {
navType = 'discount13';
} else if ($this.hasClass('discount46')) {
navType = 'discount46';
} else if ($this.hasClass('discount79')) {
navType = 'discount79';
} else if ($this.hasClass('all')) {
navType = 'all';
if ($this.hasClass('new')) {
navType = 'newest';
} else if ($this.hasClass('price')) {
navType = 'price';
} else if ($this.hasClass('discount')) {
navType = 'discount';
}
nav = navInfo[navType];
if ($this.hasClass('active')) {
// 折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
$pre = $this;
nav.reload = true; //重置reload,HTML会被替换为逆序的HTML
nav.order = nav.order === 0 ? 1 : 0; //切换排序
//最新无排序切换
if ($this.hasClass('new')) {
return;
}
if ($this.hasClass('price') || $this.hasClass('discount')) {
// 价格/折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
$pre = $this; //更新pre为当前项
nav.reload = true; //重置reload,HTML会被替换为逆序的HTML
nav.order = nav.order === 0 ? 1 : 0; //切换排序
}
} else {
$active = $this.siblings('.active');
... ... @@ -299,19 +279,15 @@ $listNav.delegate('li', 'touchstart', function() {
$goodsContainer.children('.container:not(.hide)').addClass('hide');
switch (navType) {
case 'discount13':
case 'newest':
$ngc.removeClass('hide');
break;
case 'discount46':
case 'price':
$pgc.removeClass('hide');
break;
case 'discount79':
$dgc.removeClass('hide');
break;
case 'all':
case 'discount':
$dgc.removeClass('hide');
break;
}
... ... @@ -334,4 +310,5 @@ $(window).scroll(function() {
$(document).height() - 0.25 * $goodsContainer.height()) {
search();
}
});
\ No newline at end of file
});
\ No newline at end of file
... ...
... ... @@ -5,8 +5,11 @@
*/
var $ = require('yoho.zepto'),
Swiper = require('yoho.iswiper'),
lazyLoad = require('yoho.zeptolazyload');
var swiper;
var filter = require('../../plugin/filter');
var $goodsContainer = $('#goods-container'),
... ... @@ -26,7 +29,6 @@ var defaultOpt = {
price: $('#price').val(),
discount: $('#discount').val(),
limit: $('#limit').val(),
dayLimit: $('#dayLimit').val(),
channel: $('#channel').val(),
p_d: $('#p_d').val()
};
... ... @@ -57,6 +59,11 @@ var $listNav = $('#list-nav'),
$pgc.addClass('hide');
$dgc.addClass('hide');
swiper = new Swiper('.swiper-container', {
lazyLoading: true,
pagination: '.swiper-pagination'
});
/**
* 筛选注册的回调,筛选子项点击后逻辑
* 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
... ...
... ... @@ -46,7 +46,7 @@
.list-nav {
> li {
float: left;
width: 20%;
width: 25%;
height: 33px;
line-height: 33px;
text-align: center;
... ...
... ... @@ -4,34 +4,25 @@
{{> product/banner_swipe_and_single}}
{{/ headerBanner}}
<ul id="list-nav" class="list-nav clearfix">
<li class="discount13 active">
<ul id="list-nav" class="list-nav clearfix">
<li class="new active">
<a href="javascript:void(0);">
1-3
最新
<span class="iconfont cur">&#xe616;</span>
</a>
</li>
<li class="discount46">
<li class="price">
<a href="javascript:void(0);">
4-6
价格
<span class="icon">
<i class="iconfont up">&#xe615;</i>
<i class="iconfont down cur">&#xe616;</i>
</span>
</a>
</li>
<li class="discount79">
<li class="discount">
<a href="javascript:void(0);">
7-9
<span class="icon">
<i class="iconfont up">&#xe615;</i>
<i class="iconfont down cur">&#xe616;</i>
</span>
</a>
</li>
<li class="all">
<a href="javascript:void(0);">
All
折扣
<span class="icon">
<i class="iconfont up">&#xe615;</i>
<i class="iconfont down cur">&#xe616;</i>
... ... @@ -90,10 +81,6 @@
<input id="channel" type="hidden" value={{channel}}>
{{/if}}
{{#if dayLimit}}
<input id="dayLimit" type="hidden" value={{dayLimit}}>
{{/if}}
{{#if limit}}
<input id="limit" type="hidden" value={{limit}}>
{{/if}}
... ...