// 管理首页脚本
/*====================================
 *基于JQuery 1.10.2以上主框架
 *WJDH管理界面
 *作者：WJDH.DT
====================================*/
$.ajax({
    type: "post",
    url: "../api/user.ashx?action=get_navigation_list&time=" + Math.random(),
    //url: "../api/admin_ajax.aspx",
    dataType: "html",
    success: function(data, textStatus) {
        initMenuTop(data);
        initMenuLeft(data);
        initMenuList(data);
        silder();
        common();
    }
});

//初始化快捷导航
function initMenuList(data) {
    $('.list-content').html(data);
};

function initMenuLeft(data) {
    $('.menu-left-list').html(data);
};

function initMenuTop(data) {
    //var a = $(data).find('h1').attr('title');
    $(data).find('h1').each(function(index, el) {
        var that = $(this);
        var title = that.attr('title');
        var id = that.attr('navid');
        $('#nav').append('<li class="nav' + id + '"><i></i><span>' + title + '</span></li>');
    });
    $('#nav').children('li:eq(0)').addClass('active');
}

function silder1() {


	//左侧栏目显示
    $('.menu-left-list').find('.list-group').eq(0).show().siblings().hide();
    $('.list-wrap > ul > li:first-child > ul').show();
    $('.list-wrap > ul > li:first-child > a').addClass('active');
    $('.list-wrap > ul > li > a').each(function(index, el) {
        var that = $(this);
        if (that.attr('href') != undefined) {
            that.append('<i class="menu-file"></i>')
        } else {
            that.append('<i class="menu-folder"></i><div class="more"></div>')
        }
    });

	//导航切换左侧栏目
    $('#nav li').on('click', function() {
        var that = $(this);
        $('#nav li').removeClass('active');
        that.addClass('active');
        var num = that.index();
        $('.menu-left-list').find('.list-group').eq(num).show().siblings().hide();
        $('body').removeClass('shrink');
    });

    //左侧栏目手风琴
    $('.list-wrap > ul > li > a').on("click", function() {
        var that = $(this);
        var attrClass = that.attr('class');
        if (attrClass == 'active') {
            that.next('ul').fadeToggle();
            //that.removeClass('active');
        } else {
            that.addClass('active');
            that.next('ul').fadeIn();
            that.parent().siblings().children('ul').fadeOut();
            that.parent().siblings().children('a').removeClass('active');
        }
    });


}
function silder() {
	

	//左侧栏目显示
    $('.menu-left-list').find('.list-group').eq(0).show().siblings().hide();
    $('.list-wrap > ul > li:first-child > ul').show();
    $('.list-wrap > ul > li:first-child > a').addClass('active');
    $('.list-wrap > ul > li > a').each(function(index, el) {
        var that = $(this);
        if (that.attr('href') != undefined) {
            that.append('<i class="menu-file"></i>')
        } else {
            that.append('<i class="menu-folder"></i><div class="more"></div>')
        }
    });

	//导航切换左侧栏目
    $('#nav li').on('click', function() {
        var that = $(this);
        $('#nav li').removeClass('active');
        that.addClass('active');
        var num = that.index();
        $('.menu-left-list').find('.list-group').eq(num).show().siblings().hide();
        $('body').removeClass('shrink');
    });

    //左侧栏目手风琴
	$( ".menu-left-list .list-group ul" ).accordion({
		closedSign: '',
		openedSign: ''
	}); 
}

$(function() {
    $('.menu-btn').on('click', function() {
        $('.menu-list').fadeToggle();
    });
    $('.menu-list').on('click', function() {
        $('.menu-list').fadeOut();
    });
    $('.btn-paograms').on('click', function() {
        $('.indexbody').toggleClass('shrink');
    });
	$('.menu-cache').on("click", function () {
		var stat = $(this).attr('disabled');
		if(stat!='disabled'){
			$(this).attr('disabled','disabled');
			update_cache('/api/cache.ashx?action=cachecontent','','.menu-cache');
		}
	});
	$('.menu-mcache').on("click", function () {
		var stat = $(this).attr('disabled');
		if(stat!='disabled'){
			$(this).attr('disabled','disabled');
			update_cache('/api/cache.ashx?action=cachetpl' ,'','.menu-mcache');
		}
    });
    $('.menu-ui').on("click", function () {
        location.href = 'data_visualization/index.aspx';
    });
	$("#refresh").click(function() {
		 var iframek=document.getElementById("iframe").src;
		 console.log(iframek);
              //  self.location.reload();
			  
		var _iframe1=document.getElementById('iframe');
            _iframe1.contentWindow.location.reload(true);
            });
	$(".km").click(function() {
		 var murl=$("#km").val();
		$('#iframe').attr('src',murl);
		$('#kframe').addClass("mo");
	    $('.km').addClass('red');
		$('.kpc').removeClass('red').addClass('pcm');

              //  self.location.reload();

            });
	$(".kpc").click(function() {
		// var murl=$("#km").val();
		$('#iframe').attr('src','/?a=ui');
		$('#kframe').removeClass("mo");
		$('.kpc').addClass('red');
		$('.km').removeClass('red').addClass('pcm');
              //  self.location.reload();

            });
	$('.nav-user').hover(function(){
		t = setTimeout(function(that){
			//要执行的操作；鼠标放上去后200毫秒才执行
			$('.nav-user .popover').fadeIn('100');
			},
		200);
	},
	function(){
		//鼠标移除后清除上面的操作；
		clearTimeout(t);
		$('.nav-user .popover').fadeOut('0');
	})
});
function common(){
	$(function() {
		var content = $('.nav-right').clone();
		var wdith = $(document).width();
		var navLiWidth = $('#nav li').outerWidth();
		$('#nav').width(navLiWidth*10);
		mobile(wdith);
		$(window).resize(function(event) {
			wdith = $(document).width();
			mobile(wdith);
		});
		function mobile(wdith){
			if(wdith<768){
				$('body').addClass('shrink');
				navLiWidth = $('#nav li').outerWidth();
				$('#nav').width(navLiWidth*10);
				$('.list-group a').on('click',function(){
					$('body').addClass('shrink')
				})
			}else{
				$('body').removeClass('shrink');
			}
		};
	})
};

function update_cache(url,content,btn) { //参数：提交地址，form表单内容（json格式）,提交完成之前禁用的按钮
	if(btn==undefined){
		var that = $('#submit');
	}else{
		var that = $(btn);
	}
    that.attr('disabled', 'disabled');
    var waiting = layer.load(0, { shade: false });
    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'JSON',
        timeout: 60000,
        data: content,
        success: function(data) {
            layer.close(waiting);
            layer.msg(data.msg, { time: 1000 });
            that.removeAttr("disabled");
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            if (textStatus == "timeout") {
                layer.close(waiting);
                layer.msg('超时，请重新提交', { time: 3000 });
                that.removeAttr("disabled");
            } else {
                layer.close(waiting);
                layer.msg('提交失败，请重新提交！错误代码：' + textStatus, { time: 3000 });
                that.removeAttr("disabled");
            }
        }
    })
};
function Getinfo(id,url){
		$.ajax({
			url:url,
			type: "get",
			dataType: "json",
			success:function(data){
				if(data.status == 1){
					$("#info1").html(data.info1),
					$("#info2").html(data.info2),
					$("#info3").html(data.info3),
					$("#info4").html(data.info4);
				}
				else{
					console.log(data.info);
					$('#'+id).html(0);
				}
			},
			error:function() {
				var html="<span class=\"unusual\"></span><a class=\"fcolorb\" onclick=AjaxGetValue('"+id+"','"+url+"')>重试</a>";
				$('#'+id).html(html);
			}
		})
};
function Getpaiming(id,url){
		$.ajax({
			url:url,
			type: "get",
			dataType: "json",
			success:function(data){
				if(data.allnum == 1){
					$(".MsoNormalTable").html(data.info);
				}
				else{
					console.log(data.info);
					$('#'+id).html(0);
				}
			},
			error:function() {
				var html="<span class=\"unusual\"></span><a class=\"fcolorb\" onclick=AjaxGetValue('"+id+"','"+url+"')>重试</a>";
				$('#'+id).html(html);
			}
		})
};
function Gettongji(id,url){
	
		$.ajax({
			url:url,
			type: "get",
			dataType: "json",
			success:function(data){
				//alert(data.status);
				if(data.status == 1){

					$("#lm_num").html(data.ip),
					$("#yellowsite_history").html(data.pv);
				}
				else{
					console.log(data.info);
					$('#'+id).html(0);
				}
			},
			error:function() {
				var html="<span class=\"unusual\"></span><a class=\"fcolorb\" onclick=AjaxGetValue('"+id+"','"+url+"')>重试</a>";
				$('#'+id).html(html);
			}
		})
};
function Getcount(id,url){
		$.ajax({
			url:url,
			type: "get",
			dataType: "json",
			success:function(data){
				//alert(data.status);
				if(data.code == 1){

					$(".nav-remind").html("<a href=module/message/list.aspx target=mainframe><i>"+data.data+"</i></a>");
					
				}
				else{
					console.log(data.info);
					$(".nav-remind").html("a href=module/message/list.aspx target=mainframe><i>0</i></a>");
				}
			},
			error:function() {
				var html="";
				$('#'+id).html(html);
			}
		})
};
function formatDate(datek) {
	var date1=new Date(datek);
    var myyear = date1.getFullYear();
    var mymonth = date1.getMonth() + 1;
    var myweekday = date1.getDate();
 
    if (mymonth < 10) {
        mymonth = "0" + mymonth;
    }
    if (myweekday < 10) {
        myweekday = "0" + myweekday;
    }
    return (myyear + "-" + mymonth + "-" + myweekday);
};
