index.js
4.56 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* girls model
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/05/17
*/
'use strict';
const _ = require('lodash');
const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
const sign = require(`${global.library}/sign`);
const serviceApi = new ServiceAPI();
const headerModel = require('../../../doraemon/models/header');
// 创意生活
// const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
// const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
const channelMap = {
boys: {
code: '79372627eee75d73afe7f9bac91e5ce6',
gender: '1,3'
},
girls: {
code: '75215008957605c05e8cd375eac4f817',
gender: '2,3'
},
kids: {
code: 'd71f4b27f2a7229fbb31a4bc490a6f36',
gender: 'kids'
},
lifestyle: {
code: '8a341ca7eacc069ba80f02dec80eaf34',
gender: 'lifestyle'
}
};
const getBannerList = data => {
let list = [];
_.forEach(data, (bannerData) => {
let obj = {};
obj.href = bannerData.url;
obj.img = bannerData.src;
obj.name = bannerData.title;
list.push(obj);
});
return list;
};
const getNewReportFloorData = data => {
let list = [];
_.forEach(data, (item, index) => {
if (item.data.text === '最新速报') {
let obj = {};
obj.href = data[index + 1].data[0].url;
obj.img = data[index + 1].data[0].src;
list.push(obj);
_.forEach(data[index + 2].data, (floorData) => {
let o = {};
o.href = floorData.url;
o.img = floorData.src;
list.push(o);
});
obj.href = data[index + 3].data[0].url;
obj.img = data[index + 3].data[0].src;
list.push(obj);
}
});
return list;
};
// 热门品类
const getHotGoodsFloorData = data => {
let list = [];
_.forEach(data, (item) => {
if (item.template_intro === '热门品类') {
let object = {},
keyword = [],
category = [],
brands = [],
types = [];
// product = [];
// console.log(item.data);
// console.log(item.data.menuNav);
// console.log(item.data.navs);
// return false;
_.forEach(item.data.menuNav.list, (it) => {
let obj = {};
obj.name = it.name;
obj.href = it.url;
category.push(obj);
});
_.forEach(item.data.menuNav.blocks, (it) => {
let obj = {};
obj.name = it.title;
obj.href = it.url;
obj.img = it.img;
keyword.push(obj);
});
_.forEach(item.data.imgs, (it, index) => {
let obj = {};
obj.name = it.title;
obj.href = it.url;
obj.img = it.img;
if (index < 2) {
brands.push(obj);
} else {
types.push(obj);
}
});
object.keyword = keyword;
object.category = category;
object.brands = brands;
object.types = types;
list.push(object);
}
});
return list;
};
const requestContent = (type) => {
let data = sign.apiSign({
/* eslint-disable */
client_type: 'web',
/* eslint-enable */
content_code: channelMap[type || 'boys'].code,
gender: channelMap[type || 'boys'].gender,
page: 1,
limit: 1000
});
return serviceApi.get('/operations/api/v5/resource/home', data);
};
exports.getContent = (type) => {
return Promise.all([headerModel.requestHeaderData(), requestContent(type)]).then(res => {
let headerData = res[0].data,
contentData = res[1].data;
let data = {};
data = headerModel.setHeaderData(headerData, 'boys');
data.module = 'channel';
data.page = 'boys';
data.footerTop = true;
data.channel = true;
data.slide = {
list: getBannerList(contentData.list[0].data.big_image),
pagination: getBannerList(contentData.list[0].data.list)
};
data.newReport = {
name: '最新速报',
list: getNewReportFloorData(contentData.list)
};
data.recommend = {
tplrecommend: getHotGoodsFloorData(contentData.list)
};
console.log(data.newReport);
return data;
});
};