list.js
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
const Search = require('../models/list');
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(channel) {
return [
{
name: '男士',
value: '0',
checked: channel === 'men'
}, {
name: '女士',
value: '1',
checked: channel === 'women'
}];
}
const list = {
index: (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel;
let sex = req.query.sex;
if (sex === '0') {
channel = 'men';
} else if (sex === '1') {
channel = 'women';
}
Search.queryProduct({}).then(result => {
if (result && result.code === 200 && result.data) {
let data = camelCase(result.data);
let priceRange = data.filter.priceRange;
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
return {
lower: prices[0],
higher: prices[1]
};
}).sort((a, b) => {
return a.lower - b.lower;
});
res.display('list', {
letters: brandLetters(),
people: peopleChoose(channel),
sortData: data.filter.groupSort,
brandData: data.filter.brand,
colors: data.filter.color,
size: data.filter.size,
priceRange: priceRange,
total: data.total,
pageTotal: data.pageTotal,
pageNo: data.page,
products: data.productList,
navPath: {
nav: true,
pathNav: [
{
link: true,
href: '',
pathTitle: '',
name: 'MEN首页'
},
{
link: true,
href: '',
pathTitle: '',
name: '咨询'
},
{
link: false,
href: '',
pathTitle: '',
name: '咨询'
}
]
},
module: 'product',
page: 'list',
title: '列表'
});
} else {
throw 'query product error';
}
}).catch(next);
}
};
module.exports = list;