$(function() {
	loadYears("selectYear")
	clickItem(0,"农业总产值")
	$("#datetime").html(formatDate())
	var t2 = window.setInterval(function() {
		$("#timeinfo").html(formaterTime())
	},1000)
	$.ajax({
		type:"Post",
		url:"../tianqi/returnTianqiInfo.do",
		dataType:"json",
		success:function(data){
			$("#wendu").html(data.list[0].type+":"+data.list[0].low+"~"+data.list[0].high)
			$("#fl").html(data.list[0].fengxiang)
		}
	});	
})

var nowNum = 0;

function selectYear(){
	enterFlag =0;
	clickItem(nowNum,"农业总产值")
}

var enterFlag =0;
var tableName="";
var dataListInfo = [];
function clickItem(num,name,flag){
	console.log(num)
	nowNum = num ;
	$('.itemButton').each(function(){
		$(this).removeClass("clickButton")
	})
	switch (num) {
	    case 0:
	    	dataListInfo = nongyeshenchanzongzhi;
	    	tableName = "ncjj_zcz";
	        break;
	    case 1:
	    	dataListInfo = shengchanzhongjianxiaohao;
	    	tableName = "ncjj_xh";
	        break;
	    case 2:
	    	dataListInfo = nongyezengjiazhi;
	    	tableName = "ncjj_zjz";
	        break;
	    case 3:
	    	dataListInfo = nongcunjuminshouruyuzhichu;
	    	tableName = "ncjj_inout";
	        break;
	    case 4:
	    	dataListInfo = nongchanpinjinchukoumaoyi;
	    	tableName = "ncjj_jck";
	        break;
	    case 5:
	    	dataListInfo = huizongcunjilianheshe;
	    	tableName = "ncjj_lhs";
	        break;
	    case 6:
	    	dataListInfo = jitijingjishouyi;
	    	tableName = "ncjj_sy";
	    	break;
	    case 7:
	    	dataListInfo = huizongnongminshu;
	    	tableName = "ncjj_nhs";
	    	break;
	    case 8:
	    	dataListInfo = nongyejixienianmoyongyouliang;
	    	tableName = "nyzb_njzl";
	    	break;
	    case 9:
	    	dataListInfo = yongdianyunongyehuaxuehua;
	    	tableName = "nyzb_ydhxh";
	    	break;
	    case 10:
	    	dataListInfo = nongjishehuihuazuzhujirenyuan;
	    	tableName = "nyzb_user";
	    	break;
	    case 11:
	    	dataListInfo = nongyejixiezuoyeqingkuang;
	    	tableName = "nyzb_zyqk";
	    	break;
	    case 12:
	    	dataListInfo = zhuanyejishuxiehui;
	    	tableName = "nckj_zyjs";
	    	break;
	    case 13:
	    	dataListInfo = kepushifanjidi;
	    	tableName = "nckj_sfjd";
	    	break;
	    case 14:
	    	dataListInfo = kemushifanqu;
	    	tableName = "nckj_sfq";
	    	break;
	    case 15:
	    	dataListInfo = kepushifanhu;
	    	tableName = "nckj_sfh";
	    	break;
	    case 16:
	    	dataListInfo = liangshizuowutongji;
	    	tableName = "zzy_lszw";
	    	break;
	    case 17:
	    	dataListInfo = shucaileitongji;
	    	tableName = "zzy_scl";
	    	break;
	    case 18:
	    	dataListInfo = shuiguoleitongji;
	    	tableName = "zzy_sg";
	    	break;
	    case 19:
	    	dataListInfo = zhuyaojingjizuowu;
	    	tableName = "zzy_jjzw";
	    	break;
	    case 20:
	    	dataListInfo = zuowuzaihaitongji;
	    	tableName = "zzy_zwzh";
	    	break;
	    case 21:
	    	dataListInfo = gengdimianji;
	    	tableName = "zzy_gdmj";
	    	break;
	    case 22:
	    	dataListInfo = zhuyaonongchanpinrenjunzhanyouliang;
	    	tableName = "zzy_ncpzy";
	    	break;
	    case 23:
	    	dataListInfo = nianmocunlanliang;
	    	tableName = "xmy_nmcl";
	    	break;
	    case 24:
	    	dataListInfo = dangnianchulanliang;
	    	tableName = "xmy_dncl";
	    	break;
	    case 25:
	    	dataListInfo = chanpinchanliang;
	    	tableName = "xmy_cpcl";
	    	break;
	    case 26:
	    	dataListInfo = xumusiliao;
	    	tableName = "xmy_sl";
	    	break;
	    case 27:
	    	dataListInfo = haishuiyangzhiyubuliao;
	    	tableName = "yyzb_hsyzbl";
	    	break;
	    case 28:
	    	dataListInfo = danshuiyangzhiyubuliao;
	    	tableName = "yyzb_dsyzbl";
	    	break;
	    case 29:
	    	dataListInfo = shuichanjiagong;
	    	tableName = "yy_scjg";
	    	break;	
	    case 30:
	    	dataListInfo = yuyecongyerenyuan;
	    	tableName = "yy_user";
	    		
	} 
	$("#echart1").html(name);
	$("#echart2").html(name);
	var str = '';
	var stt = ' <div class="box-title" style="color: #aedceb;">'+name+'</div>';
	stt += '<div class="box-content">'
	if(flag!=null){
		if(num=="4"){
			stt+= '<div class="radio">'
			stt+= '   <input type="radio" class="radio_type" name="type" id="radio-1" checked  >'
			stt+= '    <label for="radio-1" class="radio-label" onclick="maoyiitem(0,\'inzj\')">进口</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-2" style="margin-left: 20%;" onclick="maoyiitem(1,\'outzj\')">'
			stt+= '    <label for="radio-2" class="radio-label" onclick="maoyiitem(1,\'outzj\')">出口</label>'
			stt+= '</div>'
		}else if(num=="16"){
			stt+= '<div class="radio">'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-1" checked onclick="maoyiitem(0,\'bzzmj\')">'
			stt+= '    <label for="radio-1" class="radio-label" onclick="maoyiitem(0,\'bzzmj\')">播种面积</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-2" style="margin-left: 5%;" onclick="maoyiitem(1,\'zmc\')">'
			stt+= '    <label for="radio-2" class="radio-label" onclick="maoyiitem(1,\'zmc\')">亩产</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-3" style="margin-left: 5%;" onclick="maoyiitem(2,\'zcl\')">'
			stt+= '    <label for="radio-3" class="radio-label" onclick="maoyiitem(2,\'zcl\')">总产量</label>'	
			stt+= '</div>'
		}else if(num=="17"||num=="18"||num=="19"){
			stt+= '<div class="radio">'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-1" checked onclick="maoyiitem(0,\'bzzmj\')">'
			stt+= '    <label for="radio-1" class="radio-label" onclick="maoyiitem(0,\'bzzmj\')">播种面积</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-2" style="margin-left: 20%;" onclick="maoyiitem(1,\'zcl\')">'
			stt+= '    <label for="radio-2" class="radio-label" onclick="maoyiitem(1,\'zcl\')">总产量</label>'
			stt+= '</div>'
		}else if(num=="27"||num=="28"){
			stt+= '<div class="radio">'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-1" checked onclick="maoyiitem(0,\'zyz\')">'
			stt+= '    <label for="radio-1" class="radio-label" onclick="maoyiitem(0,\'zyz\')">养殖</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-2" style="margin-left: 10%;" onclick="maoyiitem(1,\'zbl\')">'
			stt+= '    <label for="radio-2" class="radio-label" onclick="maoyiitem(1,\'zbl\')">捕捞</label>'
			stt+= '    <input type="radio" class="radio_type" name="type" id="radio-3" style="margin-left: 10%;" onclick="maoyiitem(2,\'zyzmj\')">'
			stt+= '    <label for="radio-3" class="radio-label" onclick="maoyiitem(2,\'zyzmj\')">面积</label>'	
			stt+= '</div>'
		}
		
	}
	colnumsearch = "";
	stt += ' <div class="button" id="itembutton">'
	var flagnum = num;	
	$.each(dataListInfo,function(i,item){
		if(item.type=="2"){
			colnumsearch += item.id+",";
			str += '<div class="zb">'+item.name+'<span id="sum'+item.id+'"><span id="danwei'+item.id+'">'+item.danwei+'</span></span></div>'
		}
		if(item.type=="1"||item.type=="3"){
			if(flag!=null){
				if(item.other=="0"){
					stt += '<button class="double" id="double'+item.id+'" onclick="getItem(\''+item.id+'\',\''+flagnum+'\')">'+item.name+'</button>'
				}
			}else{
				stt += '<button class="double" id="double'+item.id+'" onclick="getItem(\''+item.id+'\',\''+flagnum+'\')">'+item.name+'</button>'
			}
		}
	})
	stt += '</div>'
	stt += '</div>'
	if(colnumsearch==""){
		colnumsearch = dataListInfo[0].id;
	}
	$("#box-zb").html(str);
	$("#box-right").html(stt);
	if(num==0){
		$("#button0").addClass("clickButton")
	}
	initData()
}
var mapData = [];
var mapdanwei = "";
var colnumsearch = "";

function initData(){
	$.ajax({
		type:"Post",
		url:"../mainshow/getInfo.do",
		data:{ 
			"tableName":tableName,
			"colNumNames":colnumsearch,
			"year":$("#selectYear").val()
		},
		dataType:"json",
		success:function(data){
			$('.itemButton').click(function(){
				$(this).addClass("clickButton")
			})
			var str = '';
			var colnum='';
			var leftDanwei ="{";
			$.each(dataListInfo,function(i,item){
				if(colnum==""&&item.type=="2"){
					colnum = item.id;
					mapdanwei = item.danwei
				}
				if(item.type=="2"){
					leftDanwei+="\""+item.id+"\""+":\""+item.danwei+"\",";
				}
			})
			if(leftDanwei!="{"){
				leftDanwei = leftDanwei.substring(0, leftDanwei.length-1);
			}
			leftDanwei += "}"
			if(colnum==""){
				colnum = dataListInfo[0].id;
				mapdanwei = dataListInfo[0].danwei
			}
			var minNum = 0
			var maxNum = 0;
			$.each(data.list,function(i,item){  
				
				for (var key in item) {
					if(colnum==key){
						var value = item[key]
						if(i==0){
							maxNum = value
						}
						if(i==data.list.length-1){
							minNum = value;
						}
						str +='<input type ="hidden" id="map'+item.orgid+'" value="'+value+'">'
					}
				}
			})
			if(minNum==maxNum){
				minNum = -1
			}
			for(key in data.MapLeftMap){
				$("#sum"+key).html(data.MapLeftMap[key]+"<span>"+JSON.parse(leftDanwei)[key]+"</span>")
			}
			if(data.orgdeptCount!=data.list.length){
				minNum = 0
			}
			$("#tempdiv").html(str);
			drawMap(minNum,maxNum);
			drawChart1(data.orgName,data.orgCount);
			drawChart2(data.years,data.sumCount);
			if(enterFlag=="0"){
				getItem("ny","0")
				enterFlag = "1";;
			}
			if(tableName=="zzy_zwzh"){
				getItem("fs")
			}
			if(tableName=="zzy_ncpzy"){
				getItem("ls")
			}
			if(tableName=="zzy_gdmj"){
				getItem("ncmj")
			}
			if(tableName=="nckj_zyjs"){
				getItem("xhs")
			}
			if(tableName=="nckj_sfjd"){
				getItem("jds")
			}
			if(tableName=="nckj_sfq"){
				getItem("qs")
			}
			if(tableName=="nckj_sfh"){
				getItem("hs")
			}
			if(tableName=="yy_user"){
				getItem("yyx")
			}
			if(tableName=="yy_scjg"){
				getItem("qys")
			}
			if(tableName=="ncjj_inout"){
				getItem("sy")
			}
			if(tableName=="ncjj_lhs"){
				getItem("lhs")
			}
			if(tableName=="ncjj_nhs"){
				getItem("nhs")
			}
			if(tableName=="ncjj_sy"){
				getItem("sr")
			}
			if(tableName=="nyzb_njzl"){
				getItem("gzj")
			}
			if(tableName=="nyzb_user"){
				getItem("jgs")
			}
			if(tableName=="nyzb_zyqk"){
				getItem("jgmj")
			}
		}
	});	
}

function getItem(c,flag){
	$('.double').each(function(i,item){
		$(this).attr("style","")
	})
	$("#double"+c).attr("style","background:#2ea9fb;")
	if(flag=="0"||flag=="1"||flag=="25"||flag=="26"){
		var str = "";
		str += ' <div class="button">'
		$.each(dataListInfo,function(i,item){
			if(item.type=="2"){
				str += '<div class="zb">'+item.name+'<span id="sum'+c+'"><span id="danwei'+c+'">'+item.danwei+'</span></span></div>'
			}
		})
		$("#box-zb").html(str);
	}
	$.ajax({
		type:"Post",
		url:"../mainshow/getInfo.do",
		data:{ 
			"tableName":tableName,
			"colNumNames":c,
			"year":$("#selectYear").val()
		},
		dataType:"json",
		success:function(data){
			var str = '';
			var colnum=c;
			var leftDanwei ="{";
			$.each(dataListInfo,function(i,item){
				if(c=item.id){
					leftDanwei+="\""+item.id+"\""+":\""+item.danwei+"\",";
				}
				if(colnum==item.id){
					mapdanwei = item.danwei
				}
				if(item.type=="2"){
					leftDanwei+="\""+item.id+"\""+":\""+item.danwei+"\",";
				}
			})
			if(leftDanwei!="{"){
				leftDanwei = leftDanwei.substring(0, leftDanwei.length-1);
			}
			var maxNum = 0;
			var minNum = 0;
			leftDanwei += "}"
			$.each(data.list,function(i,item){  
				for (var key in item) {
					if(colnum==key){
						var value = item[key]
						if(i==0){
							maxNum = value
						}
						if(i==data.list.length-1){
							minNum = value;
						}
						str +='<input type ="hidden" id="map'+item.orgid+'" value="'+value+'">'
					}
				}
			})
			if(minNum==maxNum){
				minNum = -1
			}
			for(key in data.MapLeftMap){
				$("#sum"+key).html(data.MapLeftMap[key]+"<span>"+JSON.parse(leftDanwei)[key]+"</span>")
			}
			$("#tempdiv").html(str);
			if(data.orgdeptCount!=data.list.length){
				minNum = 0
			}
			drawMap(minNum,maxNum);
			
			drawChart1(data.orgName,data.orgCount);
			drawChart2(data.years,data.sumCount);
		}
	});	
}
function maoyiitem(num,c){
	var str = '';
	$.each(dataListInfo,function(i,item){
		if(item.type=="1"&&item.other==num){
			str += '<button class="double" onclick="getItem(\''+item.id+'\')">'+item.name+'</button>'
		}
	})
	$("#itembutton").html(str);
	getItem(c)
}

function clicksg(num,name){
	$('.itemButton').each(function(){
		$(this).removeClass("clickButton")
	})
	$("#echart1").html(name);
	$("#echart2").html(name);
	$.ajax({
		type:"Post",
		url:"../fruit/getTypeAllList.do",
		dataType:"json",
		success:function(data){
			var str = '';
			var stt = ' <div class="box-title" style="color: #aedceb;">水果类统计</div>';
				stt+= '<div class="box-content">'
				stt+= '<div class="radio">'
				stt+= '    <input type="radio" class="radio_type" name="type" id="radio-1" checked  onclick="getSgInfo(\'bzmj\')">'
				stt+= '    <label for="radio-1" class="radio-label" onclick="getSgInfo(\'bzmj\')">播种面积</label>'
				stt+= '    <input type="radio" class="radio_type" name="type" id="radio-2" style="margin-left: 20%;" onclick="getSgInfo(\'zcl\')">'
				stt+= '    <label for="radio-2" class="radio-label" onclick="getSgInfo(\'zcl\')">总产量</label>'
				stt+= '</div>'
			stt += ' <div class="button" id="itembutton" style="max-height:620px;overflow-y:auto;overflow-x:hidden;::-webkit-scrollbar:1px;">'
			var flagnum = num;	
			str += '<div class="zb">总种植面积<span id="sumbzzmj"></span></div>'
			str += '<div class="zb">总产量<span id="sumzcl"></span></div>'	
			$.each(data.list,function(i,item){
				stt += '<button class="double" id="double'+item.id+'" onclick="itemSg(\''+item.id+'\')">'+item.name+'</button>'	
			})
			stt += '</div>'
			stt += '</div>'
			$("#box-zb").html(str);
			$("#box-right").html(stt);		
			getSgInfo("bzmj")
		}
	});	
}
function itemSg(id){ 
	$('.double').each(function(){
		$(this).attr("style","")
	})
	$("#double"+id).attr("style","background:#2ea9fb;")
	getSgInfo(sgType,id)  
}
function getSgInfo(type,id){
	if(id==null){
		$('.double').each(function(){
			$(this).attr("style","")
		})
	}
	sgType = type;
	$.ajax({
		type:"Post",
		url:"../mainshow/getMainShowSgInfo.do",
		data:{ 
			fruitId:id,
			type:type,
			"year":$("#selectYear").val()
		},
		dataType:"json",
		success:function(data){
			mapdanwei = data.danwei;
			var str = '';
			var minNum = 0;
			var maxNum = 0;
			$.each(data.list,function(i,item){
				if(i==0){
					maxNum = item.count
				}
				if(i==data.list.length-1){
					minNum =  item.count;
				}
				str +='<input type ="hidden" id="map'+item.id+'" value="'+item.count+'">'
			})
			if(minNum==maxNum){
				minNum = -1
			}
			$("#tempdiv").html(str);
			if(id==null){
				$("#sumbzzmj").html(data.bzzmj+"亩");
				$("#sumzcl").html(data.zcl+"吨")
			}
			
			drawMap(minNum,maxNum);
			drawChart1(data.orgName,data.orgCount);
			drawChart2(data.years,data.sumCount);
		}
	});	
}


function enterIndex(){
	window.location.href="index.html?JSONID="+getQueryVariable("JSONID");
}