outlet.js 2.02 KB
/**
 * 频道页面
 * @author: Bi Kai<kai.bi@yoho.cn>
 * @date: 2016/05/09
 */
'use strict';

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

const renderData = {
    module: 'product'
};

const yhChannelMap = {
    boys: 1,
    girls: 2,
    kids: 3,
    lifestyle: 4
};

exports.index = (req, res) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';
    let headerData = headerModel.setNavHeader('OUTLET', channel, true, '', null);
    let categoryId = req.query.category_id;
    let yhChannel = req.query.yh_channel || 1;
    let contentcode = req.query.content_code;

    outletModel.getContent(categoryId, yhChannel, contentcode).then(result => {
        res.render('outlet', Object.assign({
            page: 'outlet',
            pageHeader: headerData,
            pageFooter: true
        }, renderData, result));
    });
};

exports.activity = (req, res) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';
    let headerData = headerModel.setNavHeader('OUTLET', channel, true, '', null);

    outletModel.getActivity(req.query.id).then(result => {
        res.render('outlet/activity', Object.assign({
            page: 'outlet-detail',
            pageHeader: headerData,
            pageFooter: true
        }, renderData, result));
    });
};

exports.activityChannel = (req, res) => {
    let channel = req.cookies._Channel || 'boys';
    let headerData = headerModel.setNavHeader('OUTLET', channel, true, '', null);
    let categoryId = req.query.category_id;
    let type = req.query.type || 2;
    let template = type === 2 ? 'outlet/will-end' : 'outlet/will-start';
    let page = type === 2 ? 'outlet-will-end' : 'outlet-will-start';
    let yhChannel = yhChannelMap[channel];

    outletModel.getNearlyActivity(yhChannel, type, categoryId).then(result => {
        res.render(template, Object.assign({
            page: page,
            pageHeader: headerData,
            pageFooter: true
        }, renderData, result));
    });
};