Authored by xuqi

goods list

... ... @@ -5,4 +5,5 @@
*/
require('./newsale/newarrival');
require('./newsale/discount');
\ No newline at end of file
require('./newsale/discount');
require('./list');
\ No newline at end of file
... ...
/**
* 商品列表页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/20
*/
var $ = require('yoho.zepto'),
lazyLoad = require('yoho.zeptolazyload');
var filter = require('../plugin/filter');
var $goodsContainer = $('#goods-container'),
$ngc = $goodsContainer.children('.new-goods'),
$pgc = $goodsContainer.children('.price-goods'),
$dgc = $goodsContainer.children('.discount-goods');
var winH = $(window).height();
//默认筛选条件
var defaultOpt = {
gender: $('#gender').val(),
brand: $('#brand').val(),
msort: $('#msort').val(),
color: $('#color').val(),
size: $('#size').val(),
price: $('#price').val(),
discount: $('#discount').val()
};
var $listNav = $('#list-nav'),
//导航数据信息
navInfo = {
newest: {
order: 1,
reload: true,
page: 0,
end: false
},
price: {
order: 0,
reload: true,
page: 0,
end: false
},
discount: {
order: 0,
reload: true,
page: 0,
end: false
}
},
$pre, //纪录进入筛选前的active项
searching;
/**
* 筛选注册的回调,筛选子项点击后逻辑
* 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
* @param opt {type, id}
*/
function search(opt) {
var setting = {},
ext,
att,
nav, navType,
page;
if (opt) {
//筛选项变更则重置reload为true
for (att in navInfo) {
if (navInfo.hasOwnProperty(att)) {
navInfo[att].reload = true;
}
}
switch (opt.type) {
case 'gender':
ext = {
gender: opt.id
};
break;
case 'brand':
ext = {
brand: opt.id
};
break;
case 'msort':
ext = {
msort: 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;
}
$.extend(defaultOpt, ext); //扩展筛选项
}
if (searching) {
return;
}
//导航类别
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;
$.ajax({
type: 'GET',
url: '/product/list/search',
data: setting,
success: function(data) {
var noResult = '<p class="no-result">未找到相关搜索结果</p>',
$container;
switch (navType) {
case 'newest':
$container = $ngc;
break;
case 'price':
$container = $pgc;
break;
case 'discount':
$container = $dgc;
break;
}
if (data.data === ' ') {
nav.end = true;
if (nav.reload) {
$container.html(noResult);
}
} else {
if (nav.reload) {
$container.html(data.data);
} else {
$container.append(data.data);
}
lazyLoad($container.find('.lazy'));
}
nav.reload = true;
nav.page = page;
searching = false;
}
});
}
lazyLoad($('.lazy'));
filter.registerCbFn(search);
//导航栏点击逻辑说明:
//1.点击非active项时切换active状态
//2.价格和折扣active状态时继续点击切换排序
//3.筛选无active时点击展开筛选面板
//4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态
//5.当前active为筛选并且点击其他项时,隐藏筛选面板
$listNav.delegate('li', 'touchstart', function() {
var $this = $(this),
navType,
$active;
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')) {
//最新无排序切换
if ($this.hasClass('new')) {
return;
}
if ($this.hasClass('price') || $this.hasClass('discount')) {
// 价格/折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
}
} else {
$active = $this.siblings('.active');
if ($active.hasClass('filter')) {
$pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
//若之前active项为筛选,则隐藏筛选面板
filter.hideFilter();
} else {
$pre = $active;
}
$active.removeClass('active');
$this.addClass('active');
$pre = $active;
}
if ($this.hasClass('new')) {
navType = 'newest';
} else if ($this.hasClass('price')) {
navType = 'price';
} else if ($this.hasClass('discount')) {
navType = 'discount';
}
if (navInfo[navType].reload) {
search();
}
}
});
$(window).scroll(function() {
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
$(document).height() - 0.25 * $goodsContainer.height()) {
search();
}
});
\ No newline at end of file
... ...
@import "new-arrival", "discount";
\ No newline at end of file
@import "new-arrival", "discount", "list";
\ No newline at end of file
... ...
.good-list-page {
.search-input {
position: relative;
padding: 7px 46px 7px 15px;
background: #f8f8f8;
.search-icon {
position: absolute;
font-size: 12px;
top: 16px;
left: 24px;
}
input {
height: 30px;
width: 100%;
border-radius: 15px;
text-indent: 26px;
background: #fff;
border: none;
}
.clear-input {
position: absolute;
top: 12px;
right: 50px;
}
.search {
position: absolute;
top: 12px;
right: 0;
border: none;
background: transparent;
font-size: 16px;
}
}
.brand-way {
padding-bottom: 10px;
background: #f4f4f4;
> a {
display: block;
height: 40px;
line-height: 40px;
padding: 0 10px;
border-bottom: 1px solid #e6e6e6;
border-top: 1px solid #e6e6e6;
font-size: 17px;
background: #fff;
}
.brand-thumb {
display: block;
float: left;
width: 75px;
height: 40px;
margin: 0;
}
.entry {
color: #999;
font-size: 14px;
float: right;
}
}
.brand-header {
position: relative;
height: 150rem / $pxConvertRem;
> img {
display: block;
height: 100%;
}
}
.btn-intro, .btn-col {
position: absolute;
display: block;
width: 62px;
height: 24px;
line-height: 24px;
text-align: center;
border: 1px solid #fff;
color: #fff;
top: 50%;
margin-top: -12px;
}
.btn-intro {
right: 90px;
}
.btn-col {
right: 15px;
}
.brand-intro-box {
display: none;
}
.list-nav {
> li {
float: left;
width: 25%;
height: 33px;
line-height: 33px;
text-align: center;
font-size: 14px;
}
a {
display: block;
box-sizing: border-box;
width: 100%;
height: 100%;
color: #999;
}
.active > a {
border-bottom: 2px solid #000;
color: #000;
.iconfont {
color: #999;
&.cur {
color: #000;
}
}
}
.new .iconfont {
@include scale(0.8);
font-weight: bold;
}
.filter .iconfont {
font-size: 12px;
@include transition(transform 0.1 ease-in);
}
.filter.active .iconfont {
@include rotate(-180deg);
}
.icon {
position: relative;
i {
position: absolute;
@include scale(0.8);
font-weight: bold;
}
.up {
top: -11px;
}
.down {
top: -4px;
}
}
}
.no-result {
text-align: center;
vertical-align: middle;
color: #ccc;
font-size: 1.2em;
margin-top: 220px;
}
.goods-container {
position: relative;
min-height: 440px;
}
}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="good-list-page yoho-page">
{{# goodList}}
{{# if search}}
<div id="search-input" class="search-input">
<i class="search-icon iconfont">&#xe60f;</i>
<input type="text" value={{search}}>
<i class="clear-input iconfont hide">&#xe61a;</i>
<button id="search" class="search">搜索</button>
</div>
{{/if}}
{{# brandWay}}
<div class="brand-way">
<a href={{url}}>
<img class="brand-thumb" src={{thumb}}>
<span>{{name}}</span>
<span class="entry">
进入品牌
<i class="iconfont">&#xe614;</i>
</span>
</a>
</div>
{{/ brandWay}}
{{# brand}}
<div class="brand-header" data-id={{id}}>
<img class="lazy" data-original={{banner}}>
<a class="btn-intro" href="javascript:void(0);">
品牌介绍
</a>
<a class="btn-col" href="javascript:void(0);">
<span class="iconfont">&#xe622;</span>
收藏
</a>
</div>
<div class="brand-intro-box">
<div id="brand-intro" class="brand-intro">{{intro}}</div>
</div>
{{/ brand}}
<ul id="list-nav" class="list-nav clearfix">
<li class="new active">
<a href="javascript:void(0);">
最新
<span class="iconfont cur">&#xe616;</span>
</a>
</li>
<li class="price">
<a href="javascript:void(0);">
价格
<span class="icon">
<i class="iconfont up">&#xe615;</i>
<i class="iconfont down cur">&#xe616;</i>
</span>
</a>
</li>
<li class="discount">
<a href="javascript:void(0);">
折扣
<span class="icon">
<i class="iconfont up">&#xe615;</i>
<i class="iconfont down cur">&#xe616;</i>
</span>
</a>
</li>
<li class="filter">
<a href="javascript:void(0);">
筛选
<span class="iconfont">&#xe613;</span>
</a>
</li>
</ul>
<div id="goods-container" class="goods-container">
<div class="new-goods">
{{# new}}
{{> good}}
{{/ new}}
</div>
<div class="price-goods hide"></div>
<div class="discount-goods hide"></div>
{{> filter}}
</div>
{{/ goodList}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -117,6 +117,13 @@
</script>
{{/if}}
{{!-- 商品列表 --}}
{{#if goodListPage}}
<script>
seajs.use('js/product/list');
</script>
{{/if}}
{{!-- 品类 --}}
{{#if categoryPage}}
<script>
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
use Action\AbstractAction;
/**
* 商品列表页
*/
class ListController extends AbstractAction
{
public function indexAction()
{
$data = array(
'goodListPage' => true,
'goodList' => array(
'search' => 'Aape',
'brandWay' => array(
'url' => 'http://aape.m.yohobuy.com/',
'name' => 'Aape',
'thumb' => 'http://img13.static.yhbimg.com/brandLogo/2015/08/26/15/02261f64c198cb4b181c5ef9e61f38f4b9.jpg?imageMogr2/thumbnail/150x70/extent/150x70/background/d2hpdGU=/position/center/quality/90'
),
'new' => array(
array(
'id' => 1,
'thumb' => 'http://img13.static.yhbimg.com/goodsimg/2015/09/15/03/02e50b1037b45b90aa8f33ee328b18facf.jpg?imageMogr2/thumbnail/290x388/extent/290x388/background/d2hpdGU=/position/center/quality/90',
'url' => '',
'name' => 'Aape X YO’HOOD moon face YOH',
'salePrice' => 599,
'tags' => array(
'is_new' => true,
'is_discount' => true
),
'is_soon_sold_out' => true
),
array(
'id' => 2,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/09/15/03/0101b0c3998752d02724a5512c6efcb241.jpg?imageMogr2/thumbnail/290x388/extent/290x388/background/d2hpdGU=/position/center/quality/90',
'url' => '',
'name' => 'Aape X YO’HOOD moon face YOH',
'salePrice' => 99,
'tags' => array(
'is_yohoood' => true
),
'is_soon_sold_out' => true
)
),
'filter' => array(
array(
'classify' => array(
array(
'title' => '性别',
'name' => '全部性别',
'default' => true,
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '全部性别'
),
array(
'dataId' => 1,
'name' => '男'
),
array(
'dataId' => 3,
'name' => '女'
)
)
),
array(
'title' => '尺寸',
'name' => 'XL',
'subs' => array(
array(
'dataId' => 0,
'name' => '全部尺寸'
),
array(
'dataId' => 1,
'name' => 'S'
),
array(
'dataId' => 2,
'name' => 'M'
),
array(
'dataId' => 3,
'name' => 'L'
),
array(
'chosed' => true,
'dataId' => 4,
'name' => 'XL'
),
array(
'dataId' => 5,
'name' => 'XXL'
)
)
)
)
)
)
)
);
$this->_view->display('index', $data);
}
}
\ No newline at end of file
... ...