/*全局自适应高度*/
function autoFlashHeight(){
    var cHeader = $(".c-header").height();
    var toptitle = $(".top-title").height();
    var bottomtitle = $(".bottom-title").height();
    var sjsbottom = $(".sjs-bottom-2").height();
    $(".sjs-height-1").height($(window).height()-cHeader-160);
    $(".sjs-height-3").height($(window).height()-cHeader-toptitle-bottomtitle-sjsbottom-192);
};
$(window).resize(autoFlashHeight);
/*全局自适应高度结束*/
$(function(){
    /*侧滑*/
    $(".open-sidebar").click(function(){
        $(".slide-sidebar").animate({width:"800"}).addClass("open");
    });
    $("body").click(function(event){
        var e = event || window.event; //浏览器兼容性
        if(!$(event.target).is('a')) {
            var elem = event.target || e.srcElement;
            while (elem) { //循环判断至跟节点，防止点击的是div子元素
                if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
                    return false;
                }
                elem = elem.parentNode;
            }
            $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
        }

    });
    /*侧滑*/
    /*工具提示*/
    $(function () {
        $('[data-toggle="tooltip"]').tooltip();
        $('[data-toggle="popover"]').popover()
    });
    /*侧栏菜单*/
    $(".bg-nav > li > a").click(function() {
        var self = $(this);
        var subMenu = $(this).siblings('ul.sub-menu');
        if(subMenu.length > 0) {
            if(subMenu.is(":visible")) {
                self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
                subMenu.slideUp('fast');
                self.parent().removeClass('active');
            }else{
                self.parent().addClass('active');
                self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
                subMenu.slideDown('fast');
            }
        }
    });
});

/**
 * 动态请求数据
 * @param {String} url - 请求链接
 * @param data - 提交数据
 * @param {function} successCallback - 返回成功回调
 * @param {function} errorCallBack - 返回失败回调
 */
const postData = function (url, data, successCallback, errorCallBack) {
    $.ajax({
        type:"POST",
        url: url,
        data: {'data': JSON.stringify(data)},
        dataType: 'json',
        cache: false,
        timeout: 5000,
        beforeSend: function(xhr) {
            let csrfToken = Cookies.get('csrfToken');
            xhr.setRequestHeader('x-csrf-token', csrfToken);
        },
        success: function(result){
            if (result.err === 0) {
                if (successCallback) {
                    successCallback(result.data);
                }
            } else {
                if (errorCallBack) {
                    errorCallBack(result.data);
                }
            }
        },
        error: function(jqXHR, textStatus, errorThrown){
            if (errorCallBack) {
                errorCallBack();
            }
        }
    });
};

GetUrlQueryString = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    return r ?  unescape(r[2]) : null;
}
