...
|
...
|
@@ -3,46 +3,9 @@ |
|
|
|
|
|
const _ = require('lodash');
|
|
|
const Search = require('../models/list');
|
|
|
const BrandData = require('../models/brand-service');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
|
|
|
function 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;
|
|
|
}
|
|
|
|
|
|
function peopleChoose() {
|
|
|
return [
|
|
|
{
|
|
|
name: '男士',
|
|
|
value: '1,3'
|
|
|
}, {
|
|
|
name: '女士',
|
|
|
value: '2,3'
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
function colorConver(colors) {
|
|
|
return colors.map(c => {
|
|
|
return {
|
|
|
id: c.colorId,
|
|
|
title: c.colorName,
|
|
|
rgb: c.colorValue || '#' + c.colorCode
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
const DateHelper = require('../models/helpers');
|
|
|
|
|
|
function newFilter(key, value, name) {
|
|
|
return {
|
...
|
...
|
@@ -52,89 +15,27 @@ function newFilter(key, value, name) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
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
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
return nav;
|
|
|
}
|
|
|
|
|
|
const list = {
|
|
|
index: (req, res, next) => {
|
|
|
let page = req.query.page || 1;
|
|
|
let brand = req.query.brand || 0;
|
|
|
let sort = req.query.sort || '';
|
|
|
let gender = req.query.gender || '';
|
|
|
let price = req.query.price || '';
|
|
|
let size = req.query.size || '';
|
|
|
let color = req.query.color || '';
|
|
|
let order = req.query.order || '';
|
|
|
|
|
|
Search.queryProduct({
|
|
|
page: page,
|
|
|
brand: brand,
|
|
|
sort: sort,
|
|
|
gender: gender,
|
|
|
size: size,
|
|
|
price: price,
|
|
|
color: color,
|
|
|
order: order
|
|
|
}).then(result => {
|
|
|
|
|
|
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;
|
|
|
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 === gender) {
|
|
|
if (g.value === q.gender) {
|
|
|
g.checked = true;
|
|
|
filters.push(newFilter('gender', gender, g.name));
|
|
|
filters.push(newFilter('gender', q.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]}`));
|
|
|
if (k === q.price) {
|
|
|
filters.push(newFilter('price', q.price, `¥${prices[0]}-¥${prices[1]}`));
|
|
|
}
|
|
|
return {
|
|
|
lower: prices[0],
|
...
|
...
|
@@ -149,30 +50,30 @@ const list = { |
|
|
sizeInfo = [sizeInfo];
|
|
|
}
|
|
|
|
|
|
if (size) {
|
|
|
if (q.size) {
|
|
|
sizeInfo.forEach(s => {
|
|
|
if (s.sizeId === parseInt(size)) {
|
|
|
filters.push(newFilter('size', size, s.sizeName));
|
|
|
if (s.sizeId === parseInt(q.size, 10)) {
|
|
|
filters.push(newFilter('size', q.size, s.sizeName));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (brand) {
|
|
|
if (q.brand) {
|
|
|
let brandNames = brands.filter(b => {
|
|
|
return (',' + brand + ',').indexOf(',' + b.id + ',') >= 0;
|
|
|
return (',' + q.brand + ',').indexOf(',' + b.id + ',') >= 0;
|
|
|
}).map(b => {
|
|
|
return b.brandName;
|
|
|
}).join('、');
|
|
|
|
|
|
filters.push(newFilter('brand', brand, brandNames));
|
|
|
filters.push(newFilter('brand', q.brand, brandNames));
|
|
|
}
|
|
|
|
|
|
if (color) {
|
|
|
if (q.color) {
|
|
|
colors.forEach(c => {
|
|
|
if (c.id === parseInt(color)) {
|
|
|
if (c.id === parseInt(q.color, 10)) {
|
|
|
c.cur = true;
|
|
|
|
|
|
let fi = newFilter('color', color, c.title);
|
|
|
let fi = newFilter('color', q.color, c.title);
|
|
|
|
|
|
fi.color = c;
|
|
|
filters.push(fi);
|
...
|
...
|
@@ -180,7 +81,7 @@ const list = { |
|
|
});
|
|
|
}
|
|
|
|
|
|
ret = {
|
|
|
return {
|
|
|
people: genders,
|
|
|
sortData: sorts,
|
|
|
brandData: brands,
|
...
|
...
|
@@ -189,31 +90,64 @@ const list = { |
|
|
priceRange: priceRange,
|
|
|
filters: filters,
|
|
|
showFilters: filters.length > 0,
|
|
|
letters: DateHelper.brandLetters(),
|
|
|
navPath: {
|
|
|
nav: getNav('', sort, sorts)
|
|
|
nav: DateHelper.getNav('', q.sort, sorts)
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const list = {
|
|
|
index: (req, res, next) => {
|
|
|
let page = req.query.page || 1;
|
|
|
let brand = req.query.brand || 0;
|
|
|
let sort = req.query.sort || '';
|
|
|
let gender = req.query.gender || '';
|
|
|
let price = req.query.price || '';
|
|
|
let size = req.query.size || '';
|
|
|
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);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let pagination = {
|
|
|
Search.queryProduct({
|
|
|
page: page,
|
|
|
limit: data.limit || 45,
|
|
|
total: data.total
|
|
|
};
|
|
|
brand: brand,
|
|
|
sort: sort,
|
|
|
gender: gender,
|
|
|
size: size,
|
|
|
price: price,
|
|
|
color: color,
|
|
|
order: order
|
|
|
}).then(result => {
|
|
|
|
|
|
console.log(pagination);
|
|
|
if (result && result.code === 200 && result.data) {
|
|
|
let data = camelCase(result.data);
|
|
|
|
|
|
if (data.filter) {
|
|
|
retDate.filter = filterHandle(data.filter, req.query);
|
|
|
}
|
|
|
|
|
|
res.display('list', _.assign(ret, {
|
|
|
letters: brandLetters(),
|
|
|
retDate.paginationData = {
|
|
|
page: page,
|
|
|
limit: data.limit || 45,
|
|
|
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');
|
...
|
...
|
|