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

'use strict';

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

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

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

    data.module = 'product';
    data.page = 'outlets';
    data.footerTop = true;
    data.devEnv = true;

    data.banner = [
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        },
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        },
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        }
    ];

    data.column = [
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        },
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        },
        {
            href: '#',
            img: 'http://img10.static.yhbimg.com/yhb-img01/2016/05/25/09/01ee927cf2bec307e50dbc437141665090.jpg?imageView2/1/w/{width}/h/{height}'
        }
    ];

    data.limitedBuy = {
        name: '限时嗨购',
        topic: [
            {
                href: '#',
                img: 'http://img11.static.yhbimg.com/yhb-img01/2016/05/25/11/01d71a4867ac110b1894504da65b5cf596.jpg?imageView2/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            },
            {
                href: '#',
                img: 'http://img11.static.yhbimg.com/yhb-img01/2016/05/25/11/01d71a4867ac110b1894504da65b5cf596.jpg?imageView2/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            },
            {
                href: '#',
                img: 'http://img11.static.yhbimg.com/yhb-img01/2016/05/25/11/01d71a4867ac110b1894504da65b5cf596.jpg?imageView2/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            }
        ],
        extra: {
            sourceImg: {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/13/01/023d062b8384103df7a8dfada98afaf204.jpg?imageView2/1/w/{width}/h/{height}'
            },
            hotType: {
                title: '热销推荐',
                classify: [
                    {
                        href: '#',
                        name: '上衣'
                    },
                    {
                        href: '#',
                        name: 'T恤'
                    },
                    {
                        href: '#',
                        name: '裤子'
                    }
                ]
            },
            trendGood: {
                title: '潮品推荐',
                goods: [
                    {
                        href: '#',
                        img: 'http://img13.static.yhbimg.com/goodsimg/2015/08/04/10/02129fcc058455de1615ce770d3a4555a6.jpg?imageView/1/w/{width}/h/{height}',
                        name: 'Life·After Life 像素风sneaker印花长袖衬衫',
                        market: '¥260',
                        sale: '¥203',
                        discount: '2'
                    },
                    {
                        href: '#',
                        img: 'http://img13.static.yhbimg.com/goodsimg/2015/08/04/10/02129fcc058455de1615ce770d3a4555a6.jpg?imageView/1/w/{width}/h/{height}',
                        name: 'Life·After Life 像素风sneaker印花长袖衬衫',
                        market: '¥260',
                        sale: '¥203',
                        discount: '2'
                    },
                    {
                        href: '#',
                        img: 'http://img13.static.yhbimg.com/goodsimg/2015/08/04/10/02129fcc058455de1615ce770d3a4555a6.jpg?imageView/1/w/{width}/h/{height}',
                        name: 'Life·After Life 像素风sneaker印花长袖衬衫',
                        market: '¥260',
                        sale: '¥203',
                        discount: '2'
                    },
                    {
                        href: '#',
                        img: 'http://img13.static.yhbimg.com/goodsimg/2015/08/04/10/02129fcc058455de1615ce770d3a4555a6.jpg?imageView/1/w/{width}/h/{height}',
                        name: 'Life·After Life 像素风sneaker印花长袖衬衫',
                        market: '¥260',
                        sale: '¥203',
                        discount: '2'
                    }
                ]
            }
        }
    };

    data.nearOver = {
        name: '即将结束',
        topic: [
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            },
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            },
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            },
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                discount: '7.5',
                title: '多元化潮流风格',
                limit: '1500'
            }
        ]
    };

    data.goodsBoard = {
        goodsMenu: {
            title: '最新折扣',
            menuList: [
                {
                    name: 'T恤',
                    href: '#',
                    cur: true
                },
                {
                    name: '衬衫',
                    href: '#'
                },
                {
                    name: '休闲裤',
                    href: '#'
                },
                {
                    name: '连衣裙',
                    href: '#'
                }
            ],
            more: '#'
        },
        sort: {
            sortType: [
                {
                    name: '最新',
                    active: true,
                    href: '',
                    hasSortOrient: true
                }
            ]
        },
        list: [
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                price: '¥340',
                discount: '7.5',
                title: '多元化潮流风格'
            },
            {
                href: '#',
                img: 'http://img12.static.yhbimg.com/yhb-img01/2016/02/05/08/02bb2c8efb12319cf50f247bae13d60dde.jpg?imageView/1/w/{width}/h/{height}',
                logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
                price: '¥340',
                discount: '7.5',
                title: '多元化潮流风格'
            }
        ]
    };
    res.render('outlets/index', data);
};

/**
 * 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 = {
        list: [
            {
                href: '#',
                img: 'http://img10.static.yhbimg.com/brandBanner/2014/11/24/07/01ff74fb2a33764c2fd18b3c8a60f5beef.jpg'
            },
            {
                href: '#',
                img: 'http://img10.static.yhbimg.com/brandBanner/2014/11/24/07/01ff74fb2a33764c2fd18b3c8a60f5beef.jpg'
            },
            {
                href: '#',
                img: 'http://img10.static.yhbimg.com/brandBanner/2014/11/24/07/01ff74fb2a33764c2fd18b3c8a60f5beef.jpg'
            }
        ],
        href: '#',
        img: '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: '20000'
    };

    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 => {
        //     res.render('outlets/special', resData);
        // });

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