currency.js 2.18 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) => {
    let uid = req.user.uid || '8041246';
    var page = parseInt(req.query.page) || 1;
    var queryType = parseInt(req.query.queryType) || 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));

    console.log('请求参数:', 'page:' + page, 'queryType:' + queryType, 'beginTime:' + beginTime);
    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
            };
        }
        console.log('返回个数:' + result.list.total);
        res.render('index', {
            module: 'me',
            page: 'currency',
            isMe: true,
            content: {
                nav: mcHandler.getMeCrumb(),
                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
            }
        });
    });
};


module.exports = {
    index
};