
//填充列表展示数据
function fetchData(num) {
	if(num==undefined ){
		num = 1;
	}
	var params ={};
	var roadName = $("#roadNameSearch").val();
	roadName = roadName == null ? '' : roadName;
	params.roadName = roadName;
	params.tdmc=$("#tdmcSearch").val();
	var limit = 10;
	params.rows = limit;
	params.page = num ;
	console.log("road：",params)
    var table_html = '';
    $.ajax({
		 type:'post',
		 dataType : 'json',
		 url : 'trafficroadinfoAction!listTrafficroadinfoByPage.do',
		 data:params,
		 success:function(data){
			console.log("trafficroadinfoAction：",data);
		    genHtml(data,num,limit)
		 }
	 });
}
/********************************缉查布控查询列表功能  end ********************************/
//生成html
function genHtml(data,num,limit){
	var html = "";
	if (data && data.total > 0) {
			data.rows.forEach(function (item,index) {
				html += '<tr data-json='+JSON.stringify(item).replace(/\s+/g,'')+' ondblclick="fillRoadData(this)"  onclick="selectTr(this)">'+
							'<td>' + ((num-1)*limit+1+index) + '</td>' +
						    '<td>'+(item.roadname==null?'':item.roadname)+'</td>' +
						    '<td>'+(item.updirection==null?'':item.updirection)+'</td>' +
						    '<td>'+(item.downdirection==null?'':item.downdirection)+'</td>' +
						 '</tr>' ;
		    });
			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 fillRoadData(o){
	var winId	= $.getUrlParam("winId");
	var Label = top.$("#"+winId).panel("options").data.Label;
 	Label.fillRoad(o);  //调用子页面中的subFunction方法。    
 	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 : 'trafficroadinfoAction!getTrafficroadinfoAll.do',
		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.roadname+'">'+item.roadname+'</option>'
				})
				$("#roadNameSearch").append(options);
			}
		}
	});
}

