currency.page.js 1.58 KB
/**
 * [个人中心]YOHO币
 * @author: jiangmin
 * @date: 2016/07/11
 */
const moment = require('moment');

// 时间格式化
const convertUnitTime = (src) => {

    return moment.unix(src).format('YYYY-MM-DD');
};

var beginTime = convertUnitTime(new Date() / 1000 - 3600 * 24 * 90);
var type = 0;
var page = 1;
var Bll = {
    // 获取路由中的请求参数
    getQueryString: function() {
        var queryArr = location.search.substr(1).split('&');
        var query = {};

        queryArr.forEach(function(pair) {
            var arr = pair.split('=');

            query[arr[0]] = arr[1];
        });
        return query;
    },
    typeMap: {
        all: 0,
        paying: 1,
        delivering: 2
    },
    getDataList: function(type1, page1, beginTime1) {
        var query = ['page=' + page1, 'queryType=' + type1, 'beginTime=' + beginTime1];

        location.search = query.join('&');
    }
};

require('./me');


// tab切换
$('.tabs li').on('click', function() {
    var $this = $(this);

    type = Bll.typeMap[$this.data('type')];
    page = 1;
    beginTime = Bll.getQueryString().beginTime || beginTime;

    if (!$this.hasClass('active')) {
        $('.tabs li.active').removeClass('active');
        $this.addClass('active');
        Bll.getDataList(type, page, beginTime);
    }

});

// 时间控件切换
$('#begin-time').on('change', function() {
    var months = parseInt($(this).val(), 10);

    type = Bll.getQueryString().queryType || 1;
    page = 1;
    beginTime = convertUnitTime(new Date() / 1000 - 3600 * 24 * 30 * months);
    Bll.getDataList(type, page, beginTime);
});