brand.js
2.31 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
'use strict';
// const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const logger = global.yoho.logger;
const _processListData = (list) => {
// let category = {
// key: '',
// brands: []
// };
let listData = [];
list = list || [];
list = camelCase(list);
console.log(list);
_.forEach(list.data.allList, function(value, index) {
if (index === '0~9') {
index = '0-9';
}
listData.push(
{
key: index,
brands: value
}
);
});
return listData;
};
const _processTabData = (list) => {
list = list || [];
list = camelCase(list);
console.log(list);
// let artList = list.list.artList.map(data =>{
// data.publishTime = data.publishTime.replace(/年|月/g, '/');
// data.publishTime = data.publishTime.replace(/日/g, '');
// return data;
// });
};
const _getResources = () => {
return api.get('', {
method: 'web.brand.series'
}).then((result) => {
if (result && result.code === 200) {
return _processTabData(result.data);
} else {
logger.error('品牌页Tab数据返回 code 不是 200');
return {};
}
});
};
const _getBreakingSort = () => {
return api.get('', {
method: 'app.brand.newBrandList'
}).then((result) => {
if (result && result.code === 200) {
return _processListData(result);
} else {
logger.error('品牌页数据返回 code 不是 200');
return {};
}
});
};
// const getListData = () => {
// return api.get('', {
// method: 'app.brand.newBrandList'
// }).then((result) => {
// if (result && result.code === 200) {
// return _processListData(result);
// } else {
// logger.error('品牌页数据返回 code 不是 200');
// return {};
// }
// });
// };
const getListData = () => {
return Promise.all([_getResources(), _getBreakingSort()])
.then((result) => {
return {
tabs: result[0],
category: result[1]
};
});
};
module.exports = {
getListData: getListData
};