brand.js 1.68 KB
'use strict';

// const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const logger = global.yoho.logger;

const _processListData = (list) => {
    // let category = {
    //     key: '',
    //     brands: []
    // };

    let listData = [];

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

    _.forEach(list.data.allList, function(value, index) {

        if (index === '0~9') {
            index = '0-9';
        }

        listData.push(
            {
                key: index,
                brands: value
            }
        );
    });

    return listData;
};

const _processTabData = (list) => {
    list = list || [];
    list = camelCase(list);

};

const _getResources = () => {
    return api.get('', {

        // method: 'web.brand.series'
    }).then((result) => {
        if (result && result.code === 200) {
            return _processTabData(result.data);
        } else {

            // logger.error('品牌页Tab数据返回 code 不是 200');
            // return {};
        }
    });
};

const _getBreakingSort = () => {
    return api.get('', {
        method: 'app.brand.newBrandList'
    }).then((result) => {
        if (result && result.code === 200) {
            return _processListData(result);
        } else {
            logger.error('品牌页数据返回 code 不是 200');
            return {};
        }
    });
};

const getListData = () => {
    return Promise.all([_getResources(), _getBreakingSort()])
    .then((result) => {

        return {
            tabs: result[0],
            category: result[1]
        };
    });
};

module.exports = {
    getListData: getListData
};