list.js 1.75 KB
/*
 * @Author: sefon
 * @Date:   2016-07-24 11:40:21
 */

'use strict';
const mRoot = '../models';
const list = require(`${mRoot}/list`);

/**
 * 商品分类列表页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res, next) => {
    let resData = {};

    list.getListData(req.query).then(result => {
        Object.assign(resData, result);
        res.render('list/index', resData);
    }).catch(next);

};

/**
 * 新品到着
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.new = (req, res, next) => {
    let resData = {};

    list.getListNewData(req.query).then(result => {
        Object.assign(resData, result);
        res.render('list/index', resData);
    }).catch(next);

};

/**
 * 品牌页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.brand = (req, res, next) => {
    let resData = {},
        brandDomain = req.brandDomain || 'vans';

    // 获取品牌信息
    list.getBrandInfo({domain: brandDomain}).then(brandInfo => {
        return list.getBrandData(req.query, Object.assign({uid: req.user.id}, brandInfo));
    }).then(result => {
        Object.assign(resData, result);
        res.render('list/brand', resData);
    }).catch(next);
};

/**
 * ajax调用品牌页左侧水牌
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.getNodeContent = (req, res, next) => {

    if (!req.xhr || !req.body.node) {
        return next();
    }

    list.getNodeContentData(req.body).then(result => {
        res.json(result);
    }).catch(next);
};