Authored by 姜枫

完善列表页分页

... ... @@ -3,89 +3,98 @@
const _ = require('lodash');
const Search = require('../models/list');
const BrandData = require('../models/brand-service');
const camelCase = global.yoho.camelCase;
const DateHelper = require('../models/helpers');
function brandLetters() {
let letters = [];
function newFilter(key, value, name) {
return {
key: key,
value: value,
name: name
};
}
function filterHandle(filter, q) {
let priceRange = filter.priceRange;
let sizeInfo = filter.size;
let genders = DateHelper.genders();
let brands = filter.brand;
let colors = DateHelper.colorConver(filter.color);
let sorts = filter.groupSort;
let filters = [];
genders.forEach(g => {
if (g.value === q.gender) {
g.checked = true;
filters.push(newFilter('gender', q.gender, g.name));
}
});
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
letters.push({
letter: '0-9',
selected: false
if (k === q.price) {
filters.push(newFilter('price', q.price, ${prices[0]}-¥${prices[1]}`));
}
return {
lower: prices[0],
higher: prices[1]
};
}).sort((a, b) => {
return a.lower - b.lower;
});
for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
letters.push({
letter: String.fromCharCode(i),
selected: false
if (!_.isArray(sizeInfo)) {
sizeInfo.checked = true;
sizeInfo = [sizeInfo];
}
if (q.size) {
sizeInfo.forEach(s => {
if (s.sizeId === parseInt(q.size, 10)) {
filters.push(newFilter('size', q.size, s.sizeName));
}
});
}
return letters;
}
if (q.brand) {
let brandNames = brands.filter(b => {
return (',' + q.brand + ',').indexOf(',' + b.id + ',') >= 0;
}).map(b => {
return b.brandName;
}).join('、');
function peopleChoose() {
return [
{
name: '男士',
value: '1,3'
}, {
name: '女士',
value: '2,3'
}];
}
filters.push(newFilter('brand', q.brand, brandNames));
}
function colorConver(colors) {
return colors.map(c => {
return {
id: c.colorId,
title: c.colorName,
rgb: c.colorValue || '#' + c.colorCode
};
});
}
if (q.color) {
colors.forEach(c => {
if (c.id === parseInt(q.color, 10)) {
c.cur = true;
function newFilter(key, value, name) {
return {
key: key,
value: value,
name: name
};
}
let fi = newFilter('color', q.color, c.title);
function getNav(channel, sort, sorts) {
let nav = [{
link: '#',
pathTitle: '',
name: 'MEN首页'
}];
if (sort) {
sorts.forEach(s => {
if (s.relationParameter.sort === sort) {
nav.push({
link: '#',
pathTitle: '',
name: s.categoryName
});
} else if (s.sub) {
s.sub.forEach(m => {
if (m.relationParameter.sort === sort) {
nav.push({
link: '#',
pathTitle: '',
name: s.categoryName
});
nav.push({
link: '#',
pathTitle: '',
name: m.categoryName
});
}
});
fi.color = c;
filters.push(fi);
}
});
}
return nav;
return {
people: genders,
sortData: sorts,
brandData: brands,
colors: colors,
size: sizeInfo,
priceRange: priceRange,
filters: filters,
showFilters: filters.length > 0,
letters: DateHelper.brandLetters(),
navPath: {
nav: DateHelper.getNav('', q.sort, sorts)
}
};
}
const list = {
... ... @@ -99,6 +108,18 @@ const list = {
let color = req.query.color || '';
let order = req.query.order || '';
let retDate = {
module: 'product',
page: 'list',
title: '列表'
};
if (brand) {
BrandData.getBannerInfoAsync(brand).then(brandInfo => {
console.log(brandInfo);
});
}
Search.queryProduct({
page: page,
brand: brand,
... ... @@ -112,108 +133,21 @@ const list = {
if (result && result.code === 200 && result.data) {
let data = camelCase(result.data);
let ret = {};
if (data.filter) {
let priceRange = data.filter.priceRange;
let sizeInfo = data.filter.size;
let genders = peopleChoose(gender);
let brands = data.filter.brand;
let colors = colorConver(data.filter.color);
let sorts = data.filter.groupSort;
let filters = [];
genders.forEach(g => {
if (g.value === gender) {
g.checked = true;
filters.push(newFilter('gender', gender, g.name));
}
});
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
if (k === price) {
filters.push(newFilter('price', price, ${prices[0]}-¥${prices[1]}`));
}
return {
lower: prices[0],
higher: prices[1]
};
}).sort((a, b) => {
return a.lower - b.lower;
});
if (!_.isArray(sizeInfo)) {
sizeInfo.checked = true;
sizeInfo = [sizeInfo];
}
if (size) {
sizeInfo.forEach(s => {
if (s.sizeId === parseInt(size)) {
filters.push(newFilter('size', size, s.sizeName));
}
});
}
if (brand) {
let brandNames = brands.filter(b => {
return (',' + brand + ',').indexOf(',' + b.id + ',') >= 0;
}).map(b => {
return b.brandName;
}).join('、');
filters.push(newFilter('brand', brand, brandNames));
}
if (color) {
colors.forEach(c => {
if (c.id === parseInt(color)) {
c.cur = true;
let fi = newFilter('color', color, c.title);
fi.color = c;
filters.push(fi);
}
});
}
ret = {
people: genders,
sortData: sorts,
brandData: brands,
colors: colors,
size: sizeInfo,
priceRange: priceRange,
filters: filters,
showFilters: filters.length > 0,
navPath: {
nav: getNav('', sort, sorts)
}
};
retDate.filter = filterHandle(data.filter, req.query);
}
let pagination = {
retDate.paginationData = {
page: page,
limit: data.limit || 45,
total: data.total
};
console.log(pagination);
res.display('list', _.assign(ret, {
letters: brandLetters(),
total: data.total,
pageTotal: data.pageTotal,
pageNo: data.page,
queryParams: req.query
};
res.display('list', _.assign(retDate, {
products: data.productList,
pagination: pagination,
order: order,
module: 'product',
page: 'list',
title: '列表'
order: order
}));
} else {
return Promise.reject('query product error');
... ...
/**
* @author: jiangfeng<jeff.jiang@yoho.cn>
*/
'use strict';
const api = global.yoho.API;
const getBannerInfoAsync = bid => {
return api.get('', {
method: 'web.brand.banner',
brand_id: bid
});
};
const getBrandLogoByDomainAsync = domain => {
return api.get('', {
domain: domain,
method: 'web.brand.byDomain'
});
};
module.exports = {
getBannerInfoAsync,
getBrandLogoByDomainAsync
};
... ...
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const api = require('./brand-api');
const camelCase = global.yoho.camelCase;
const getBrandByDomainAsync = domain => {
return co(function*() {
let brandInfo = yield api.getBrandLogoByDomainAsync(domain);
if (!brandInfo.data || brandInfo.code !== 200) {
return {};
}
return camelCase(brandInfo.data);
})();
};
const getBannerInfoAsync = bid => {
return co(function*() {
let brandInfo = yield api.getBannerInfoAsync(bid);
if (!brandInfo.data || brandInfo.code !== 200) {
return {};
}
return camelCase(brandInfo.data);
})();
};
module.exports = {
getBrandByDomainAsync,
getBannerInfoAsync: getBannerInfoAsync
};
... ...
'use strict';
const helpers = {
brandLetters() {
let letters = [];
letters.push({
letter: '0-9',
selected: false
});
for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
letters.push({
letter: String.fromCharCode(i),
selected: false
});
}
return letters;
},
genders() {
return [
{
name: '男士',
value: '1,3'
}, {
name: '女士',
value: '2,3'
}];
},
colorConver(colors) {
return colors.map(c => {
return {
id: c.colorId,
title: c.colorName,
rgb: c.colorValue || '#' + c.colorCode
};
});
},
getNav(channel, sort, sorts) {
let nav = [{
link: '#',
pathTitle: '',
name: 'MEN首页'
}];
if (sort) {
sorts.forEach(s => {
if (s.relationParameter.sort === sort) {
nav.push({
link: '#',
pathTitle: '',
name: s.categoryName
});
} else if (s.sub) {
s.sub.forEach(m => {
if (m.relationParameter.sort === sort) {
nav.push({
link: '#',
pathTitle: '',
name: s.categoryName
});
nav.push({
link: '#',
pathTitle: '',
name: m.categoryName
});
}
});
}
});
}
return nav;
}
};
module.exports = helpers;
... ...
<div class="blk-page yoho-product-list">
<div class="center-content">
{{# navPath}}
{{# filter.navPath}}
{{> path-nav}}
{{/ navPath}}
{{/ filter.navPath}}
</div>
<div class="center-content clearfix">
<div class="left">
{{!-- 筛选区域 --}}
{{#filter}}
{{> list/filter}}
{{/filter}}
</div>
<div class="right">
{{!-- 已选中条件 --}}
{{#filter}}
{{> list/filter-area}}
{{/filter}}
{{!-- 排序 --}}
{{> list/order-area}}
{{!-- 商品列表 --}}
{{> list/goods-box}}
{{!-- 分页 --}}
{{{ pagination pagination }}}
{{{ pagination paginationData }}}
</div>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -7,20 +7,22 @@
<span class="iconfont down s_p_desc {{#isEqual order 's_p_desc'}}selected{{/isEqual}}">&#xe616;</span>
</div>
{{#paginationData}}
<div class="right">
<label>
<span>{{total}}</span>件商品
</label>
<label class="page-info"><span class="cur-page">{{pageNo}}</span>/<span class="total-page">{{pageTotal}}</span></label>
{{#isEqual pageNo 1}}
<label class="page-info"><span class="cur-page">{{page}}</span>/<span class="total-page">{{pageTotal}}</span></label>
{{#isEqual page 1}}
<span class="iconfont page disable page-pre">&#xe607;</span>
{{^}}
<span class="iconfont page page-pre">&#xe607;</span>
{{/isEqual}}
{{#isEqual pageNo pageTotal}}
{{#isEqual page pageTotal}}
<span class="iconfont page disable page-next">&#xe61e;</span>
{{^}}
<span class="iconfont page page-next">&#xe61e;</span>
{{/isEqual}}
</div>
{{/paginationData}}
</div>
\ No newline at end of file
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain: 'yohoblk.com',
domains: {
api: 'http://api.yoho.yohoops.org/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api: 'http://devapi.yoho.cn:58078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://devservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
search: 'http://192.168.102.216:8080/yohosearch/'
},
... ...
... ... @@ -15,4 +15,5 @@ module.exports = app => {
app.use('/', require('./apps/channel')); // 频道页
app.use('/me', require('./apps/me')); // 个人中心
app.use('/editorial', require('./apps/editorial')); // 资讯
app.use('/product', require('./apps/product'));
};
... ...