brand-list.js 3.08 KB
/**
 * blk品牌品类
 * @author: xiaoru.zhang
 * @date: 2017/02/07
 */

'use strict';

const mRoot = '../models';
const brandModel = require(`${mRoot}/brand-list`);
const headerModel = require('../../../doraemon/models/header'); // 头部model

let channels = {
    boys: 1,
    girls: 2,
    lifestyle: 4
};

const index = (req, res, next) => {
    let categoryTab = req.query.tab || '';
    let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
    let brandCode;
    let cateCode;
    let isCate = categoryTab === 'category' ? true : false;

    if (parseInt(gender, 10) === 1) {
        brandCode = '7317a4701a1d3ddc8d93a5df77a63b75';
        cateCode = '7f885e9cab53231cff34ea236f3f1120';
    } else {
        brandCode = '84313c4b293a1c0aea985aa16a42a6b5';
        cateCode = 'a6f9dc00219eb7d08520a18864929a30';
    }

    brandModel.indexData(gender, brandCode, cateCode).then(result => {

        res.render('brand/brand', {
            module: 'guang',
            page: 'brand-list',
            width750: true,
            categoryTab: isCate,
            channel: result.channel ? result.channel : '',
            brandList: result.brandList,
            list: result.list ? result.list : '',
            categoryData: result.categoryData
        });
    }).catch(next);
};

const brandList = (req, res, next) => {
    let code;
    let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;

    if (parseInt(gender, 10) === 1) {
        code = '7317a4701a1d3ddc8d93a5df77a63b75';
    } else {
        code = '84313c4b293a1c0aea985aa16a42a6b5';
    }

    brandModel.brandListData(code, gender).then(result => {
        res.render('brand/brand-list', {
            layout: false,
            brandList: result.brandList
        });
    }).catch(next);
};

const categoryData = (req, res, next) => {
    let code;
    let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;

    if (parseInt(gender, 10) === 1) {
        code = '7f885e9cab53231cff34ea236f3f1120';
    } else {
        code = 'a6f9dc00219eb7d08520a18864929a30';
    }

    brandModel.categoryData(code).then(result => {
        res.render('brand/category', {
            layout: false,
            categoryData: result.categoryData
        });
    }).catch(next);
};

// 全部分类
const cateAll = (req, res, next) => {
    let appType = req.query.app_type || 1;

    brandModel.getCateData(req.yoho.channel, appType).then((result) => {
        res.render('brand/cate-all', {
            module: 'guang',
            page: 'cate-all',
            title: '全部分类',
            pageHeader: headerModel.setNav({
                navTitle: '全部分类'
            }),
            pageFooter: false,
            category: {
                nav: result.nav,
                list: result.list
                // searchUrl: helpers.urlFormat('/search', null, 'search')
            }
            // showFooterTab: footerModel.getUrlData('category')
        });
    }).catch(next);
};

module.exports = {
    index,
    brandList,
    categoryData,
    cateAll
};