list.js 1.94 KB
/*
 * @Author: Targaryen
 * @Date:   2016-06-02 15:11:15
 * @Last Modified by:   Targaryen
 * @Last Modified time: 2016-06-08 14:57:54
 */

'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = new API();
const outletsApi = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const publicHandler = require('./public-handler');

// const headerModel = require('../../../doraemon/models/header');

/**
 * 获取商品列表商品数据 Controller 调用
 * @param  {[type]} params [常规参数]
 * @param  {[type]} extra  [左侧列表额外要拼接的参数]
 * @return {[type]}        [description]
 */
exports.getSaleOthersData = (params, channel) => {

    return api.all([
        // headerModel.requestHeaderData(channel),
        outletsApi.getOutletsGoodsList(Object.assign(params, { channel: channel })),
        outletsApi.getOutletsGoodsList({limit: '1', channel: channel })
    ]).then(result => {
        let finalResult = {};

        // 获取商品数据和顶部筛选条件
        if (result[0].code === 200) {
            finalResult.goods = productProcess.processProductList(result[0].data.product_list);
        }

        // 获取左侧类目数据
        if (result[1].code === 200) {
            finalResult.leftContent = publicHandler.handleSaleSortData(result[1].data.filter.group_sort, params);
            finalResult.filters = publicHandler.handleSaleFilterData(result[1].data.filter, params);
            finalResult.pathNav = publicHandler.handlePathNavData(result[1].data.filter.group_sort, params);

            // 处理排序数据
            finalResult.opts = publicHandler.handleSaleOptsData(params, result[1].data.total);
            finalResult.totalCount = result[1].data.total;
            finalResult.pager = publicHandler.handleSalePagerData(result[1].data.total, params);
        }

        return finalResult;
    });
};