|
|
const getContent = () => {
|
|
|
const content = {
|
|
|
/**
|
|
|
* 频道页 model
|
|
|
* @author: 赵彪<bill.zhao@yoho.cn>
|
|
|
* @date: 2016/07/26
|
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
const channelApi = require('./channel-api');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
/**
|
|
|
* 获取slider楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getSliderData = d => {
|
|
|
|
|
|
return {
|
|
|
slider: d
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取BrandsAd楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getBrandAdFloor = d => {
|
|
|
|
|
|
_.forEach(d, data => {
|
|
|
data.btnText = 'shop now';
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
brandsAd: d
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取new arrivals楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getNewArrivals = d => {
|
|
|
_.forEach(d, (data, index) => {
|
|
|
if (index === 0 || index === d.length - 1) {
|
|
|
data.smallImg = true;
|
|
|
}
|
|
|
|
|
|
if (index % 2 === 0) {
|
|
|
data.even = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
floorZh: '新品抢鲜看',
|
|
|
floorEn: 'NEW ARRIVALS',
|
|
|
newArrivals: d
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取classic brands楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getClassicBrands = d => {
|
|
|
let brands = [];
|
|
|
let subArr;
|
|
|
let i = 0;
|
|
|
|
|
|
_.forEach(d, (data, index) => {
|
|
|
if (index === 0 || index === 1 || index === 6 || index === 7) {
|
|
|
brands.push({
|
|
|
big: [d[index]]
|
|
|
});
|
|
|
} else if ((index > 1 && index < 6 || index > 7 && index < 12) && index % 2 === 0) {
|
|
|
if (i < 4) {
|
|
|
subArr = d.slice(index, index + 2);
|
|
|
brands[i].small = subArr;
|
|
|
i += 1;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(brands, (data, index) => {
|
|
|
if (index < 2) {
|
|
|
data.bottomSpace = true;
|
|
|
}
|
|
|
|
|
|
if (index === 1 || index === 3) {
|
|
|
data.right = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
floorZh: '经典品牌',
|
|
|
floorEn: 'CLASSIC BRANDS',
|
|
|
classicBrands: brands
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取潮流标志楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getStyleIcon = d => {
|
|
|
_.forEach(d, data => {
|
|
|
data.btnText = '去看看';
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
floorZh: '潮流标志',
|
|
|
floorEn: 'STYLE ICON',
|
|
|
styleIcon: d
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取咨询楼层数据
|
|
|
* @param {Object} d 接口返回的楼层数据
|
|
|
* @return {Object} 处理之后的数据
|
|
|
*/
|
|
|
const _getEditorial = d => {
|
|
|
console.log(d);
|
|
|
return {
|
|
|
floorZh: '资讯',
|
|
|
floorEn: 'EDITORIAL',
|
|
|
editorial: d
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
const floorMap = {
|
|
|
slider: _getSliderData,
|
|
|
标题: _getBrandAdFloor,
|
|
|
新品抢先看: _getNewArrivals,
|
|
|
CLASSIC: _getClassicBrands,
|
|
|
潮流标识: _getStyleIcon,
|
|
|
EDITORIAL: _getEditorial
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取floorMap中对应的key
|
|
|
* @param {String} d 含有key的字符串
|
|
|
* @return {String} 得到的key值
|
|
|
*/
|
|
|
const _getKey = d => {
|
|
|
let k = d.split(' ')[0];
|
|
|
|
|
|
return k;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 判断title类型是否为对象
|
|
|
* @param {Object} t title
|
|
|
* @return {Boolen}
|
|
|
*/
|
|
|
const _isObjectTitle = t => {
|
|
|
return _.isObject(t);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 判断是否为Banner焦点图楼层
|
|
|
* @param {Object} d 楼层数据
|
|
|
* @return {Boolen}
|
|
|
*/
|
|
|
const _isBannerFloor = d => {
|
|
|
return d.templateName === 'focus' && d.templateIntro === '焦点图';
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取用于渲染模板的数据
|
|
|
* @param {Object} d 接口返回的数据
|
|
|
* @return {Array} 模板数据数组
|
|
|
*/
|
|
|
const _processFloorData = d => {
|
|
|
let floorList = [];
|
|
|
|
|
|
_.forEach(d, data => {
|
|
|
let floorTitle;
|
|
|
let floorData;
|
|
|
|
|
|
// 处理banner
|
|
|
if (_isBannerFloor(data)) {
|
|
|
floorData = floorMap.slider(data.data);
|
|
|
|
|
|
// 判断标题类型
|
|
|
} else if (_isObjectTitle(data.data.title)) {
|
|
|
floorTitle = _getKey(data.data.title.title);
|
|
|
floorData = floorMap[floorTitle](data.data.list);
|
|
|
} else {
|
|
|
floorTitle = _getKey(data.data.title);
|
|
|
floorData = floorMap[floorTitle](data.data.list);
|
|
|
}
|
|
|
|
|
|
floorList.push(floorData);
|
|
|
});
|
|
|
|
|
|
return floorList;
|
|
|
};
|
|
|
|
|
|
const getContent = type => {
|
|
|
return channelApi.getChannelDataAsync(type).then(result => {
|
|
|
const l = camelCase(result.data.list);
|
|
|
const floor = {
|
|
|
content: _processFloorData(l)
|
|
|
};
|
|
|
|
|
|
return floor;
|
|
|
});
|
|
|
|
|
|
/* eslint-disable */
|
|
|
const content = {
|
|
|
content: [
|
|
|
{
|
|
|
slider: [
|
...
|
...
|
@@ -250,7 +463,7 @@ const getContent = () => { |
|
|
};
|
|
|
/* eslint-enable */
|
|
|
|
|
|
return content;
|
|
|
// return content;
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|