list.js
4.48 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* 列表页、新品到着列表页
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
*
*/
'use strict';
const _ = require('lodash');
const Search = require('../models/search');
const DataHelper = require('../models/helpers');
const Resouces = require('../models/resouces');
const list = {
// 列表页
index: (req, res, next) => {
let q = req.query;
let channel = req.query._Channel || req.cookies._Channel || 'men';
q.page = parseInt(q.page || 1, 10);
q.order = q.order || 's_n_desc';
q.yh_channel = channel;
let retData = {
module: 'product',
page: 'list',
title: '列表'
};
Promise.all([Search.queryAllSort(), Search.queryProduct(q)]).then(allResult => {
let allSort = allResult[0];
let result = allResult[1];
if (result && result.code === 200 && result.data) {
let data = result.data;
let nav = [DataHelper.getChannelNav(channel)];
if (data.filter) {
data.filter.standard = data.standard;
data.filter.group_sort = DataHelper.sortConvert(allSort.data.sort);
retData.filter = DataHelper.filterHandle(data.filter, q);
retData.filter.showPrice = data.total > 10;
retData.filter.showInfo = (retData.filter.style && retData.filter.style.length > 0)
|| (data.standard && data.standard.length > 0); //eslint-disable-line
nav = _.concat(nav, retData.filter.nav);
}
retData.navPath = {
nav: nav
};
retData.paginationData = {
page: q.page,
limit: data.limit || 45,
total: data.total,
pageTotal: data.page_total,
queryParams: q
};
res.display('list', _.assign(retData, {
products: DataHelper.handleProductList(data.product_list, q),
order: q.order
}));
} else {
return Promise.reject('query product error');
}
}).catch(next);
},
// 新品到着
newPage: (req, res, next) => {
let q = req.query;
let channel = req.query._Channel || req.cookies._Channel || 'men';
q.page = parseInt(q.page || 1, 10);
q.order = q.order || 's_n_desc';
q.yh_channel = channel;
let retData = {
module: 'product',
page: 'list',
title: '新品'
};
Promise.all([Resouces.newProductBanner(channel), Search.queryAllSort(),
Search.queryNewProduct(q)]).then(result => {
let banner = result[0];
let sortData = result[1];
let listData = result[2];
let nav = [DataHelper.getChannelNav(channel), {
name: '新品'
}];
retData.banner = banner;
if (listData && listData.code === 200 && listData.data) {
let data = listData.data;
if (data.filter) {
data.filter.standard = data.standard;
data.filter.group_sort = DataHelper.sortConvert(sortData.data.sort);
retData.filter = DataHelper.filterHandle(data.filter, q);
retData.filter.showPrice = data.total > 10;
// retData.filter.showInfo = (retData.filter.style && retData.filter.style.length > 0)
// || (data.standard && data.standard.length > 0); //eslint-disable-line
}
retData.navPath = {
nav: nav
};
retData.paginationData = {
page: q.page,
limit: data.limit || 45,
total: data.total,
pageTotal: data.page_total,
queryParams: q
};
res.display('newList', _.assign(retData, {
products: DataHelper.handleProductList(data.product_list, q),
order: q.order
}));
} else {
return Promise.reject('query product error');
}
}).catch(next);
}
};
module.exports = list;