	var myChart = echarts.init(document.getElementById('china-map'));
    var oBack = document.getElementById("fanhui");

    var provinces = ['shanghai', 'hebei', 'shanxi', 'neimenggu', 'liaoning', 'jilin', 'heilongjiang', 'jiangsu', 'zhejiang', 'anhui', 'fujian', 'jiangxi', 'shandong', 'henan', 'hubei', 'hunan', 'guangdong', 'guangxi', 'hainan', 'sichuan', 'guizhou', 'yunnan', 'xizang', 'shanxi1', 'gansu', 'qinghai', 'ningxia', 'xinjiang', 'beijing', 'tianjin', 'chongqing', 'xianggang', 'aomen'];

    var provincesText = ['上海', '河北', '山西', '内蒙古', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '江西', '山东', '河南', '湖北', '湖南', '广东', '广西', '海南', '四川', '贵州', '云南', '西藏', '陕西', '甘肃', '青海', '宁夏', '新疆', '北京', '天津', '重庆', '香港', '澳门'];

    var seriesData = [{
      name: '北京',
      value: 0
    }];
	$.each(provincesText,function(k,v){
		var js = {};
		js.name=v;
		js.value=0;
		seriesData.push(js);
	});

    oBack.onclick = function () {
    	nowCur=0;
		isindex=true;
		initmaps();
		$("#back").html('<img src="/images/addr.png">全国');
		$(".fanhui").hide();
    };
	//缩小
	function reduceToRange(num) {
		if (num <= 100) return num;
		return reduceToRange(Math.floor(num / 2)); // 示例：除以2，也可以选择其他缩小方式
	}
	// 当前是 省市县 
	var nowCur=0;
	var s1="",s2="",s3="";
	var ss2="";
	function changeValue(obj){
		
	
	 $.post("/pc/index243/setseion",{nian:obj.value},function(
			data){
				if(nowCur==0){
					seriesData=[];
					$.each(provincesText,function(k,v){
						var js = {};
						js.name=v;
						js.value=0;
						seriesData.push(js);
					});
					isindex=true;
					$(".tttdbg").remove();
					$.each(provincesText,function(k,v){
						var js = {};
						js.name=v;
						js.value=0;
						seriesData.push(js);
					});
					initmaps();
					$("#back").html('<img src="/images/addr.png">全国');
					$(".fanhui").hide();
				}else if (nowCur==1){
					shlist=[];;
					showProvince(s1, s2,s3);
				}else{
					xianji(ss2);
				}
			});
	}
	//当前是否首页
	var isindex=true;
    function initmaps(){
		$.post("/pc/index243/sheng",{},function(data){
 		var json = eval("("+data+")");
		 
		$(".tttdbg").remove();
		var m1=0,m2=0,m3=0;
		$(".tttd").remove();
		$(".ddbss").append('<tr class="tttd"> <td></td> <td>总单数</td> <td>总金额（万元）</td> </tr>');
		var v1=0,v2=0;
		var k1=0,k2=0;
 		$.each(json.list,function(k,v){
			if(v.types=="水土保持碳汇"){
				k1=Number(v.sl);
				k2=Number(v.value);
			}else{
				v1+=Number(v.sl);
				v2+=Number(v.value);
			}
			//$(".ddbss").append('<tr class="tttdbg"> <td>'+v.types+'</td> <td class="jinels">'+v.sl+'</td> <td class="jinels">'+v.value+'</td> </tr>');
			m1+=Number(v.sl);
			m2+=Number(v.value);
			m3+=Number(v.mj);
			 
		});
		$(".ddbss").append('<tr class="tttdbg"> <td>水土保持生态产品（除碳汇）</td> <td class="jinels">'+v1.toFixed(0)+'</td> <td class="jinels">'+v2.toFixed(2)+'</td> </tr>');
		console.log(k1);
		$(".ddbss").append('<tr class="tttdbg"> <td>水土保持碳汇</td> <td class="jinels">'+k1.toFixed(0)+'</td> <td class="jinels">'+k2.toFixed(2)+'</td> </tr>');
		
		var zidingyishuzu=[];
		$.each(json.list2,function(k,v){  
			zidingyishuzu.push(Number(v.value));
		});
		//排序
		zidingyishuzu = zidingyishuzu.map(reduceToRange);
		var i_=0;
		$.each(json.list2,function(k,v){
			var js ={};
			js.name=v.title.replace(/省/ig,"").replace(/市/ig,"");
			js.value=zidingyishuzu[i_];
			i_++;
			 
			seriesData.push(js);
		}); 
		$(".ddbss").append('<tr class="tttdbg"> <td>总计</td> <td class="jinels">'+m1.toFixed(0)+'</td> <td class="jinels">'+m2.toFixed(2)+'</td> </tr>');
 		initEcharts("china", "中国");
	});
	}
	$(".leiji").click(function(){
		$.post("/pc/index243/quanbu",{},function(data){
 		var json = eval("("+data+")");
		 
		$(".tttdbg").remove();
		var m1=0,m2=0,m3=0;
		$(".tttd").remove();
		$(".ddbss").append('<tr class="tttd"> <td></td> <td>总单数</td> <td>总金额（万元）</td> </tr>');
		var v1=0,v2=0;
		var k1=0,k2=0;
 		$.each(json.list,function(k,v){
			if(v.types=="水土保持碳汇"){
				k1=Number(v.sl);
				k2=Number(v.value);
			}else{
				v1+=Number(v.sl);
				v2+=Number(v.value);
			}
			//$(".ddbss").append('<tr class="tttdbg"> <td>'+v.types+'</td> <td class="jinels">'+v.sl+'</td> <td class="jinels">'+v.value+'</td> </tr>');
			m1+=Number(v.sl);
			m2+=Number(v.value);
			m3+=Number(v.mj);
			 
		});
		$(".ddbss").append('<tr class="tttdbg"> <td>水土保持生态产品（除碳汇）</td> <td class="jinels">'+v1.toFixed(0)+'</td> <td class="jinels">'+v2.toFixed(2)+'</td> </tr>');
		$(".ddbss").append('<tr class="tttdbg"> <td>水土保持碳汇</td> <td class="jinels">'+k1.toFixed(0)+'</td> <td class="jinels">'+k2.toFixed(2)+'</td> </tr>');
		
		var zidingyishuzu=[];
		$.each(json.list2,function(k,v){  
			zidingyishuzu.push(Number(v.value));
		});
		//排序
		zidingyishuzu = zidingyishuzu.map(reduceToRange);
		var i_=0;
		$.each(json.list2,function(k,v){
			var js ={};
			js.name=v.title.replace(/省/ig,"").replace(/市/ig,"");
			js.value=zidingyishuzu[i_];
			i_++;
			 
			seriesData.push(js);
		}); 
		$(".ddbss").append('<tr class="tttdbg"> <td>总计</td> <td class="jinels">'+m1.toFixed(0)+'</td> <td class="jinels">'+m2.toFixed(2)+'</td> </tr>');
 		initEcharts("china", "中国");
	});
	});
	var shlist=[];
    // 初始化echarts
    function initEcharts(pName, Chinese_) {
		 
      var tmpSeriesData = pName === "china" ? seriesData : shlist;
	   
      var option = {
        title: {
          text: "",//Chinese_ || pName,
          left: 'center'
        },
		 visualMap: {
			 
			min: 0,
			max:100,
			bottom: 150,
			realtime:false,
			calculable: true,
				inRange: {
					color: ['#b2f9ba', '#63c26d']
				}
		},
           //tooltip: {
          //     trigger: 'item',
         //      formatter: '{b}<br/>{c} '.replace(/undefined/ig,"").replace(/NaN/ig,"")
          // },
        series: [
          {
            name: Chinese_ || pName,
            type: 'map',
            mapType: pName,
            roam: false,//是否开启鼠标缩放和平移漫游
            data: tmpSeriesData,
            top: "3%",//组件距离容器的距离
              zoom:1.1,
              selectedMode : 'single',

              label: {
                  normal: {
                      show: true,//显示省份标签
                      textStyle:{color:"#000000"}//省份标签字体颜色
                  },
                  emphasis: {//对应的鼠标悬浮效果
                      show: true,
                      textStyle:{color:"#000000"}
                  }
              },
              itemStyle: {
                  normal: {
                      borderWidth: .5,//区域边框宽度
                      borderColor: '#CCCCCC',//区域边框颜色
                      areaColor:"#EDF9FF",//区域颜色

                  },

                  emphasis: {
                      borderWidth: .5,
                      borderColor: '#FFFFFF',
                      areaColor:"#fee9e9",
                  }
              },
          }
        ]

           };

      myChart.setOption(option);

      myChart.off("click");
		
      if (pName === "china") { // 全国时，添加click 进入省级
	   
         myChart.on('click', function (param) {
			 $(".fanhui").show(); 
			 nowCur=1;
          // 遍历取到provincesText 中的下标  去拿到对应的省js
			$("#back").html('<img src="/images/addr.png">'+param.name);
			  for (var i = 0; i < provincesText.length; i++) {
				if (param.name === provincesText[i]) {
				  //显示对应省份的方法
				  if(provinces[i]!=""){
					  s1=provinces[i];
					  s2=provincesText[i]; 
					  s3=param.name;
				  }
				  showProvince(provinces[i], provincesText[i],param.name);
				  break;
				}
			  }
            if (param.componentType === 'series') {
                var provinceName =param.name;
                $('#box').css('display','block');
                $("#box-title").html(provinceName);

            } 
			
        });
      } else { // 省份，添加双击 回退到全国
		   
    	   
           myChart.on('click', function (param) {
			   if(nowCur==0){
				   $(".fanhui").show(); 
					 nowCur=1;
				  // 遍历取到provincesText 中的下标  去拿到对应的省js
					$("#back").html('<img src="/images/addr.png">'+param.name);
					  for (var i = 0; i < provincesText.length; i++) {
						if (param.name != provincesText[i]) {
						  //显示对应省份的方法
						  s1=provinces[i];
						  s2=provincesText[i];
						  s3=param.name;
						  $("#back").html('<img src="/images/addr.png">'+ s3);
						  showProvince(provinces[i], provincesText[i],param.name);
						  break;
						}
					  }
					if (param.componentType === 'series') {
						var provinceName =param.name;
						$('#box').css('display','block');
						$("#box-title").html(provinceName);

					} 
			   }else{
				   if(param.name!=""){
					   ss2=param.name;	 
					   $("#back").html('<img src="/images/addr.png">'+ ss2);					   
				   }else{
					   console.log(param );
					   console.log(param.seriesName);
					   ss2=param.seriesName;	 
					   $("#back").html('<img src="/images/addr.png">'+ ss2);		
				   }
				    
				  
				   nowCur=2;
				   xianji(ss2);
			   }
			  
		   });
      }
    }
	function xianji(name){
		if(name==""){
		  		$(".tttdbg").remove();
				$(".tttd").remove();
				$(".ddbss").append('<tr class="tttd"> <td></td> <td>小流域/项目区</td><td>小流域面积(km<sup>2</sup>)</td><td>总单数</td> <td>总金额（万元）</td><td> 交易时间</td> </tr>');
				return;
		  	
		  }
		  
		  //$("#back").html('<img src="/images/addr.png">'+ name);
          $.post("/pc/index243/xian",{title: name},function(data){
				var json = eval("("+data+")");
				 
				
				var m1=0,m2=0,m3=0;
				var zidingyishuzu=[];
				$.each(json.list,function(k,v){  
					zidingyishuzu.push(Number(v.value));
				});
				//排序
				zidingyishuzu = zidingyishuzu.map(reduceToRange);
				var i_=0;
				shlist=[];;
				$.each(json.list,function(k,v){
					var js ={};
					js.name=v.title ;
					js.value=zidingyishuzu[i_];
					i_++;
				//	$(".ddbss").append('<tr class="tttdbg"><td>'+v.types+'</td> <td>'+v.name+'</td><td class=" ">'+v.mj+'</td> <td class=" ">'+v.sl+'</td> <td class=" ">'+v.value+'</td> <td class=" ">'+v.qysj+'</td> </tr>');
					m1+=Number(v.mj);
					m2+=Number(v.sl);
					m3+=Number(v.value);
					shlist.push(js);
				});
				//showProvince2(s1, s2,s3);
				$(".tttdbg").remove();
				$(".tttd").remove();
				$(".ddbss").append('<tr class="tttd"> <td></td> <td>小流域/项目区</td><td>小流域面积(km<sup>2</sup>)</td><td>总单数</td> <td>总金额（万元）</td><td> 交易时间</td> </tr>');
				var v1=0,v2=0,v3=0,v4="",v5="";
				var k1=0,k2=0,k3=0,k4="",k5="";
				$.each(json.list2,function(k,v){
				 
					//$(".ddbss").append('<tr class="tttdbg"><td>'+v.types+'</td> <td>'+v.name+'</td><td class=" ">'+v.mj+'</td> <td class=" ">'+v.sl+'</td> <td class=" ">'+v.value+'</td> <td class=" ">'+v.qysj+'</td> </tr>');
					if(v.types=="水土保持碳汇"){
						k1=Number(v.mj);
						k2=Number(v.sl);
						k3=Number(v.value);
						k4=v.name;
						k5=v.qysj;
					}else{
						v1+=Number(v.mj);
						v2+=Number(v.sl);
						v3+=Number(v.value);
						v4=v.name;
						v5=v.qysj;
					} 
				 
				});
				$(".ddbss").append('<tr class="tttdbg"><td width="80px">水土保持生态产品（除碳汇）</td> <td>'+v4+'</td><td class=" ">'+v1.toFixed(2)+'</td> <td class=" ">'+v2.toFixed(0)+'</td> <td class=" ">'+v3.toFixed(2)+'</td> <td class=" ">'+v5+'</td> </tr>');
				$(".ddbss").append('<tr class="tttdbg"><td>水土保持碳汇</td> <td>'+k4+'</td><td class=" ">'+k1.toFixed(2)+'</td> <td class=" ">'+k2.toFixed(0)+'</td> <td class=" ">'+k3.toFixed(2)+'</td> <td class=" ">'+k5+'</td> </tr>');
				 
				
				$(".ddbss").append('<tr class="tttdbg"> <td>总计</td><td></td><td>'+m1.toFixed(2)+'</td> <td class=" ">'+m2.toFixed(0)+'</td> <td class=" ">'+m3.toFixed(2)+'</td> <td></td> </tr>'); 
				
					
			});
	}
    // 展示对应的省
    function showProvince(pName, Chinese_,title) {
		if(title==""){
			$(".tttdbg").remove();
				$(".tttd").remove();
				$(".ddbss").append('<tr class="tttd"> <td></td> <td>总单数</td> <td>总金额（万元）</td> </tr>');
			return;
		} 
	  
			isindex=false;
      //这写省份的js都是通过在线构建工具生成的，保存在本地，需要时加载使用即可，最好不要一开始全部直接引入。
			loadBdScript('$' + pName + 'JS', '/map/js/map/province/' + pName + '.js', function () {
			nowCur=1;
			
			$.each(jsons,function(k,v){
				if(v.name.indexOf(s2)!=-1&&s2!=""){
					json = v.city ;
					shlist=[]; 
					$.each(json,function(k,v){
						var js ={};
						js.name=v.name ;
						js.value=0;
						shlist.push(js);
						
					});
					console.log("---");
					console.log(shlist);
					console.log("---");
				}
			});
			
			$.post("/pc/index243/shi",{title:title},function(data){
				var json = eval("("+data+")");
				 
				 
				$(".tttdbg").remove();
				$(".tttd").remove();
				$(".ddbss").append('<tr class="tttd"> <td></td> <td>总单数</td> <td>总金额（万元）</td> </tr>');
				var m1=0,m2=0,m3=0;
				var zidingyishuzu=[];
				$.each(json.list,function(k,v){  
					zidingyishuzu.push(Number(v.value));
				});
				//排序
				zidingyishuzu = zidingyishuzu.map(reduceToRange);
				var i_=0;
				var v1=0,v2=0;
				var k1=0,k2=0;
				$.each(json.list,function(k,v){
					var js ={};
					js.name=v.title ;
					js.value=zidingyishuzu[i_];
					
					
				//	$(".ddbss").append('<tr class="tttdbg"> <td>'+v.types+'</td> <td class="jinels">'+v.sl+'</td> <td class="jinels">'+v.value+'</td> </tr>');
					m1+=Number(v.sl);
					m2+=Number(v.value);
					m3+=Number(v.mj);
				 	shlist.push(js);
				 	
				 	js ={};
					js.name=v.title+"市" ;
					js.value=zidingyishuzu[i_];
					shlist.push(js);
				 	
				 	i_++;
				 	
				});
				 
			
		 		$.each(json.list2,function(k,v){
					if(v.types=="水土保持碳汇"){
						k1=Number(v.sl);
						k2=Number(v.value);
					}else{
						v1+=Number(v.sl);
						v2+=Number(v.value);
					} 
					 
				});
				$(".ddbss").append('<tr class="tttdbg"> <td>水土保持生态产品（除碳汇）</td> <td class="jinels">'+v1.toFixed(0)+'</td> <td class="jinels">'+v2.toFixed(2)+'</td> </tr>');
				$(".ddbss").append('<tr class="tttdbg"> <td>水土保持碳汇</td> <td class="jinels">'+k1.toFixed(0)+'</td> <td class="jinels">'+k2.toFixed(2)+'</td> </tr>');
			    $(".ddbss").append('<tr class="tttdbg"> <td>总计</td> <td class="jinels">'+m1.toFixed(0)+'</td> <td class="jinels">'+m2.toFixed(2)+'</td> </tr>');

				initEcharts(Chinese_);
			});
			
		  }); 
    }
 

    // 加载对应的JS
    function loadBdScript(scriptId, url, callback) {
      var script = document.createElement("script");
      script.type = "text/javascript";
      if (script.readyState) {  //IE
        script.onreadystatechange = function () {
          if (script.readyState === "loaded" || script.readyState === "complete") {
            script.onreadystatechange = null;
            callback();
          }
        };
      } else {  // Others
        script.onload = function () {
          callback();
        };
      }
      script.src = url;
      script.id = scriptId;
      document.getElementsByTagName("head")[0].appendChild(script);
    };
	initmaps();