$(document).ready(function() {
	if($("#role").val() == "agent"){
		//全部广告主
		$("#advertiser_son_ul").hide();
		$("#advertiser_son_ul").append("<li value='-1'>全部广告主</li>");
		var url = "/ssp_web_back/widget/selector/provide/advertiser?parentId="+$("#agentId").val();
		$.getJSON( url, function(data) {
			var data_1 = data.advertiserList;
			$.each( data_1, function( key, val ) {
				$("#advertiser_son_ul").append('<li class="selectop" value='+ val.value +'>' + val.label + '</li>');
			});
		});
	}else if($("#role").val() == "advertiser"){
		$("#advertiserul_span").html($("#sessionadvertiserName").val());
		$("#advertiserId").val($("#sessionadvertiserId").val());
	}
 	$("#advertiserul_span").live("click",function(){
 		if($("#role").val() == "agent"){
 			$('#advertiser_son_ul').slideDown(); //ul显示
 		}
 	});
 	$('ul#advertiser_son_ul li').live("click",function(){
 		$(this).parents('li').find('span').html($(this).html());
		$("#advertiserId").val($(this).attr("value"));
		$("#advertiserName").val($(this).html());
		$('#advertiser_son_ul').slideUp(); //ul隐藏
		$("#orderul_span").html("全部订单");
		$("#orderId").val(-1);
		$("#orderName").val("全部订单");
		$("#activeul_span").html("全部活动");
		$("#activeId").val(-1);
		$("#activeName").val("全部活动");
		$("#putul_span").html("全部投放");
		$("#putId").val(-1);
		$("#putName").html("全部投放");
	});
	$("#advertiserul_box").mouseleave(function(){
 		$('#advertiser_son_ul').slideUp(); //ul隐藏
 	});
	
	//全部订单
	$("#orderul_son_ul").hide();
 	$("#orderul_span").live("click",function(){
 		$("#orderul_son_ul").empty();
 		$("#orderul_son_ul").append("<li value='-1'>全部订单</li>");
 		if($("#advertiserId").val() != -1 && $("#advertiserId").val() != ""){
	 		var url = "/ssp_web_back/widget/selector/provide/order?parentId=" + $("#advertiserId").val();
	 		$.getJSON( url, function(data) {
				var data_1 = data.orderList;
				$.each( data_1, function( key, val ) {
					$("#orderul_son_ul").append('<li value='+ val.value +'>' + val.label + '</li>');
				});
			});	
 		}
		$('#orderul_son_ul').slideDown(); //ul显示
 	});
 	$('ul#orderul_son_ul li').live("click",function(){
		$(this).parents('li').find('span').html($(this).html());
		$("#orderId").val($(this).attr("value"));
		$("#orderName").val($(this).html());
		$('#orderul_son_ul').slideUp(); //ul隐藏
		$("#activeul_span").html("全部活动");
		$("#activeId").val(-1);
		$("#activeName").val("全部活动");
		$("#putul_span").html("全部投放");
		$("#putId").val(-1);
		$("#putName").html("全部投放");
	});
	$("#orderul_box").mouseleave(function(){
 		$('#orderul_son_ul').slideUp(); //ul隐藏
 	});
	
	//全部活动
	$("#activeul_son_ul").hide();
 	$("#activeul_span").live("click",function(){
 		$("#activeul_son_ul").empty();
 		$("#activeul_son_ul").append("<li value='-1'>全部活动</li>");
 		if($("#orderId").val() != -1 && $("#orderId").val() != ""){
	 		var url = "/ssp_web_back/widget/selector/provide/campaign?parentId=" + $("#orderId").val();
	 		$.getJSON( url, function(data) {
				var data_1 = data[$("#orderId").val()];
				$.each( data_1, function( key, val ) {
					$("#activeul_son_ul").append('<li value='+ val.value +'>' + val.label + '</li>');
				});
			});	
 		}
		$('#activeul_son_ul').slideDown(); //ul显示
 	});
 	$('ul#activeul_son_ul li').live("click",function(){
		$(this).parents('li').find('span').html($(this).html());
		$("#activeId").val($(this).attr("value"));
		$("#activeName").val($(this).html());
		$('#activeul_son_ul').slideUp(); //ul隐藏
		$("#putul_span").html("全部投放");
		$("#putId").val(-1);
		$("#putName").html("全部投放");
	});
	$("#activeul_box").mouseleave(function(){
 		$('#activeul_son_ul').slideUp(); //ul隐藏
 	});
	
	//全部投放
	$("#putul_son_ul").hide();
 	$("#putul_span").live("click",function(){
 		$("#putul_son_ul").empty();
 		$("#putul_son_ul").append("<li value='-1'>全部投放</li>");
 		if($("#activeId").val() != -1 && $("#activeId").val() != ""){
 			var url = "/ssp_web_back/widget/selector/provide/ad-group?parentId=" + $("#activeId").val();
 	 		$.getJSON( url, function(data) {
 				var data_1 = data[$("#activeId").val()];
 				$.each( data_1, function( key, val ) {
 					$("#putul_son_ul").append('<li value='+ val.value +'>' + val.label + '</li>');
 				});
 			});
 		}
		$('#putul_son_ul').slideDown(); //ul显示
 	});
 	$("#dimensionul_span").live("click",function(){
 		$('#dimension_son_ul').slideDown(); //ul显示
 	});
 	$('ul#putul_son_ul li').live("click",function(){
		$(this).parents('li').find('span').html($(this).html());
		$("#putId").val($(this).attr("value"));
		$("#putName").val($(this).html());
		$('#putul_son_ul').slideUp(); //ul隐藏
	});
	$("#putul_box").mouseleave(function(){
 		$('#putul_son_ul').slideUp(); //ul隐藏
 	});
	
	//请选择维度
	$("#dimension_son_ul").hide();
	$("#dimension_son_ul").append("<li value='-1'>请选择维度</li>");
	var url = "/ssp_web_back/main/ad/report/advertiser-report/dimensionlist";
	$.getJSON( url, function(data) {
		$.each( data, function( key, val ) {
			$("#dimension_son_ul").append('<li class="selectop" value='+ val.id +'>' + val.name + '</li>');
		});
	});
	
	$('ul#dimension_son_ul li').live("click",function(){
 		$(this).parents('li').find('span').html($(this).html());
		$("#dimensionId").val($(this).attr("value"));
		$("#dimensionName").val($(this).html());
		$('#dimension_son_ul').slideUp(); //ul隐藏
		$("#formPage").submit();
	});
	
	$("#dimensionul_box").mouseleave(function(){
 		$('#dimension_son_ul').slideUp(); //ul隐藏
 	});
});


