currency.page.js 1.66 KB
/**
 * [个人中心]有货币
 * @author: jiangmin
 * @date: 2016/07/11
 */

var type = 0;
var page = 1;
var Bll = {
    // 获取路由中的请求参数
    getQueryString: function() {
        var queryArr = location.search.substr(1).split('&');
        var query = {};
        var i;
        var arr = [];

        for (i = 0; i < queryArr.length; i++) {
            arr = queryArr[i].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('&');
    },
    getTime: function(time, a) {
        var newDate = new Date(time.getFullYear(), time.getMonth() + 1, time.getDate() - 30 * a);

        return newDate.getFullYear() + '-' + newDate.getMonth() + '-' + newDate.getDate();
    }
};
var beginTime = Bll.getTime(new Date(), 3);

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 = Bll.getTime(new Date(), months);
    Bll.getDataList(type, page, beginTime);
});