
//填充列表展示数据
function fetchData(num) {
	if(num==undefined ){
		num = 1;
	}
	var params ={};
	var bzlx = $("#roadNameSearch").val();
	bzlx = bzlx == null ? '' : bzlx;
	params.bzlx = bzlx;
	params.LIKEbzmc=$("#tdmcSearch").val();
	var limit = 10;
	params.rows = limit;
	params.page = num ;
//	console.log("road：",params)
    var table_html = '';
    $.ajax({
		 type:'post',
		 dataType : 'json',
		 url : 'nhywjtbzglAction!listNhywjtbzglByPage.do',
		 data:params,
		 success:function(data){
//			console.log(data);
		    genHtml(data,num,limit)
		 }
	 });
}

//生成html
function genHtml(data,num,limit){
	var html = "";
	if (data && data.total > 0) {
			data.rows.forEach(function (item,index) {
				//经度、维度保留两位小数
				var jd = item.jd==null?'':item.jd;
				if(jd.length > 1){
					jd = parseFloat(jd).toFixed(2);
				}
				var wd = item.wd==null?'':item.wd;
				if(wd.length > 1){
					wd = parseFloat(wd).toFixed(2);
				}
				var datastr = {};
				datastr.xh = item.xh;
				datastr.bzbh = item.bzbh;
				datastr.bzmc = item.bzmc;
				datastr.bzlx = item.bzlx;
				datastr.bzpp = item.bzpp;
				datastr.ggxh = item.ggxh;
				html += '<tr data-json='+JSON.stringify(datastr)+' ondblclick="fillVideoData(this)"  onclick="selectTr(this)"><td>' + ((num-1)*limit+1+index) + '</td>' +
			    '<td>'+(item.bzmc==null?'':item.bzmc)+'</td>' +
			    '<td>'+(item.bzlx==null?'':item.bzlx)+'</td>' +
			    '<td>'+(item.bzpp==null?'':item.bzpp)+'</td>' +
			    '<td>'+(item.ggxh==null?'':item.ggxh)+'</td>' +
			    '<td>'+(item.jd==null?'':item.jd)+'</td>' +
			    '<td>'+(item.wd==null?'':wd)+'</td>' ;
		    });
			if (num === 1) {
                $("#page").initPage(data.total, 1, function (index) {
                	fetchData(index);
    			});
            }
	}else{
		html = "<tr><td colspan='11'>暂无数据</td></tr>";
		$("#page").initPage(0, 1, function (index) {
		});
	}
	$('#tbody').html(html);
}


function fillVideoData(o){
	var winId	= $.getUrlParam("winId");
	var Label = top.$("#"+winId).panel("options").data.Label;
	Label.fillNhywjtbz(o);
	top.$(top.GETWIN(top.windowid)).destroy();
}
function selectTr(o){
	$("#list-show tr").css("backgroundColor",'white');
	$(o).css("backgroundColor",'#cccccc');
}
$(function(){
	fetchData(1);
 	$(".queryList").live("click",function(){
 		fetchData(1);
 	});
 	
 	$("#arcgisVideoList").find(".font14:eq(1)").click(function(){
 		parent.$("#arcgisIframe").hide();
 		parent.$(".esri-component").show();
 	});
 	
 	
 	
 	// 点击  路段名称  出现下拉框选择
 	$("#roadNameSearch").on('click',addRoadOptions());
});



//加载下拉框
function addRoadOptions(){
	$.ajax({
		type:'post',
		dataType : 'json',
		url : 'xtclAction!query_Xtcl.do?csdl=nhywBzlx',
		success:function(data){
			//console.log(data);
			$("#roadNameSearch").empty();
			if(data != null){
				var options = '<option value=""  selected="selected">请选择标志类型</option>';
				data.forEach(function(item){
					options += '<option value="'+item.csdm+'">'+item.csmc+'</option>'
				})
				$("#roadNameSearch").append(options);
			}
		}
	});
}

