brand.js 2.31 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);
    console.log(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);

    console.log(list);

    // let artList = list.list.artList.map(data =>{
    //     data.publishTime = data.publishTime.replace(/年|月/g, '/');
    //     data.publishTime = data.publishTime.replace(/日/g, '');

    //     return data;
    // });

};

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 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
};