|
@@ -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');
|