currency.js 2.07 KB
/**
 * [个人中心]yoho币
 * @author: jiangmin
 * @date: 2016/07/11
 */

'use strict';
const mcHandler = require('../models/menu-crumb-handler');

const currencyModel = require('../models/currency');
const moment = require('moment');

const convertUnitTime = (src) => {
    return moment.unix(src).format('YYYY-MM-DD');
};

/**
 * yoho币页面加载
 */
const index = (req, res) => {
    var uid = req.user.uid;
    var page = parseInt(req.query.page, 10) || 1;
    var queryType = parseInt(req.query.queryType, 10) || 0;
    var beginTime = req.query.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90);
    var date1 = new Date().getTime() / 1000;
    var date2 = new Date(beginTime).getTime() / 1000;
    var selectIndex = parseInt((date1 - date2) / (3600 * 24 * 30 * 6), 10);

    currencyModel.getIndexData(uid, page, queryType, beginTime).then(result=> {
        result.list.tabs[queryType].isActive = true;
        result.list.coinList.forEach(function(x) {
            x.date = x.date.replace(/\-/g, '.');
        });
        result.list.selects[selectIndex].isSelected = 'selected';
        if (result.list.paginationOpts) {
            result.list.paginationOpts.queryParams = {
                queryType: queryType,
                beginTime: beginTime
            };
        }

        res.display('index', {
            module: 'me',
            page: 'currency',
            isMe: true,
            content: {
                nav: mcHandler.getMeCrumb('我的YOHO币'),
                navigation: mcHandler.getSideMenu('我的YOHO币'),
                banner: 'http://placehold.it/150x120',
                currency: true,
                tabs: result.list.tabs,
                title: '我的YOHO币',
                currentYear: new Date().getFullYear(),
                data: result.list.coinList,
                paginationOpts: result.list.paginationOpts,
                num: result.num.data,
                selects: result.list.selects,
                total: result.list.total ? result.list.total : 0
            }
        });
    });
};


module.exports = {
    index
};