brand.js
2.59 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
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/7/19
* Time: 13:51
*/
'use strict';
const brandApi = require('./brand-api');
const _ = require('lodash');
/**
* 处理品牌一览品牌列表数据
* @param origin
* @returns {Array}
*/
const handleBrandList = origin => {
let dest = {
brandList: [],
indexList: []
};
// 标记是否有数字,有数字先暂存
let hasNum = false;
let numTemp = {};
_.forEach(origin, (value, key) => {
let brands = [];
if (_.size(value) <= 0) {
return;
}
if (key === '0~9') {
hasNum = true;
numTemp = origin[key];
} else {
_.forEach(value, (subValue) => {
brands.push({
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
logo: subValue.brand_ico,
domain: subValue.brand_domain
});
});
dest.brandList.push({
index: key,
brands: brands
});
dest.indexList.push({
index: key,
name: key === '0~9' ? '0' : key
});
}
});
// 商品列表排序一次
_.sortBy(dest.brandList, o => {
return o.index.charCodeAt();
});
// 字母列表排序一次
_.sortBy(dest.indexList, o => {
return o.index.charCodeAt();
});
// 如果有数字,单独处理
if (hasNum) {
let brands = [];
_.forEach(numTemp, (subValue) => {
brands.push({
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
logo: subValue.brand_ico,
domain: subValue.brand_domain
});
});
dest.brandList.push({
index: '0~9',
brands: brands
});
dest.indexList.push({
index: '0_9',
name: '0'
});
}
return dest;
};
/**
* 获取品牌列表页数据
* @param params
*/
const getBrandListData = params => {
let finalResult = {};
return brandApi.getBrandListOriginData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, handleBrandList(result.data.all_list));
}
return finalResult;
});
};
/**
* 获取全部分类数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getCateListData = params => {
return brandApi.getCateListData(params);
};
module.exports = {
getBrandListData,
getCateListData
};