Showing
14 changed files
with
381 additions
and
92 deletions
@@ -33,7 +33,7 @@ const blkNewGoods = (req, res) => { | @@ -33,7 +33,7 @@ const blkNewGoods = (req, res) => { | ||
33 | 33 | ||
34 | // 新品到着 | 34 | // 新品到着 |
35 | const newGoods = (req, res, next) => { | 35 | const newGoods = (req, res, next) => { |
36 | - let channel = req.cookies._Channel; | 36 | + let channel = req.yoho.channel; |
37 | 37 | ||
38 | newModel.getNewFocus(channel).then((result) => { | 38 | newModel.getNewFocus(channel).then((result) => { |
39 | res.render('new/new', { | 39 | res.render('new/new', { |
@@ -61,36 +61,53 @@ const newGoods = (req, res, next) => { | @@ -61,36 +61,53 @@ const newGoods = (req, res, next) => { | ||
61 | }; | 61 | }; |
62 | 62 | ||
63 | const _newGoods = (req, res, next) => { | 63 | const _newGoods = (req, res, next) => { |
64 | - const channel = req.cookies._Channel; | 64 | + const channel = req.yoho.channel; |
65 | + const uid = req.user.uid; | ||
65 | 66 | ||
66 | - res.render('new/index', { | ||
67 | - module: 'product', | ||
68 | - page: 'new-arrival', | ||
69 | - width750: true, | ||
70 | - localCss: true, | ||
71 | - pageHeader: headerModel.setNav({ | ||
72 | - navTitle: '新品到着' | ||
73 | - }), | 67 | + newModel.indexData(uid, channel).then(result => { |
68 | + let shopList = _.get(result, 'shop_list', []); | ||
69 | + let banner = _.get(result, 'ads[0]', {}); | ||
70 | + let handPick = _.get(result, 'ads[1]', {}); | ||
71 | + | ||
72 | + // console.log(handPick) | ||
73 | + | ||
74 | + res.render('new/index', { | ||
75 | + module: 'product', | ||
76 | + page: 'new-arrival', | ||
77 | + width750: true, | ||
78 | + localCss: true, | ||
79 | + pageHeader: headerModel.setNav({ | ||
80 | + navTitle: '新品到着' | ||
81 | + }), | ||
82 | + | ||
83 | + cartUrl: helpers.urlFormat('/cart/index/index', null), | ||
84 | + pageFooter: true, | ||
85 | + showDownloadApp: true, | ||
86 | + | ||
87 | + // 资源位 | ||
88 | + shopList, | ||
89 | + banner, | ||
90 | + handPick, | ||
91 | + | ||
92 | + // 搜索参数,貌似没用到 | ||
93 | + brand: '0', | ||
94 | + sort: '0', | ||
95 | + gender: req.query.gender || searchProcess.getGenderByChannel(channel), | ||
96 | + channel, | ||
97 | + price: '0', | ||
98 | + size: '0', | ||
99 | + dayLimit: 1, | ||
100 | + discount: '' | ||
101 | + }); | ||
102 | + }).catch(next); | ||
74 | 103 | ||
75 | - brand: '0', | ||
76 | - sort: '0', | ||
77 | - gender: req.query.gender || searchProcess.getGenderByChannel(channel), | ||
78 | - channel, | ||
79 | - price: '0', | ||
80 | - size: '0', | ||
81 | - dayLimit: 1, | ||
82 | - discount: '', | ||
83 | - cartUrl: helpers.urlFormat('/cart/index/index', null), | ||
84 | - pageFooter: true, | ||
85 | - showDownloadApp: true | ||
86 | - }); | ||
87 | }; | 104 | }; |
88 | 105 | ||
89 | /** | 106 | /** |
90 | * 新品到着 落地页: 为您推荐 | 107 | * 新品到着 落地页: 为您推荐 |
91 | */ | 108 | */ |
92 | const brands = (req, res, next) => { | 109 | const brands = (req, res, next) => { |
93 | - const channel = req.cookies._Channel; | 110 | + const channel = req.yoho.channel; |
94 | const uid = req.user.uid; | 111 | const uid = req.user.uid; |
95 | 112 | ||
96 | newModel.recbrand(uid, channel).then(data => { | 113 | newModel.recbrand(uid, channel).then(data => { |
@@ -132,9 +149,11 @@ const selectNewSale = (req, res, next) => { | @@ -132,9 +149,11 @@ const selectNewSale = (req, res, next) => { | ||
132 | * Router: /product/new/recommend-shop.json | 149 | * Router: /product/new/recommend-shop.json |
133 | */ | 150 | */ |
134 | const recommendShop = (req, res, next) => { | 151 | const recommendShop = (req, res, next) => { |
135 | - const channel = req.cookies._Channel; | 152 | + const channel = req.yoho.channel; |
136 | const uid = req.user.uid; | 153 | const uid = req.user.uid; |
137 | 154 | ||
155 | + console.log(channel) | ||
156 | + | ||
138 | newModel.recommendShops(uid, channel).then(data => { | 157 | newModel.recommendShops(uid, channel).then(data => { |
139 | res.json(data); | 158 | res.json(data); |
140 | }); | 159 | }); |
@@ -146,7 +165,7 @@ const recommendShop = (req, res, next) => { | @@ -146,7 +165,7 @@ const recommendShop = (req, res, next) => { | ||
146 | */ | 165 | */ |
147 | const fetchNew = (req, res, next) => { | 166 | const fetchNew = (req, res, next) => { |
148 | const uid = req.user.uid; | 167 | const uid = req.user.uid; |
149 | - const channel = req.cookies._Channel; | 168 | + const channel = req.yoho.channel; |
150 | 169 | ||
151 | delete req.query.uid; | 170 | delete req.query.uid; |
152 | delete req.query.channel; | 171 | delete req.query.channel; |
@@ -158,7 +177,7 @@ const fetchNew = (req, res, next) => { | @@ -158,7 +177,7 @@ const fetchNew = (req, res, next) => { | ||
158 | 177 | ||
159 | const goodsFilter = (req, res, next) => { | 178 | const goodsFilter = (req, res, next) => { |
160 | const uid = req.user.uid; | 179 | const uid = req.user.uid; |
161 | - const channel = req.cookies._Channel; | 180 | + const channel = req.yoho.channel; |
162 | 181 | ||
163 | newModel.reclistFilter(uid, channel).then(result => { | 182 | newModel.reclistFilter(uid, channel).then(result => { |
164 | res.render('search/filter', { | 183 | res.render('search/filter', { |
1 | {{!--新品到着--}} | 1 | {{!--新品到着--}} |
2 | <div> | 2 | <div> |
3 | {{!--top banner--}} | 3 | {{!--top banner--}} |
4 | + {{#if banner}} | ||
4 | <div class="banner-top"> | 5 | <div class="banner-top"> |
5 | <div class="banner-swiper swiper-container"> | 6 | <div class="banner-swiper swiper-container"> |
6 | <!-- Additional required wrapper --> | 7 | <!-- Additional required wrapper --> |
7 | <div class="swiper-wrapper"> | 8 | <div class="swiper-wrapper"> |
8 | <!-- Slides --> | 9 | <!-- Slides --> |
9 | <div class="swiper-slide"> | 10 | <div class="swiper-slide"> |
10 | - <a href=""> | ||
11 | - <img class="banner-top-pic" src="//img12.static.yhbimg.com/yhb-img01/2016/03/21/05/02c8856b64157f6fe018e76d1d5dbe6a92.jpg?imageView2/2/w/640/h/240/q/60" alt=""> | 11 | + {{#each banner.data}} |
12 | + <a href="{{url}}"> | ||
13 | + <img class="banner-top-pic swiper-lazy" data-src="{{image2 src w=750 h=234 q=60}}" alt=""> | ||
12 | </a> | 14 | </a> |
15 | + {{/each}} | ||
13 | </div> | 16 | </div> |
14 | </div> | 17 | </div> |
15 | - <div class="swiper-pagination"></div> | 18 | + <div class="swiper-pagination-s1"> |
19 | + <div id="banner-pagination" class="pagination-inner"></div> | ||
20 | + </div> | ||
16 | </div> | 21 | </div> |
17 | </div> | 22 | </div> |
23 | + {{/if}} | ||
18 | 24 | ||
19 | {{!--为您推荐--}} | 25 | {{!--为您推荐--}} |
26 | + {{#if shopList}} | ||
20 | <div id="new-recommend" class="new-recommend panel"> | 27 | <div id="new-recommend" class="new-recommend panel"> |
21 | <header class="panel-header"> | 28 | <header class="panel-header"> |
22 | <h3>为您推荐</h3> | 29 | <h3>为您推荐</h3> |
@@ -24,11 +31,16 @@ | @@ -24,11 +31,16 @@ | ||
24 | <i class="iconfont more"></i> | 31 | <i class="iconfont more"></i> |
25 | </a> | 32 | </a> |
26 | </header> | 33 | </header> |
27 | - <div class="panel-body"></div> | 34 | + <div class="panel-body"> |
35 | + {{> product/brands shops=shopList}} | ||
36 | + </div> | ||
28 | </div> | 37 | </div> |
38 | + {{/if}} | ||
29 | 39 | ||
30 | {{!--精选抢先看--}} | 40 | {{!--精选抢先看--}} |
31 | - {{> 'new/handpick'}} | 41 | + {{#if handPick.data}} |
42 | + {{> 'new/handpick' swiper=handPick.data}} | ||
43 | + {{/if}} | ||
32 | 44 | ||
33 | {{!--最新上架--}} | 45 | {{!--最新上架--}} |
34 | {{> 'new/goods'}} | 46 | {{> 'new/goods'}} |
1 | {{!-- 新品到着: 最新上架--}} | 1 | {{!-- 新品到着: 最新上架--}} |
2 | <div id="new-goods"> | 2 | <div id="new-goods"> |
3 | - <div> | 3 | + <div class="filter-nav-wrap" data-sticky> |
4 | {{> common/filter-nav}} | 4 | {{> common/filter-nav}} |
5 | + <div id="js-filter"></div> | ||
5 | </div> | 6 | </div> |
6 | 7 | ||
7 | <div class="goods-container"> | 8 | <div class="goods-container"> |
9 | + <div class="goods-box"></div> | ||
10 | + {{!-- | ||
8 | <div class="container" data-rel="new-0"></div> | 11 | <div class="container" data-rel="new-0"></div> |
9 | <div class="container" data-rel="price-0"></div> | 12 | <div class="container" data-rel="price-0"></div> |
10 | <div class="container" data-rel="price-1"></div> | 13 | <div class="container" data-rel="price-1"></div> |
11 | <div class="container" data-rel="discount-0"></div> | 14 | <div class="container" data-rel="discount-0"></div> |
12 | <div class="container" data-rel="discount-1"></div> | 15 | <div class="container" data-rel="discount-1"></div> |
13 | <div class="container" data-rel="filter"></div> | 16 | <div class="container" data-rel="filter"></div> |
14 | - <div id="js-filter"></div> | 17 | + --}} |
15 | </div> | 18 | </div> |
16 | 19 | ||
17 | {{> common/query-param}} | 20 | {{> common/query-param}} |
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | <div id="handpick" class="panel handpick"> | 2 | <div id="handpick" class="panel handpick"> |
3 | <header class="panel-header"> | 3 | <header class="panel-header"> |
4 | <h4>精选抢先看</h4> | 4 | <h4>精选抢先看</h4> |
5 | - <a href="#javascript" class="panel-header-r more"> | 5 | + {{!--<a href="#javascript" class="panel-header-r more"> |
6 | <i class="iconfont"></i> | 6 | <i class="iconfont"></i> |
7 | - </a> | 7 | + </a>--}} |
8 | </header> | 8 | </header> |
9 | <main class="panel-body"> | 9 | <main class="panel-body"> |
10 | <!-- Slider main container --> | 10 | <!-- Slider main container --> |
@@ -12,9 +12,13 @@ | @@ -12,9 +12,13 @@ | ||
12 | <!-- Additional required wrapper --> | 12 | <!-- Additional required wrapper --> |
13 | <div class="swiper-wrapper"> | 13 | <div class="swiper-wrapper"> |
14 | <!-- Slides --> | 14 | <!-- Slides --> |
15 | - <div class="swiper-slide">Slide 1</div> | ||
16 | - <div class="swiper-slide">Slide 2</div> | ||
17 | - <div class="swiper-slide">Slide 3</div> | 15 | + {{#each swiper}} |
16 | + <div class="swiper-slide"> | ||
17 | + <a href="{{url}}"> | ||
18 | + <img class="swiper-lazy" data-src="{{image2 src w=332 h=194 q=60}}" alt=""> | ||
19 | + </a> | ||
20 | + </div> | ||
21 | + {{/each}} | ||
18 | </div> | 22 | </div> |
19 | </div> | 23 | </div> |
20 | </main> | 24 | </main> |
@@ -49,6 +49,7 @@ const bottomBannerContentCode = { | @@ -49,6 +49,7 @@ const bottomBannerContentCode = { | ||
49 | const outletContentCode = 'c19ffa03f053f4cac3690b22c8da26b7'; | 49 | const outletContentCode = 'c19ffa03f053f4cac3690b22c8da26b7'; |
50 | 50 | ||
51 | 51 | ||
52 | +// TODO: remove | ||
52 | const newContentCode = { | 53 | const newContentCode = { |
53 | boys: '3cf2c1be5217fbab6009ce83959e1e12', | 54 | boys: '3cf2c1be5217fbab6009ce83959e1e12', |
54 | girls: '1cf7f9f10e2a2670e73d05c568793ad9', | 55 | girls: '1cf7f9f10e2a2670e73d05c568793ad9', |
@@ -56,6 +57,13 @@ const newContentCode = { | @@ -56,6 +57,13 @@ const newContentCode = { | ||
56 | lifestyle: '04953a61cbf1db426a681e55d496d2fe' | 57 | lifestyle: '04953a61cbf1db426a681e55d496d2fe' |
57 | }; | 58 | }; |
58 | 59 | ||
60 | +const newContentCodeV2 = { | ||
61 | + boys: '1f2e07cb63811680154ba693c954dd62', | ||
62 | + girls: '375f201d1ec56f7515509249c9c66959', | ||
63 | + kids: '74c62151673e7dde9fb154c90dcff3f0', | ||
64 | + lifestyle: 'b9b4bd0de670f982e1f8e7dc23980e81' | ||
65 | +}; | ||
66 | + | ||
59 | const liveContentCode = { | 67 | const liveContentCode = { |
60 | index: '345c80537dca15611f37ae4863004bfe' | 68 | index: '345c80537dca15611f37ae4863004bfe' |
61 | }; | 69 | }; |
@@ -66,6 +74,7 @@ module.exports = { | @@ -66,6 +74,7 @@ module.exports = { | ||
66 | channel: channelContentCode, | 74 | channel: channelContentCode, |
67 | bottom: bottomBannerContentCode, | 75 | bottom: bottomBannerContentCode, |
68 | guang: guangContentCode, | 76 | guang: guangContentCode, |
69 | - new: newContentCode, | 77 | + new: newContentCode, // TODO: remove |
78 | + newV2: newContentCodeV2, | ||
70 | live: liveContentCode | 79 | live: liveContentCode |
71 | }; | 80 | }; |
1 | <ul id="list-nav" class="list-nav filter-nav clearfix"> | 1 | <ul id="list-nav" class="list-nav filter-nav clearfix"> |
2 | - <li class="new active"> | 2 | + <li class="new active" data-order="s_t_desc"> |
3 | <a href="javascript:void(0);"> | 3 | <a href="javascript:void(0);"> |
4 | <span class="span-test">最新</span> | 4 | <span class="span-test">最新</span> |
5 | </a> | 5 | </a> |
@@ -8,8 +8,8 @@ | @@ -8,8 +8,8 @@ | ||
8 | <a href="javascript:void(0);"> | 8 | <a href="javascript:void(0);"> |
9 | <span class="span-test">价格</span> | 9 | <span class="span-test">价格</span> |
10 | <span class="icon"> | 10 | <span class="icon"> |
11 | - <i class="iconfont up cur"></i> | ||
12 | - <i class="iconfont down"></i> | 11 | + <i class="iconfont up cur" data-order="s_p_asc"></i> |
12 | + <i class="iconfont down" data-order="s_p_desc"></i> | ||
13 | </span> | 13 | </span> |
14 | </a> | 14 | </a> |
15 | </li> | 15 | </li> |
@@ -17,8 +17,8 @@ | @@ -17,8 +17,8 @@ | ||
17 | <a href="javascript:void(0);"> | 17 | <a href="javascript:void(0);"> |
18 | <span class="span-test">折扣</span> | 18 | <span class="span-test">折扣</span> |
19 | <span class="icon"> | 19 | <span class="icon"> |
20 | - <i class="iconfont up cur"></i> | ||
21 | - <i class="iconfont down"></i> | 20 | + <i class="iconfont up" data-order="p_d_asc"></i> |
21 | + <i class="iconfont down cur" data-order="s_p_desc"></i> | ||
22 | </span> | 22 | </span> |
23 | </a> | 23 | </a> |
24 | </li> | 24 | </li> |
@@ -2,13 +2,17 @@ | @@ -2,13 +2,17 @@ | ||
2 | require('product/new-arrival.page.css'); | 2 | require('product/new-arrival.page.css'); |
3 | require('common'); | 3 | require('common'); |
4 | require('common/suspend-cart'); | 4 | require('common/suspend-cart'); |
5 | +require('plugin/sticky'); | ||
5 | 6 | ||
6 | let Swiper = require('yoho-swiper'); | 7 | let Swiper = require('yoho-swiper'); |
7 | let lazyLoad = require('yoho-jquery-lazyload'); | 8 | let lazyLoad = require('yoho-jquery-lazyload'); |
8 | 9 | ||
9 | let filter = require('plugin/filter'); | 10 | let filter = require('plugin/filter'); |
10 | -let mySwiper = new Swiper('.handpick-swiper', { | 11 | + |
12 | +new Swiper('.handpick-swiper', { | ||
11 | // Optional parameters | 13 | // Optional parameters |
14 | + lazyLoading: true, | ||
15 | + lazyLoadingInPrevNext: true, | ||
12 | loop: true, | 16 | loop: true, |
13 | 17 | ||
14 | // If we need pagination | 18 | // If we need pagination |
@@ -16,62 +20,157 @@ let mySwiper = new Swiper('.handpick-swiper', { | @@ -16,62 +20,157 @@ let mySwiper = new Swiper('.handpick-swiper', { | ||
16 | centeredSlides: true, | 20 | centeredSlides: true, |
17 | paginationClickable: true, | 21 | paginationClickable: true, |
18 | spaceBetween: 30, | 22 | spaceBetween: 30, |
19 | - pagination: '.swiper-pagination', | ||
20 | }); | 23 | }); |
21 | 24 | ||
22 | -// ============================================== | ||
23 | -// function: 为您推荐 | ||
24 | -let recommendShops = function() { | ||
25 | - let $container = $('#new-recommend'); | ||
26 | - let fetchURI = '/product/new/recommend-shop.json'; | ||
27 | - let template = require('product/new/brands.hbs'); | ||
28 | - | ||
29 | - // 渲染模版并插入 | ||
30 | - function render(shops) { | ||
31 | - let html = template({shops}); | 25 | +new Swiper('.banner-swiper', { |
26 | + lazyLoading: true, | ||
32 | 27 | ||
33 | - $container.find('.panel-body').append(html); | ||
34 | - } | 28 | + // If we need pagination |
29 | + centeredSlides: true, | ||
30 | + paginationClickable: true, | ||
31 | + pagination: (function() { | ||
32 | + if ($('.banner-swiper').find('.swiper-slide').length > 1) { | ||
33 | + return '#banner-pagination'; | ||
34 | + } else { | ||
35 | + $('#banner-pagination').hide(); | ||
36 | + return null; | ||
37 | + } | ||
38 | + }()), | ||
39 | +}); | ||
35 | 40 | ||
36 | - $.get(fetchURI).done(shopData => { | ||
37 | - render(shopData.shop_list || []); | ||
38 | - }); | ||
39 | -}; | ||
40 | 41 | ||
41 | -recommendShops(); | 42 | +// ============================================== |
43 | +// 1 滚动: 搜索参数不变, 追加数据 | ||
44 | +// 2 筛选,切换排序: 重新搜索 | ||
45 | +// | ||
42 | 46 | ||
43 | 47 | ||
44 | -// ============================================== | ||
45 | let searchView = function() { | 48 | let searchView = function() { |
49 | + let body = document.body; | ||
46 | let $c = $('#new-goods'); | 50 | let $c = $('#new-goods'); |
47 | - let $nav = $c.find('filter-nav'); | ||
48 | - let $goodsBox = $c.find('.goods-container'); | 51 | + let $navBox = $c.find('.filter-nav'); |
52 | + let $goodsWraper = $c.find('.goods-container'); | ||
49 | 53 | ||
50 | - let $prevNav = null; | ||
51 | let goodsT = require('product/new/goods.hbs'); | 54 | let goodsT = require('product/new/goods.hbs'); |
52 | - | ||
53 | - // 给nav 设置 数据属性 | ||
54 | - $nav.children('.new').data('order', ['new', '0']); // 从新到旧 | ||
55 | - $nav.children('.price').data('order', ['price', '1']); // 从低到高 | ||
56 | - $nav.children('.discount').data('order', ['discount', '0']); // 折扣从大到小 | 55 | + let $loading = $('<div class="yo-loading"></div>'); |
56 | + | ||
57 | + let $prevNav = $navBox.children('.new'); | ||
58 | + let $goodBox = $goodsWraper.children('.goods-box'); | ||
59 | + let fetchXhr = null; | ||
60 | + | ||
61 | + /** | ||
62 | + * 搜索 参数 | ||
63 | + * Note:filter 没有重置功能 | ||
64 | + * see: search-process.js | ||
65 | + */ | ||
66 | + let searchParams = { | ||
67 | + order: 's_t_desc', | ||
68 | + filter: { | ||
69 | + }, | ||
70 | + page: { | ||
71 | + cur: 0, | ||
72 | + total: null | ||
73 | + } | ||
74 | + }; | ||
57 | 75 | ||
58 | 76 | ||
59 | 77 | ||
60 | 78 | ||
61 | function initFilter() { | 79 | function initFilter() { |
62 | - $.get('/product/new/goods-filter').done(filterHtml => { | ||
63 | - $('#js-filter').replaceWith(filterHtml); | 80 | + return $.get('/product/new/goods-filter').done(filterHtml => { |
81 | + $('#js-filter').html(filterHtml); | ||
64 | 82 | ||
65 | filter.initFilter({ | 83 | filter.initFilter({ |
66 | - fCbFn: $.noop, | ||
67 | - hCbFn: $.noop | 84 | + /** |
85 | + * filterObj: | ||
86 | + * {filtering, id, type} | ||
87 | + */ | ||
88 | + fCbFn: function(filterObj) { | ||
89 | + let filterKey = filterObj.type; | ||
90 | + | ||
91 | + // 字段正规化 | ||
92 | + let normalizeKey = ({ | ||
93 | + ageLevel: 'age_level' | ||
94 | + | ||
95 | + // TODO: 哪些字段不正规,添加再这里 | ||
96 | + })[filterKey]; | ||
97 | + | ||
98 | + normalizeKey && (filterKey = normalizeKey); | ||
99 | + | ||
100 | + // 放入查询参数 | ||
101 | + searchParams.filter[filterKey] = filterObj.id; | ||
102 | + | ||
103 | + console.log(searchParams); | ||
104 | + | ||
105 | + fetchNew({ // eslint-disable-line | ||
106 | + $box: $goodBox, | ||
107 | + before: $box => { | ||
108 | + fetchXhr.abort(); | ||
109 | + $box.html(''); | ||
110 | + } | ||
111 | + }); | ||
112 | + }, | ||
113 | + hCbFn: function() { | ||
114 | + // hide filter ,switch prev nav; | ||
115 | + $navBox.children('.filter').removeClass('active'); | ||
116 | + $prevNav.addClass('active'); | ||
117 | + } | ||
68 | }); | 118 | }); |
69 | }); | 119 | }); |
70 | } | 120 | } |
71 | 121 | ||
72 | - | 122 | + /** |
123 | + * 切换nav | ||
124 | + */ | ||
73 | function switchNav($nextNav) { | 125 | function switchNav($nextNav) { |
126 | + let _$prevNav = $navBox.children('.active'); // 当前active nav | ||
127 | + | ||
128 | + // active 不是filter, 都暂存起来,filter hide的时候用到 | ||
129 | + if (!_$prevNav.hasClass('filter')) { | ||
130 | + $prevNav = _$prevNav; | ||
131 | + } | ||
132 | + | ||
133 | + // 点击的nav 是filter nav | ||
134 | + if ($nextNav.hasClass('filter')) { | ||
135 | + let filterActived = $nextNav.hasClass('active'); | ||
136 | + | ||
137 | + filterActived ? filter.hideFilter() : filter.showFilter(); | ||
138 | + $prevNav.toggleClass('active', filterActived); | ||
139 | + $nextNav.toggleClass('active', !filterActived); | ||
74 | 140 | ||
141 | + return; | ||
142 | + } | ||
143 | + | ||
144 | + // 以下都是 order nav的情况, $prevNav始终是order nav; | ||
145 | + | ||
146 | + filter.hideFilter(); | ||
147 | + | ||
148 | + if (!$prevNav.is($nextNav)) { | ||
149 | + $prevNav.removeClass('active'); | ||
150 | + } else if ($nextNav.is('.price,.discount')) { // same && is price, discount | ||
151 | + let $cur = $nextNav.find('.cur'); | ||
152 | + | ||
153 | + $cur.removeClass('cur').siblings().addClass('cur'); | ||
154 | + } | ||
155 | + | ||
156 | + $nextNav.toggleClass('active', true); | ||
157 | + | ||
158 | + return $nextNav; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * order是否改变 | ||
163 | + * Note: filter的改变,有filter的回调处理 | ||
164 | + */ | ||
165 | + function checkOrderChange($activeNav, changeAction) { | ||
166 | + if (!$activeNav) { | ||
167 | + return; | ||
168 | + } | ||
169 | + | ||
170 | + let order = $activeNav.data('order') || $activeNav.find('.cur').data('order'); | ||
171 | + | ||
172 | + searchParams.order = order; | ||
173 | + changeAction(); | ||
75 | } | 174 | } |
76 | 175 | ||
77 | function renderGoods($container, data) { | 176 | function renderGoods($container, data) { |
@@ -80,26 +179,98 @@ let searchView = function() { | @@ -80,26 +179,98 @@ let searchView = function() { | ||
80 | }); | 179 | }); |
81 | 180 | ||
82 | $container.append(html); | 181 | $container.append(html); |
83 | - lazyLoad($container.find('.lazy')); | 182 | + |
183 | + | ||
184 | + lazyLoad(html); | ||
84 | } | 185 | } |
85 | 186 | ||
86 | - // search state | ||
87 | - function fetchNew(searchParams) { | ||
88 | - return $.get('/product/new/goods.json', searchParams) | ||
89 | - .then(data => { | ||
90 | - console.log(data); | ||
91 | - renderGoods($('.goods-container'), data.list); | 187 | + /** |
188 | + * 搜索 | ||
189 | + * @param conf | ||
190 | + * { | ||
191 | + * $box: 数据塞入的容器, | ||
192 | + * nextPage: true // 有该字段,且为true, 会去fetch 下一页数据 | ||
193 | + * before: 搜索之前的动作,第一个参数为 $box | ||
194 | + * } | ||
195 | + */ | ||
196 | + function fetchNew(conf) { | ||
197 | + let $box = conf.$box; | ||
198 | + let page = { | ||
199 | + cur: 0, | ||
200 | + total: null | ||
201 | + }; | ||
202 | + | ||
203 | + if (conf.nextPage) { | ||
204 | + page = searchParams.page; | ||
205 | + | ||
206 | + if (page.cur === page.total) { // no nore next | ||
207 | + return; | ||
208 | + } | ||
209 | + } | ||
210 | + | ||
211 | + conf.before && conf.before.apply(null, [$box]); | ||
212 | + | ||
213 | + // search params | ||
214 | + let data = {}; | ||
215 | + | ||
216 | + data.page = page.cur + 1; // fetch one page | ||
217 | + data.order = searchParams.order; | ||
218 | + $.extend(data, searchParams.filter); | ||
219 | + | ||
220 | + $loading.appendTo($box); | ||
221 | + return (fetchXhr = $.get('/product/new/goods.json', data)) | ||
222 | + .done(res => { | ||
223 | + searchParams.page.total = res.pageTotal; | ||
224 | + searchParams.page.cur = page.cur + 1; | ||
225 | + | ||
226 | + renderGoods($box, res.list); | ||
227 | + }) | ||
228 | + .always(() => { | ||
229 | + $loading.remove(); | ||
92 | }); | 230 | }); |
93 | } | 231 | } |
94 | 232 | ||
233 | + /** | ||
234 | + * 滚动到底部一定距离时, 加载下一页 | ||
235 | + */ | ||
236 | + function fetchNextPage() { | ||
237 | + fetchNew({ | ||
238 | + $box: $goodBox, | ||
239 | + nextPage: true | ||
240 | + }); | ||
241 | + } | ||
95 | 242 | ||
96 | - $nav.on('click', 'li', function(event) { | ||
97 | - let $curNav = $(event.target); | 243 | + initFilter() |
244 | + .done(function() { | ||
245 | + $navBox.on('click', 'li', function(event) { | ||
246 | + let $curNav = $(event.currentTarget); | ||
247 | + | ||
248 | + let $activeNav = switchNav($curNav); | ||
249 | + | ||
250 | + checkOrderChange($activeNav, function() { | ||
251 | + fetchNew({ // eslint-disable-line | ||
252 | + $box: $goodBox, | ||
253 | + before: $box => { | ||
254 | + fetchXhr.abort(); | ||
255 | + $box.html(''); | ||
256 | + } | ||
257 | + }); | ||
258 | + }); | ||
259 | + }); | ||
260 | + }); | ||
98 | 261 | ||
99 | - switchNav($curNav); | 262 | + $(window).scroll(function() { |
263 | + setTimeout(() => { | ||
264 | + if (body.scrollHeight - (body.scrollTop + body.scrollWidth) < 300 && fetchXhr.readyState === 4) { | ||
265 | + fetchNextPage(); | ||
266 | + } | ||
267 | + }, 0); | ||
100 | }); | 268 | }); |
101 | 269 | ||
102 | - initFilter(); | 270 | + |
271 | + fetchNew({ | ||
272 | + $box: $goodBox | ||
273 | + }); | ||
103 | 274 | ||
104 | return { | 275 | return { |
105 | fetchNew, | 276 | fetchNew, |
@@ -109,6 +280,7 @@ let searchView = function() { | @@ -109,6 +280,7 @@ let searchView = function() { | ||
109 | 280 | ||
110 | 281 | ||
111 | window.search = searchView(); | 282 | window.search = searchView(); |
283 | +window.filter = filter; | ||
112 | window.$ = $; | 284 | window.$ = $; |
113 | 285 | ||
114 | 286 |
public/scss/layout/_pagination.css
0 → 100644
@@ -523,4 +523,36 @@ | @@ -523,4 +523,36 @@ | ||
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | + | ||
527 | +.swiper-pagination-s1 { | ||
528 | + position: absolute; | ||
529 | + left: 0; | ||
530 | + right: 0; | ||
531 | + bottom: 0.5rem; | ||
532 | + text-align: center; | ||
533 | + z-index: 1; | ||
534 | + | ||
535 | + .pagination-inner { | ||
536 | + display: inline-block; | ||
537 | + padding: 0 0.2rem 0.1rem; | ||
538 | + background: rgba(0, 0, 0, 0.2); | ||
539 | + border-radius: 1.25rem; | ||
540 | + } | ||
541 | + | ||
542 | + .pagination-inner span { | ||
543 | + display: inline-block; | ||
544 | + width: 0.35rem; | ||
545 | + height: 0.35rem; | ||
546 | + background: #fff; | ||
547 | + opacity: 0.5; | ||
548 | + margin: 0 0.225rem; | ||
549 | + border-radius: 50% | ||
550 | + } | ||
551 | + | ||
552 | + .pagination-inner span.swiper-pagination-bullet-active { | ||
553 | + background: #fff; | ||
554 | + opacity: 1; | ||
555 | + } | ||
556 | +} | ||
557 | + | ||
526 | /* stylelint-enable */ | 558 | /* stylelint-enable */ |
public/scss/layout/_yo-loading.css
0 → 100644
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | @import '../layout/panel'; | 3 | @import '../layout/panel'; |
4 | @import '../layout/swiper'; | 4 | @import '../layout/swiper'; |
5 | +@import '../layout/yo-loading'; | ||
5 | @import '../common/filter'; | 6 | @import '../common/filter'; |
6 | @import '../common/good'; | 7 | @import '../common/good'; |
7 | @import 'new/recommend'; | 8 | @import 'new/recommend'; |
@@ -15,6 +16,16 @@ body { | @@ -15,6 +16,16 @@ body { | ||
15 | background-color: #f0f0f0; | 16 | background-color: #f0f0f0; |
16 | } | 17 | } |
17 | 18 | ||
19 | +.banner-swiper .swiper-slide { | ||
20 | + height: 234px; | ||
21 | +} | ||
22 | + | ||
23 | +.swiper-slide img { | ||
24 | + height: 100%; | ||
25 | + width: 100%; | ||
26 | +} | ||
27 | + | ||
28 | + | ||
18 | .goods-container { | 29 | .goods-container { |
19 | overflow: hidden; | 30 | overflow: hidden; |
20 | } | 31 | } |
@@ -35,11 +46,30 @@ body { | @@ -35,11 +46,30 @@ body { | ||
35 | min-height: 193px; | 46 | min-height: 193px; |
36 | } | 47 | } |
37 | 48 | ||
49 | +#js-filter { | ||
50 | + position: relative; | ||
51 | +} | ||
52 | + | ||
53 | +.filter-nav-wrap.sticky { | ||
54 | + position: fixed; | ||
55 | + top: 0; | ||
56 | + width: 100%; | ||
57 | + z-index: 2; | ||
58 | +} | ||
59 | + | ||
38 | .filter-nav { | 60 | .filter-nav { |
39 | border-top: 1PX solid #dededf; | 61 | border-top: 1PX solid #dededf; |
40 | border-bottom: 1PX solid #dededf; | 62 | border-bottom: 1PX solid #dededf; |
41 | } | 63 | } |
42 | 64 | ||
65 | +.filter-nav .iconfont { | ||
66 | + color: #999; | ||
67 | +} | ||
68 | + | ||
69 | +.filter-nav .iconfont.cur { | ||
70 | + color: inherit; | ||
71 | +} | ||
72 | + | ||
43 | .banner-top { | 73 | .banner-top { |
44 | border-bottom: 1PX solid #dededf; | 74 | border-bottom: 1PX solid #dededf; |
45 | margin-bottom: 30px; | 75 | margin-bottom: 30px; |
-
Please register or login to post a comment