product-list.js
2.37 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
/**
* 产品列表页 controller
* @author 陈轩 <xuan.chen@yoho.cn>
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const prettyFilter = require(`${global.utils}/beautify/filters`);
const processProductList = require(`${global.utils}/beautify/product`);
/* 搜索 页面 */
exports.index = (req, res) => {
const view = {
module: 'product',
page: 'list'
};
res.render('product-list', view);
};
/* 筛选的二级页面 */
exports.subFilter = (req, res) => {
const view = {
module: 'product',
page: 'filter-sub'
};
res.render('filter-sub', view);
};
/* 获取 筛选配置 */
exports.fetchFilters = (req, res, next) => {
const params = {
uid: 14741796, // mock data
page: req.body.page || 1,
order: req.body.order || 1,
yh_channel: req.body.yh_channel || 'all',
channel: req.body.channel || 'all',
};
const data = _.merge({
method: 'app.search.sales',
}, params);
api.post('', data, {
cache: true,
code: 200
})
.then(result => {
let filterConfig = {};
if (result.code === 200 || !result.hasOwnProperty('code')) {
prettyFilter(result.data.filter);
filterConfig = camelCase(result.data.filter);
}
res.json({
code: result.code,
data: filterConfig
});
})
.catch(next);
};
/* 查询 产品列表 */
exports.fetchProducts = (req, res, next) => {
const params = {
uid: 14741796, // mock data
page: req.body.page || 1,
order: req.body.order || 1,
yh_channel: req.body.yh_channel || 'all',
channel: req.body.channel || 'all',
};
const data = _.merge({
method: 'app.search.sales',
}, params);
api.post('', data, {
cache: true,
code: 200
})
.then(result => {
if (!result.hasOwnProperty('code')) {
result.code = 200;
}
if (result.code === 200) {
prettyFilter(result.data.filter);
result.data.productList = processProductList(result.data.productList);
result = camelCase(result);
}
res.json(result);
})
.catch(next);
};