Authored by 姜枫

完善列表页分页

@@ -3,46 +3,9 @@ @@ -3,46 +3,9 @@
3 3
4 const _ = require('lodash'); 4 const _ = require('lodash');
5 const Search = require('../models/list'); 5 const Search = require('../models/list');
  6 +const BrandData = require('../models/brand-service');
6 const camelCase = global.yoho.camelCase; 7 const camelCase = global.yoho.camelCase;
7 -  
8 -function brandLetters() {  
9 - let letters = [];  
10 -  
11 - letters.push({  
12 - letter: '0-9',  
13 - selected: false  
14 - });  
15 -  
16 - for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {  
17 - letters.push({  
18 - letter: String.fromCharCode(i),  
19 - selected: false  
20 - });  
21 - }  
22 -  
23 - return letters;  
24 -}  
25 -  
26 -function peopleChoose() {  
27 - return [  
28 - {  
29 - name: '男士',  
30 - value: '1,3'  
31 - }, {  
32 - name: '女士',  
33 - value: '2,3'  
34 - }];  
35 -}  
36 -  
37 -function colorConver(colors) {  
38 - return colors.map(c => {  
39 - return {  
40 - id: c.colorId,  
41 - title: c.colorName,  
42 - rgb: c.colorValue || '#' + c.colorCode  
43 - };  
44 - });  
45 -} 8 +const DateHelper = require('../models/helpers');
46 9
47 function newFilter(key, value, name) { 10 function newFilter(key, value, name) {
48 return { 11 return {
@@ -52,89 +15,27 @@ function newFilter(key, value, name) { @@ -52,89 +15,27 @@ function newFilter(key, value, name) {
52 }; 15 };
53 } 16 }
54 17
55 -function getNav(channel, sort, sorts) {  
56 - let nav = [{  
57 - link: '#',  
58 - pathTitle: '',  
59 - name: 'MEN首页'  
60 - }];  
61 -  
62 - if (sort) {  
63 - sorts.forEach(s => {  
64 - if (s.relationParameter.sort === sort) {  
65 - nav.push({  
66 - link: '#',  
67 - pathTitle: '',  
68 - name: s.categoryName  
69 - });  
70 - } else if (s.sub) {  
71 - s.sub.forEach(m => {  
72 - if (m.relationParameter.sort === sort) {  
73 - nav.push({  
74 - link: '#',  
75 - pathTitle: '',  
76 - name: s.categoryName  
77 - });  
78 - nav.push({  
79 - link: '#',  
80 - pathTitle: '',  
81 - name: m.categoryName  
82 - });  
83 - }  
84 - });  
85 - }  
86 - });  
87 - }  
88 - return nav;  
89 -}  
90 -  
91 -const list = {  
92 - index: (req, res, next) => {  
93 - let page = req.query.page || 1;  
94 - let brand = req.query.brand || 0;  
95 - let sort = req.query.sort || '';  
96 - let gender = req.query.gender || '';  
97 - let price = req.query.price || '';  
98 - let size = req.query.size || '';  
99 - let color = req.query.color || '';  
100 - let order = req.query.order || '';  
101 -  
102 - Search.queryProduct({  
103 - page: page,  
104 - brand: brand,  
105 - sort: sort,  
106 - gender: gender,  
107 - size: size,  
108 - price: price,  
109 - color: color,  
110 - order: order  
111 - }).then(result => {  
112 -  
113 - if (result && result.code === 200 && result.data) {  
114 - let data = camelCase(result.data);  
115 - let ret = {};  
116 -  
117 - if (data.filter) {  
118 - let priceRange = data.filter.priceRange;  
119 - let sizeInfo = data.filter.size;  
120 - let genders = peopleChoose(gender);  
121 - let brands = data.filter.brand;  
122 - let colors = colorConver(data.filter.color);  
123 - let sorts = data.filter.groupSort; 18 +function filterHandle(filter, q) {
  19 + let priceRange = filter.priceRange;
  20 + let sizeInfo = filter.size;
  21 + let genders = DateHelper.genders();
  22 + let brands = filter.brand;
  23 + let colors = DateHelper.colorConver(filter.color);
  24 + let sorts = filter.groupSort;
124 let filters = []; 25 let filters = [];
125 26
126 genders.forEach(g => { 27 genders.forEach(g => {
127 - if (g.value === gender) { 28 + if (g.value === q.gender) {
128 g.checked = true; 29 g.checked = true;
129 - filters.push(newFilter('gender', gender, g.name)); 30 + filters.push(newFilter('gender', q.gender, g.name));
130 } 31 }
131 }); 32 });
132 33
133 priceRange = Object.keys(priceRange).map((k) => { 34 priceRange = Object.keys(priceRange).map((k) => {
134 let prices = k.split(','); 35 let prices = k.split(',');
135 36
136 - if (k === price) {  
137 - filters.push(newFilter('price', price, ${prices[0]}-¥${prices[1]}`)); 37 + if (k === q.price) {
  38 + filters.push(newFilter('price', q.price, ${prices[0]}-¥${prices[1]}`));
138 } 39 }
139 return { 40 return {
140 lower: prices[0], 41 lower: prices[0],
@@ -149,30 +50,30 @@ const list = { @@ -149,30 +50,30 @@ const list = {
149 sizeInfo = [sizeInfo]; 50 sizeInfo = [sizeInfo];
150 } 51 }
151 52
152 - if (size) { 53 + if (q.size) {
153 sizeInfo.forEach(s => { 54 sizeInfo.forEach(s => {
154 - if (s.sizeId === parseInt(size)) {  
155 - filters.push(newFilter('size', size, s.sizeName)); 55 + if (s.sizeId === parseInt(q.size, 10)) {
  56 + filters.push(newFilter('size', q.size, s.sizeName));
156 } 57 }
157 }); 58 });
158 } 59 }
159 60
160 - if (brand) { 61 + if (q.brand) {
161 let brandNames = brands.filter(b => { 62 let brandNames = brands.filter(b => {
162 - return (',' + brand + ',').indexOf(',' + b.id + ',') >= 0; 63 + return (',' + q.brand + ',').indexOf(',' + b.id + ',') >= 0;
163 }).map(b => { 64 }).map(b => {
164 return b.brandName; 65 return b.brandName;
165 }).join('、'); 66 }).join('、');
166 67
167 - filters.push(newFilter('brand', brand, brandNames)); 68 + filters.push(newFilter('brand', q.brand, brandNames));
168 } 69 }
169 70
170 - if (color) { 71 + if (q.color) {
171 colors.forEach(c => { 72 colors.forEach(c => {
172 - if (c.id === parseInt(color)) { 73 + if (c.id === parseInt(q.color, 10)) {
173 c.cur = true; 74 c.cur = true;
174 75
175 - let fi = newFilter('color', color, c.title); 76 + let fi = newFilter('color', q.color, c.title);
176 77
177 fi.color = c; 78 fi.color = c;
178 filters.push(fi); 79 filters.push(fi);
@@ -180,7 +81,7 @@ const list = { @@ -180,7 +81,7 @@ const list = {
180 }); 81 });
181 } 82 }
182 83
183 - ret = { 84 + return {
184 people: genders, 85 people: genders,
185 sortData: sorts, 86 sortData: sorts,
186 brandData: brands, 87 brandData: brands,
@@ -189,31 +90,64 @@ const list = { @@ -189,31 +90,64 @@ const list = {
189 priceRange: priceRange, 90 priceRange: priceRange,
190 filters: filters, 91 filters: filters,
191 showFilters: filters.length > 0, 92 showFilters: filters.length > 0,
  93 + letters: DateHelper.brandLetters(),
192 navPath: { 94 navPath: {
193 - nav: getNav('', sort, sorts) 95 + nav: DateHelper.getNav('', q.sort, sorts)
194 } 96 }
195 }; 97 };
  98 +}
  99 +
  100 +const list = {
  101 + index: (req, res, next) => {
  102 + let page = req.query.page || 1;
  103 + let brand = req.query.brand || 0;
  104 + let sort = req.query.sort || '';
  105 + let gender = req.query.gender || '';
  106 + let price = req.query.price || '';
  107 + let size = req.query.size || '';
  108 + let color = req.query.color || '';
  109 + let order = req.query.order || '';
  110 +
  111 + let retDate = {
  112 + module: 'product',
  113 + page: 'list',
  114 + title: '列表'
  115 + };
  116 +
  117 + if (brand) {
  118 + BrandData.getBannerInfoAsync(brand).then(brandInfo => {
  119 + console.log(brandInfo);
  120 + });
196 } 121 }
197 122
198 - let pagination = { 123 + Search.queryProduct({
199 page: page, 124 page: page,
200 - limit: data.limit || 45,  
201 - total: data.total  
202 - }; 125 + brand: brand,
  126 + sort: sort,
  127 + gender: gender,
  128 + size: size,
  129 + price: price,
  130 + color: color,
  131 + order: order
  132 + }).then(result => {
203 133
204 - console.log(pagination); 134 + if (result && result.code === 200 && result.data) {
  135 + let data = camelCase(result.data);
  136 +
  137 + if (data.filter) {
  138 + retDate.filter = filterHandle(data.filter, req.query);
  139 + }
205 140
206 - res.display('list', _.assign(ret, {  
207 - letters: brandLetters(), 141 + retDate.paginationData = {
  142 + page: page,
  143 + limit: data.limit || 45,
208 total: data.total, 144 total: data.total,
209 pageTotal: data.pageTotal, 145 pageTotal: data.pageTotal,
210 - pageNo: data.page, 146 + queryParams: req.query
  147 + };
  148 + res.display('list', _.assign(retDate, {
211 products: data.productList, 149 products: data.productList,
212 - pagination: pagination,  
213 - order: order,  
214 - module: 'product',  
215 - page: 'list',  
216 - title: '列表' 150 + order: order
217 })); 151 }));
218 } else { 152 } else {
219 return Promise.reject('query product error'); 153 return Promise.reject('query product error');
  1 +/**
  2 + * @author: jiangfeng<jeff.jiang@yoho.cn>
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const api = global.yoho.API;
  8 +
  9 +const getBannerInfoAsync = bid => {
  10 + return api.get('', {
  11 + method: 'web.brand.banner',
  12 + brand_id: bid
  13 + });
  14 +
  15 +};
  16 +
  17 +const getBrandLogoByDomainAsync = domain => {
  18 + return api.get('', {
  19 + domain: domain,
  20 + method: 'web.brand.byDomain'
  21 + });
  22 +};
  23 +
  24 +module.exports = {
  25 + getBannerInfoAsync,
  26 + getBrandLogoByDomainAsync
  27 +};
  1 +/**
  2 + * Created by TaoHuang on 2016/6/14.
  3 + */
  4 +'use strict';
  5 +
  6 +const Promise = require('bluebird');
  7 +const co = Promise.coroutine;
  8 +const api = require('./brand-api');
  9 +const camelCase = global.yoho.camelCase;
  10 +
  11 +const getBrandByDomainAsync = domain => {
  12 + return co(function*() {
  13 + let brandInfo = yield api.getBrandLogoByDomainAsync(domain);
  14 +
  15 + if (!brandInfo.data || brandInfo.code !== 200) {
  16 + return {};
  17 + }
  18 +
  19 + return camelCase(brandInfo.data);
  20 + })();
  21 +};
  22 +
  23 +const getBannerInfoAsync = bid => {
  24 + return co(function*() {
  25 + let brandInfo = yield api.getBannerInfoAsync(bid);
  26 +
  27 + if (!brandInfo.data || brandInfo.code !== 200) {
  28 + return {};
  29 + }
  30 +
  31 + return camelCase(brandInfo.data);
  32 + })();
  33 +};
  34 +
  35 +module.exports = {
  36 + getBrandByDomainAsync,
  37 + getBannerInfoAsync: getBannerInfoAsync
  38 +};
  1 +'use strict';
  2 +
  3 +const helpers = {
  4 + brandLetters() {
  5 + let letters = [];
  6 +
  7 + letters.push({
  8 + letter: '0-9',
  9 + selected: false
  10 + });
  11 +
  12 + for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
  13 + letters.push({
  14 + letter: String.fromCharCode(i),
  15 + selected: false
  16 + });
  17 + }
  18 +
  19 + return letters;
  20 + },
  21 +
  22 + genders() {
  23 + return [
  24 + {
  25 + name: '男士',
  26 + value: '1,3'
  27 + }, {
  28 + name: '女士',
  29 + value: '2,3'
  30 + }];
  31 + },
  32 +
  33 + colorConver(colors) {
  34 + return colors.map(c => {
  35 + return {
  36 + id: c.colorId,
  37 + title: c.colorName,
  38 + rgb: c.colorValue || '#' + c.colorCode
  39 + };
  40 + });
  41 + },
  42 +
  43 + getNav(channel, sort, sorts) {
  44 + let nav = [{
  45 + link: '#',
  46 + pathTitle: '',
  47 + name: 'MEN首页'
  48 + }];
  49 +
  50 + if (sort) {
  51 + sorts.forEach(s => {
  52 + if (s.relationParameter.sort === sort) {
  53 + nav.push({
  54 + link: '#',
  55 + pathTitle: '',
  56 + name: s.categoryName
  57 + });
  58 + } else if (s.sub) {
  59 + s.sub.forEach(m => {
  60 + if (m.relationParameter.sort === sort) {
  61 + nav.push({
  62 + link: '#',
  63 + pathTitle: '',
  64 + name: s.categoryName
  65 + });
  66 + nav.push({
  67 + link: '#',
  68 + pathTitle: '',
  69 + name: m.categoryName
  70 + });
  71 + }
  72 + });
  73 + }
  74 + });
  75 + }
  76 + return nav;
  77 + }
  78 +};
  79 +
  80 +module.exports = helpers;
1 <div class="blk-page yoho-product-list"> 1 <div class="blk-page yoho-product-list">
2 <div class="center-content"> 2 <div class="center-content">
3 - {{# navPath}} 3 + {{# filter.navPath}}
4 {{> path-nav}} 4 {{> path-nav}}
5 - {{/ navPath}} 5 + {{/ filter.navPath}}
6 </div> 6 </div>
7 <div class="center-content clearfix"> 7 <div class="center-content clearfix">
8 <div class="left"> 8 <div class="left">
9 {{!-- 筛选区域 --}} 9 {{!-- 筛选区域 --}}
  10 + {{#filter}}
10 {{> list/filter}} 11 {{> list/filter}}
  12 + {{/filter}}
11 </div> 13 </div>
12 <div class="right"> 14 <div class="right">
13 {{!-- 已选中条件 --}} 15 {{!-- 已选中条件 --}}
  16 + {{#filter}}
14 {{> list/filter-area}} 17 {{> list/filter-area}}
  18 + {{/filter}}
15 {{!-- 排序 --}} 19 {{!-- 排序 --}}
16 {{> list/order-area}} 20 {{> list/order-area}}
17 {{!-- 商品列表 --}} 21 {{!-- 商品列表 --}}
18 {{> list/goods-box}} 22 {{> list/goods-box}}
19 {{!-- 分页 --}} 23 {{!-- 分页 --}}
20 - {{{ pagination pagination }}} 24 + {{{ pagination paginationData }}}
21 </div> 25 </div>
22 </div> 26 </div>
23 </div> 27 </div>
@@ -7,20 +7,22 @@ @@ -7,20 +7,22 @@
7 <span class="iconfont down s_p_desc {{#isEqual order 's_p_desc'}}selected{{/isEqual}}">&#xe616;</span> 7 <span class="iconfont down s_p_desc {{#isEqual order 's_p_desc'}}selected{{/isEqual}}">&#xe616;</span>
8 </div> 8 </div>
9 9
  10 + {{#paginationData}}
10 <div class="right"> 11 <div class="right">
11 <label> 12 <label>
12 <span>{{total}}</span>件商品 13 <span>{{total}}</span>件商品
13 </label> 14 </label>
14 - <label class="page-info"><span class="cur-page">{{pageNo}}</span>/<span class="total-page">{{pageTotal}}</span></label>  
15 - {{#isEqual pageNo 1}} 15 + <label class="page-info"><span class="cur-page">{{page}}</span>/<span class="total-page">{{pageTotal}}</span></label>
  16 + {{#isEqual page 1}}
16 <span class="iconfont page disable page-pre">&#xe607;</span> 17 <span class="iconfont page disable page-pre">&#xe607;</span>
17 {{^}} 18 {{^}}
18 <span class="iconfont page page-pre">&#xe607;</span> 19 <span class="iconfont page page-pre">&#xe607;</span>
19 {{/isEqual}} 20 {{/isEqual}}
20 - {{#isEqual pageNo pageTotal}} 21 + {{#isEqual page pageTotal}}
21 <span class="iconfont page disable page-next">&#xe61e;</span> 22 <span class="iconfont page disable page-next">&#xe61e;</span>
22 {{^}} 23 {{^}}
23 <span class="iconfont page page-next">&#xe61e;</span> 24 <span class="iconfont page page-next">&#xe61e;</span>
24 {{/isEqual}} 25 {{/isEqual}}
25 </div> 26 </div>
  27 + {{/paginationData}}
26 </div> 28 </div>
@@ -19,7 +19,7 @@ module.exports = { @@ -19,7 +19,7 @@ module.exports = {
19 }, 19 },
20 cookieDomain: 'yohoblk.com', 20 cookieDomain: 'yohoblk.com',
21 domains: { 21 domains: {
22 - api: 'http://api.yoho.yohoops.org/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078 22 + api: 'http://devapi.yoho.cn:58078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
23 service: 'http://devservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077 23 service: 'http://devservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
24 search: 'http://192.168.102.216:8080/yohosearch/' 24 search: 'http://192.168.102.216:8080/yohosearch/'
25 }, 25 },
@@ -15,4 +15,5 @@ module.exports = app => { @@ -15,4 +15,5 @@ module.exports = app => {
15 app.use('/', require('./apps/channel')); // 频道页 15 app.use('/', require('./apps/channel')); // 频道页
16 app.use('/me', require('./apps/me')); // 个人中心 16 app.use('/me', require('./apps/me')); // 个人中心
17 app.use('/editorial', require('./apps/editorial')); // 资讯 17 app.use('/editorial', require('./apps/editorial')); // 资讯
  18 + app.use('/product', require('./apps/product'));
18 }; 19 };