outlets.js 4.19 KB
/**
 * 商品促销controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/5/19
 */

'use strict';
const mRoot = '../models';

// const simuOutlets = require(`${mRoot}/simu-outlets`);
const headerModel = require('../../../doraemon/models/header');

// 开发用模拟数据
// const outletsSimulation = require('../models/simulation');

// sale 页 model
const outlets = require(`${mRoot}/outlets`);

/**
 * outlets 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res) => {
    let responseData = {};

    // 首页模拟数据
    // responseData.result = simuOutlets.index();
    headerModel.requestHeaderData().then(headerData => {
        responseData = headerModel.setHeaderData(headerData.data, 'sale');
        responseData.module = 'product';
        responseData.page = 'outlets';
        responseData.footerTop = true;
        responseData.devEnv = true;

        outlets.getOutletsIndexData(req.query).then(result => {
            responseData.result = result;
            responseData.resultShow = JSON.stringify(result, null, 4);
            res.render('outlets/index', responseData);
        });
    });

};

/**
 * outlets 频道页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.channel = (req, res) => {

    let channel = {
        boys: 'true',
        girls: 'true',
        kids: 'true',
        lifestyle: ''
    };

    let response = {};

    // 错误页面
    if (!channel[req.params.channel]) {
        response.pageErr = true;
    }

    // 头部数据
    headerModel.requestHeaderData().then(headerData => {
        Object.assign(response, headerModel.setHeaderData(headerData.data, 'outlets'));

        // 频道数据
        outlets.getOutletsChannelData({ channel: req.params.channel }).then(outletsData => {
            response.module = 'product';
            response.page = 'outlets';
            response.devEnv = true;

            // 输出数据
            Object.assign(response, outletsData);
            res.render('outlets/channel', response);
        });

        // 假数据
        // response.module = 'product';
        // response.page = 'outlets';
        // response.footerTop = true;
        // response.devEnv = true;
        // res.render('outlets/channel', Object.assign(response, outletsSimulation.outletBanner()));
    });

    // outlets.getOutletsChannelData({channel:req.params.channel}).then(outletsData => {
    //     response.module = 'product';
    //     response.page = 'sale';
    //     response.footerTop = true;
    //     response.devEnv = true;
    //     res.render('outlets/channel', Object.assing(response, outlets.outletBanner()));
    // });
    // 输出数据
    // res.render('outlets/channel', Object.assign(response,
    // outlets.getOutletsChannelData({'channel':req.params.channel})));
};

/**
 * outlets 活动
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.special = (req, res) => {
    let params = req.query;

    let resData = {
        module: 'product',
        page: 'outlets',
        devEnv: true
    };

    resData.mainBanner = {
        url: '#',
        src: 'http://img10.static.yhbimg.com/brandBanner/2014/11/24/07/01ff74fb2a33764c2fd18b3c8a60f5beef.jpg'
    };

    resData.specialHead = {
        logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
        special: '精品上装专场',
        discount: '8',
        title: '全部商品',
        count: '123533',
        limit: '80000000'
    };

    headerModel.requestHeaderData().then(headerData => {

        resData = Object.assign(resData, headerModel.setHeaderData(headerData.data, 'outlets'));

        if (!params.id) {
            resData.pageErr = true;
        }

        // res.render('outlets/special', resData);

        outlets.getOutletsSpecialData(params).then(result => {
            resData.specialHead = result.specialHead;
            res.render('outlets/special', resData);
        });

    }).catch(() => {
        resData.pageErr = true;
        res.render('error', resData);
    });
};