brand.js 1.56 KB
/**
 * Created by PhpStorm.
 * User: Targaryen
 * Date: 2016/7/19
 * Time: 13:51
 */
'use strict';

const brandApi = require('./brand-api');
const _ = require('lodash');
const camelCase = global.yoho.camelCase;

/**
 * 处理品牌一览品牌列表数据
 * @param origin
 * @returns {Array}
 */
const handleBrandList = origin => {
    let dest = {
        brandList: [],
        indexList: []
    };

    _.sortBy(origin, (o) => {
        return o.key;
    });

    _.forEach(origin, (value, key) => {
        let brands = [];

        _.forEach(value, (subValue) => {
            brands.push({
                name: subValue.brand_name,
                logo: subValue.brand_ico,
                domain: subValue.brand_domain
            });
        });

        dest.brandList.push({
            index: key,
            brands: brands
        });

        dest.indexList.push({
            index: key,
            name: key === '0~9' ? '0' : key
        });
    });

    return dest;
};

/**
 * 获取品牌列表页数据
 * @param params
 */
const getBrandListData = params => {
    let finalResult = {};

    return brandApi.getBrandListOriginData(params).then(result => {
        if (result && result.data) {
            Object.assign(finalResult, handleBrandList(result.data.all_list));
        }

        return finalResult;
    });
};

/**
 * 获取全部分类数据
 * @param params
 * @returns {*|Promise.<TResult>}
 */
const getCateListData = params => {
    return brandApi.getCateListData(params).then(camelCase);
};

module.exports = {
    getBrandListData,
    getCateListData
};