resources-process.js 2.21 KB
const _ = require('lodash');
const processTime = require('./time-process');
const camelCase = global.yoho.camelCase;

/**
 * 处理楼层数据
 * @param  {[array]} list
 * @return {[array]}
 */
module.exports = (list) => {
    const formatData = [];

    list = list || [];
    list = camelCase(list);

    _.forEach(list, (floor) => {
        floor[_.camelCase(floor.templateName)] = true;

        // 特殊资源位处理
        // PLUS
        if (floor.singleNameImage && floor.data) {
            floor.data.title = {
                title: floor.data.title
            };
        }

        // 潮流时装/经典裤裙/时尚靴履/潮人配饰/潮流上装
        if (floor.recommendContentOne && floor.data) {
            if (floor.data.bigImage && floor.data.bigImage.length > 1) {
                floor.data.bigImage = {
                    bigList: floor.data.bigImage
                };
            }
        }

        // OUTLETS
        if (floor.titleImage && floor.data) {
            if (floor.data.image) {
                floor.data.bigImage = {
                    bigList: [floor.data.image]
                };
            }

            floor.data.title = {
                moreName: floor.data.moreName,
                moreUrl: floor.data.moreUrl,
                title: floor.data.title
            };
        }

        // 折扣专场
        if (floor.discountActivity && floor.data && floor.data.list.length) {
            _.map(floor.data.list, (item) => {
                Object.assign(item, processTime(item.leftTime));
            });
        }

        // 断码区 , 此资源位数据结构比较坑
        if (floor.offCodeArea && floor.data && floor.data.list.length) {
            floor.data = {
                title: floor.data.title,
                data: [floor.data.list[0]],
                left: [floor.data.list[1]],
                right: floor.data.list.slice(2)
            };
        }

        // 会员专享
        if (floor.vipFloor && floor.data) {
            floor.data.data = floor.data.image;
        }

        // 单张轮播图
        floor.singleImage &&
        floor.data.length === 1 &&
        (floor.singleOne = true);

        formatData.push(floor);
    });


    return formatData;
};