brand.js
1.33 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
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const _processListData = (list) => {
let category = {
key: '',
brands: []
};
let listData = [];
list = list || [];
list = camelCase(list);
_.forEach(list.data, function(value, index) {
_.forEach(value, function(obj) {
obj.brandIco = `//img13.static.yhbimg.com/brandLogo/${obj.brandIco}?imageView2/3/w/{width}/h/{height}`;
if (!_.isNaN(+index)) {
category.key = '0-9';
category.brands.push(obj);
}
});
if (_.isNaN(+index)) {
listData.push(
{
key: index,
brands: value
}
)
}
console.log(value)
});
listData.push(category);
return listData;
};
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 {};
}
});
};
module.exports = {
getListData: getListData
};