resources-process.js 2.96 KB
'use strict';

const _ = require('lodash');
const processTime = require('./time-process');

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

    list = list || [];

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

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

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

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

            floor.data.title = {
                more_name: floor.data.more_name,
                more_url: floor.data.more_url,
                title: floor.data.title
            };
        }

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

        // 断码区 , 此资源位数据结构比较坑
        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);

        // 处理价格两位小数
        if ((floor.vipUse || floor.popularSingleProduct || floor.newUserFloor) && floor.data) {
            for (let item of floor.data.list) {
                item.vip1_price && (item.vip1_price = item.vip1_price.toFixed(2));
                item.vip2_price && (item.vip2_price = item.vip2_price.toFixed(2));
                item.vip3_price && (item.vip3_price = item.vip3_price.toFixed(2));
                item.sales_price && (item.sales_price = item.sales_price.toFixed(2));
                item.market_price && (item.market_price = item.market_price.toFixed(2));
            }
        }

        // sale banner名字
        if (floor.sale1T1L4R && floor.data && floor.data.big_image) {
            floor.data.banner_image = floor.data.big_image;
        }
        
        formatData.push(floor);
    });


    return formatData;
};