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() {
        let queryArr = location.search.substr(1).split('&');
        let query = {};

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

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

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

require('./me');


// tab切换
$('.tabs li').on('click', function() {
    let $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() {
    let 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);
});