order.js 1.45 KB
/**
 * [个人中心]首页/我的订单
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2016/07/04
 */

'use strict';

const mcHandler = require('../models/menu-crumb-handler');
const orderModel = require('../models/order');

/**
 * 我的订单
 */
const index = (req, res) => {
    const type = req.query.type;
    const page = req.query.page;

    orderModel.getOrderData(type, page).then(result => {
        res.render('index', {
            page: 'order',
            isMe: true,
            content: Object.assign({
                nav: mcHandler.getMeCrumb(),
                navigation: mcHandler.getSideMenu('我的订单'),
                banner: 'http://placehold.it/{width}x{height}'
            }, result)
        });
    });
};

const getOrderList = (req, res) => {
    const type = req.query.type;
    const page = req.query.page;

    orderModel.getOrderData(type, page).then(result => {
        res.render('order-table', {
            layout: false,
            page: 'order',
            isMe: true,
            orderList: result.order.orderList,
            paginationOpts: result.order.paginationOpts
        });
    });
};

const getOrderTotal = (req, res) => {
    const type = req.query.type;

    orderModel.getOrderData(type).then(result => {

        res.json({
            total: result.order.total,
            type: result.order.type
        });
    });
};

module.exports = {
    index: index,
    getOrderList: getOrderList,
    getOrderTotal: getOrderTotal
};