brand.js 1.33 KB
'use strict';

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

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

    let listData = [];

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

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

        _.forEach(value, function(obj) {
            obj.brandIco = `//img13.static.yhbimg.com/brandLogo/${obj.brandIco}?imageView2/3/w/{width}/h/{height}`;

            if (!_.isNaN(+index)) {
                category.key = '0-9';
                category.brands.push(obj);
            }
        });
        
        if (_.isNaN(+index)) {
            listData.push(
                {
                    key: index,
                    brands: value
                }
            )
        }
        console.log(value)
    });

    listData.push(category);

    return listData;
};

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

module.exports = {
    getListData: getListData
};