var windowId,proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;
$(function(){
	initDefault();	
});
//默认
function initDefault(){
	
//	$("#jobreporttimeStart").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
//	$("#jobreporttimeEnd").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	
	initGrid();
}
//查询条件
function getQueryParams(){
	
	var sParam = {};	
	var tableparam = "";
	//sParam.faultdevicetype = $('#faultdevicetype').combobox("getValue");
	sParam.LIKEfaultdevicename = $('#LIKEfaultdevicename').textbox("getValue");

	var LIKEtime1 = $('#jobreporttimeStart').datetimebox("getValue");	
	var LIKEtime2 = $('#jobreporttimeEnd').datetimebox("getValue");	
	if(!(LIKEtime1==null||LIKEtime1==""||LIKEtime1==undefined)){
		tableparam += " AND jobreporttime >= '" +LIKEtime1 + "'";
	}
	if(!(LIKEtime2==null||LIKEtime2==""||LIKEtime2==undefined)){
		tableparam += " AND jobreporttime <= '" +LIKEtime2 + "'";
	}
	sParam.tableparam = tableparam;
	sParam.flag = "feedback";
	sParam.order = "order by jobaccepttime desc ";
	return sParam;

}
//加载列表
function initGrid(){	
	var toolbar = [{
    	text	:	'查询',
        iconCls	:	'icon-search',
        handler	:	doSearch
    },{
    	text	:	'处理',
//      iconCls	:	'icon-search',
        handler	:	handlesele
    }];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:true,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'ywrepairjobinfoAction!listYwrepairjobinfoByPage.do',
		columns : [[
		    {
				field: 'A',
				checkbox:'true',
				width:30
			},
		    {field:'jobid',title:'jobid',hidden:true,width:120, 
				formatter:function showClick(value,record,num){ 
					return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
				}
			
 			},
			{field:'jobnum',title:'工单编号',hidden:false,width:130},
			{field:'jobacceptstate',title:'工单受理状态',hidden:true,width:120},
			{field:'jobprocessstate',title:'工单受理状态',hidden:false,width:120,
				formatter:function showClick(value,record,num){ 
					return CommonData.jobprocessstate[value];
				}
			},
			{field:'faultgradename',title:'告警等级',hidden:true,width:120},
			{field:'faultdevicetypename',title:'故障设备类型',hidden:false,width:120},
			{field:'faultdevicename',title:'故障设备名称',hidden:false,width:120},
			{field:'faultdeviceid',title:'故障设备编号',hidden:true,width:120},
			{field:'faulttype',title:'故障类型',hidden:true,width:120},
			{field:'faultdescription',title:'故障描述',hidden:false,width:220},
			{field:'jobreportcompanyname',title:'上报单位',hidden:false,width:120},
			{field:'jobreporttime',title:'上报时间',hidden:false,width:130},
			{field:'requirefinishtime',title:'要求完成时间',hidden:false,width:130},
            {field:'B',title:'操作',hidden:false,width:120, 
            	formatter:function (value,record,num){ 
            		var status = CommonData.jobprocessstate[record.jobprocessstate]
            		return '<a href="javascript:;" style="background: #67c23a;color:white;" class="l-btn l-btn-small" onclick="handlejob(\'' + record.jobid + '\',\''+record.faultdeviceid+'\',\''+record.faultdevicename+'\',\''+record.channelnum+'\',\''+status+'\')" group="" id=""><span class="l-btn-left"><span class="l-btn-text">反馈</span></span></a>';
				}
            }
		]]
	});
}

//查询
function doSearch(){	
	$('#tableGrid').datagrid('load',getQueryParams());
}

function handlesele() {
	var selRows = $('#tableGrid').datagrid('getChecked'); 
 	if(selRows===null || selRows.length != 1){
		$.showMsg('请选择一行! ');
		 return;
	}
	var selectRow = $('#tableGrid').datagrid('getSelected'); 
	var jobid = selectRow.jobid;
	handlejob(jobid);
}

// 处理 反馈 工单
function handlejob(jobid,faultdeviceid,faultdevicename,channelnum,jobacceptstate){
	windowId = top.$.createWin({
		title	: 	'工单反馈',
		width	:  	800,
		height	: 	630,
		onClose:function(){
			var win		=	$.getTopWindowById(windowId);
			win.unloadWindow();
		},
		buttons:  [{
			text:$.fn.textbox.defaults.ok,
			handler:dodelaySearch
		}],
		url : sysUrl + "/yw/repairmanage/feedback/jump.jsp?jobid="+jobid+"&faultdeviceid="+faultdeviceid+"&channelnum="+channelnum+"&faultdevicename="+encodeURI(faultdevicename)+"&jobStatus="+encodeURI(jobacceptstate)
	 });
}

function dodelaySearch(){
	setTimeout(function(){
		doSearch();
	},1000)
}
		

