Authored by 周少峰

outlets channel data

... ... @@ -269,7 +269,6 @@ exports.channel = (req, res) => {
outlets.getOutletsChannelData({channel:req.params.channel}).then(outletsData => {
response.module = 'product';
response.page = 'outlets';
response.footerTop = true;
response.devEnv = true;
//输出数据
Object.assign(response, outletsData);
... ...
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const _ = require('lodash');
const camelCase = require('../../../library/camel-case');
/**
* NL2R图片轮播
*/
const NL2R = (data) => {
const result = {
left: [],
right: [],
};
//左侧
_.forEach(data.left, (value, key) => {
result.left.push({
img: value.src,
url: value.url
});
})
//右侧
_.forEach(data.right, (value, key) => {
result.right.push({
img: value.src,
url: value.url
});
})
return result
}
/**
* 热门分类
*/
const hotCategory = (data) => {
return {
hotCategory: {
name: data.name,
list: data.menuNav.list,
blocks: data.menuNav.blocks,
brands: data.imgs.slice(0, 1),
types: data.imgs.slice(1, 7)
}
}
}
/**
* 分类导航
*/
const categoryNavigation = (data) => {
}
/**
* 处理楼层数据
* @param {[array]} list
* @return {[array]}
*/
exports.processFloor = (list) => {
const formatData = [];
var floorData;
list = list || [];
list = camelCase(list);
//格式化数据
_.forEach(list, (floor) => {
switch (floor.templateName) {
case 'NL2R':
floorData = NL2R(floor.data);
break;
case 'hotCategory':
floorData = hotCategory(floor.data);
break;
case 'categoryNavigation':
floorData = categoryNavigation(floor.data);
break;
default:
floorData = floor.data;
break;
}
Object.assign(formatData, floorData);
});
return formatData;
};
/**
* 组织嗨购数据
*/
exports.formatActivityData = (data) => {
var high = {
name: '限时嗨购',
imgHot: []
};
_.forEach(data, (value) => {
high.imgHot.push({
url: value.webUrl,
img: value.coverUrl,
logo: value.logoUrl,
name: value.title,
price: value.promotionName,
count: value.endTime
});
})
return high;
}
\ No newline at end of file
... ...
... ... @@ -15,6 +15,8 @@ const api = new API();
const sign = require(`${library}/sign`);
const helpers = require(`${library}/helpers`);
const camelCase = require('../../../library/camel-case');
const saleApi = require('./sale-api');
const outletsProcess = require('./outlets-handler');
/**
... ... @@ -75,84 +77,20 @@ const channelCode = {
}
/**
* 处理楼层数据
* @param {[array]} list
* @return {[array]}
*/
const processFloor = (list) => {
const formatData = [];
var floorData;
list = list || [];
list = camelCase(list);
//格式化数据
_.forEach(list, (floor) => {
if (floor.templateName === 'NL2R' && floor.data) {
floorData = NL2R(floor.data);
}
if (floor.templateName === 'hotCategory' && floor.data) {
floorData = hotCategory(floor.data);
console.log(floorData)
}
Object.assign(formatData, floorData);
});
return formatData;
};
//NL2R图片轮播
const NL2R = (data) => {
const result = {
left: [],
right: [],
};
//左侧
_.forEach(data.left, (value, key) => {
result.left.push({
img: value.src,
url: value.url
});
})
//右侧
_.forEach(data.right, (value, key) => {
result.right.push({
img: value.src,
url: value.url
});
})
return result
}
// 热门分类
const hotCategory = (data) => {
return {
hotCategory: {
name: data.name,
list: data.menuNav.list,
blocks: data.menuNav.blocks,
brands: data.imgs.slice(0, 1),
types: data.imgs.slice(1, 7)
}
}
}
/**
* 获取奥莱频道页面数据
* @param {[object]} gender
* @return {[type]}
*/
exports.getOutletsChannelData = (params) => {
return api.all([getChannelResouceData({content_code: channelCode[params.channel]}), getOutletsActivityData()]).then(result => {
if (resul[0].code === 200) {
return processFloor(result[0].data.list);
}
if (resul[1].code === 200) {
var channelData = {};
return api.all([getChannelResouceData({content_code: channelCode[params.channel]}), getOutletsActivityData({platform: 2, size: 0, type:1})]).then(result => {
if (result[0].code === 200) {
Object.assign(channelData, outletsProcess.processFloor(result[0].data.list));
}
if (result[1].code === 200) {
Object.assign(channelData, {flashSale: outletsProcess.formatActivityData(result[1].data)});
}
return channelData;
});
}
... ... @@ -162,7 +100,7 @@ exports.getOutletsChannelData = (params) => {
* @return {[type]}
*/
const getChannelResouceData = (params) => {
return serviceApi.get('operations/api/v5/resource/home', params)
return serviceApi.get('operations/api/v5/resource/home', sign.apiSign(params))
}
/**
... ... @@ -181,3 +119,17 @@ const getOutletsActivityData = (params) => {
method: 'app.outlets.activityGet',
}, params)));
}
/**
* 获取奥莱频道商品分类
* @param {[object]} params
* @return {[type]}
*/
const getOutletsSortData = (params) => {
return api.get('', sign.apiSign(
Object.assign({
method: 'app.outlets.activityGet',
}, params)));
}
... ...
... ... @@ -5,13 +5,13 @@
{{#each imgHot}}
<li>
<a href="{{href}}" target= "_blank"><div class="flash-sale-banner">
<img src="{{img}}"/></div>
<img src="{{image img 560 260}}"/></div>
<div class="flash-sale-bottom">
<p class="flash-sale-count">{{count}}折起</p>
<p class="flash-sale-name">{{name}}</p>
<p class="flash-sale-timer">timer</p>
<div class="flash-sale-logo">
<img src="{{logo}}"/>
<img src="{{image logo 100 60}}"/>
</div>
</div>
</a>
... ...