...
|
...
|
@@ -39,128 +39,155 @@ const channelMap = { |
|
|
};
|
|
|
|
|
|
const getBannerList = data => {
|
|
|
let list = [];
|
|
|
let l = [];
|
|
|
|
|
|
_.forEach(data, (bannerData) => {
|
|
|
|
|
|
let obj = {};
|
|
|
|
|
|
obj.href = bannerData.url;
|
|
|
obj.img = bannerData.src;
|
|
|
obj.name = bannerData.title;
|
|
|
|
|
|
list.push(obj);
|
|
|
l.push(obj);
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
return l;
|
|
|
};
|
|
|
|
|
|
|
|
|
const getNewReportFloorData = data => {
|
|
|
let list = [];
|
|
|
|
|
|
_.forEach(data, (item, index) => {
|
|
|
if (item.data.text === '最新速报') {
|
|
|
let obj = {};
|
|
|
const getSlideData = srcData => {
|
|
|
let slideData = {
|
|
|
slide: {
|
|
|
list: [],
|
|
|
pagination: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
obj.href = data[index + 1].data[0].url;
|
|
|
obj.img = data[index + 1].data[0].src;
|
|
|
|
|
|
list.push(obj);
|
|
|
slideData.slide.list = getBannerList(srcData.big_image);
|
|
|
slideData.slide.pagination = getBannerList(srcData.list);
|
|
|
|
|
|
_.forEach(data[index + 2].data, (floorData) => {
|
|
|
let o = {};
|
|
|
return slideData;
|
|
|
};
|
|
|
|
|
|
o.href = floorData.url;
|
|
|
o.img = floorData.src;
|
|
|
|
|
|
list.push(o);
|
|
|
});
|
|
|
const getNewReportFloorData = (args) => {
|
|
|
let item = args[0].data;
|
|
|
let secondItem = args[1].data;
|
|
|
let thirdItem = args[2].data;
|
|
|
|
|
|
obj.href = data[index + 3].data[0].url;
|
|
|
obj.img = data[index + 3].data[0].src;
|
|
|
let list = [];
|
|
|
let obj = {};
|
|
|
|
|
|
list.push(obj);
|
|
|
let data = {
|
|
|
newReport: {
|
|
|
name: '最新速报',
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
obj.href = item[0].url;
|
|
|
obj.img = item[0].src;
|
|
|
|
|
|
list.push(obj);
|
|
|
|
|
|
_.forEach(secondItem, (floorData) => {
|
|
|
let o = {};
|
|
|
|
|
|
o.href = floorData.url;
|
|
|
o.img = floorData.src;
|
|
|
|
|
|
list.push(o);
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
obj.href = thirdItem[0].url;
|
|
|
obj.img = thirdItem[0].src;
|
|
|
|
|
|
list.push(obj);
|
|
|
|
|
|
data.newReport.list = list;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
// 热门品类
|
|
|
const getHotGoodsFloorData = data => {
|
|
|
const getHotGoodsFloorData = (args) => {
|
|
|
let item = args[0];
|
|
|
let nextItem = args[1];
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
_.forEach(data, (item, index) => {
|
|
|
if (item.template_intro === '热门品类') {
|
|
|
let object = {},
|
|
|
keyword = [],
|
|
|
category = [],
|
|
|
brands = [],
|
|
|
types = [],
|
|
|
navs = {},
|
|
|
products = [];
|
|
|
|
|
|
// console.log(item.data);
|
|
|
// console.log(item.data.menuNav);
|
|
|
// console.log(item.data.navs);
|
|
|
|
|
|
|
|
|
_.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, idx) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.img;
|
|
|
|
|
|
if (idx === 0 || idx === 4) {
|
|
|
brands.push(obj);
|
|
|
} else {
|
|
|
types.push(obj);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(data[index + 1].data, (it) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.src;
|
|
|
|
|
|
products.push(obj);
|
|
|
});
|
|
|
|
|
|
navs.name = item.data.navs.list[0].name;
|
|
|
navs.href = item.data.navs.list[0].url;
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = navs;
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
let object = {},
|
|
|
keyword = [],
|
|
|
category = [],
|
|
|
brands = [],
|
|
|
types = [],
|
|
|
navs = {},
|
|
|
products = [];
|
|
|
|
|
|
let data = {
|
|
|
recommend: {
|
|
|
tplrecommend: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
_.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, idx) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.img;
|
|
|
|
|
|
if (idx === 0 || idx === 4) {
|
|
|
brands.push(obj);
|
|
|
} else {
|
|
|
types.push(obj);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
_.forEach(nextItem.data, (it) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.src;
|
|
|
|
|
|
products.push(obj);
|
|
|
});
|
|
|
|
|
|
navs.name = item.data.navs.list[0].name;
|
|
|
navs.href = item.data.navs.list[0].url;
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = navs;
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
|
|
|
data.recommend.tplrecommend = list;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
const requestContent = type => {
|
...
|
...
|
@@ -177,34 +204,46 @@ const requestContent = type => { |
|
|
return serviceApi.get('/operations/api/v5/resource/home', data);
|
|
|
};
|
|
|
|
|
|
// boys, girls, kids, lifestyle
|
|
|
const floorMap = {
|
|
|
slide: getSlideData,
|
|
|
hot: getHotGoodsFloorData,
|
|
|
最新速报: getNewReportFloorData
|
|
|
};
|
|
|
|
|
|
const processFloorData = rawData => {
|
|
|
let floorList = [];
|
|
|
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = {};
|
|
|
|
|
|
if (data.template_name === 'recommend_content_three') {
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
} else if (data.data.text) {
|
|
|
floorData = floorMap[data.data.text] &&
|
|
|
floorMap[data.data.text].call(null, rawData.slice(index + 1, index + 5));
|
|
|
} else if (data.template_intro === '热门品类') {
|
|
|
floorData = floorMap.hot.call(null, rawData.slice(index, index + 2));
|
|
|
}
|
|
|
|
|
|
!_.isEmpty(floorData) && floorList.push(floorData);
|
|
|
});
|
|
|
|
|
|
return floorList;
|
|
|
};
|
|
|
|
|
|
// type => boys, girls, kids, lifestyle
|
|
|
exports.getContent = type => {
|
|
|
return Promise.all([headerModel.requestHeaderData(), requestContent(type)]).then(res => {
|
|
|
let headerData = res[0].data,
|
|
|
contentData = res[1].data;
|
|
|
contentData = res[1].data.list;
|
|
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
|
data = headerModel.setHeaderData(headerData, type);
|
|
|
data.module = 'channel';
|
|
|
data.page = type;
|
|
|
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)
|
|
|
};
|
|
|
data.channel = processFloorData(contentData);
|
|
|
|
|
|
return data;
|
|
|
});
|
...
|
...
|
|