$(function(){
	$("#LIKEczsjStart").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
	$("#LIKEczsjEnd").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	initGrid();
});
$.extend($.fn.datagrid.methods,
		{
	renderMachineData:function(n, g, h){
		console.log("ggggg:",g);
		 var m = n.parent(".datagrid-view:eq(0)"),
         c;
         var k = m.prev("div").append("<table cellspacing=0 cellpadding=0 style='display:inline-block;height:26px;float:right;'><tbody><tr/></tbody></table>").children("table:eq(1)").find("tbody tr");
         var b = m.parent().height();
         var o = m.parent().width();
         if (!m.next("div.imgcontainer").html()) {
             c = $("<div class='imgcontainer' style='overflow-y:auto; width:99%;height:" + (b - 70) + "px;'></div>");
             m.after(c)
         } else {
             c = m.next("div.imgcontainer")
         }
         if (!g) {
             return
         }
         var f = 0,
         l = [],
         e,
         d,
         j = this;
         for (; (g.data[f]); f++) {
             g.data[f].oprStatusStr = g.data[f].oprStatus == 0 ? "正常": "异常";
             g.data[f].oprStatusColor = 'style="color:' + (g.data[f].oprStatus == 0 ? "blue;": "red;") + '"';
             g.data[f].picUrl = $.getPicProxyUrl(g.data[f].picUrl);
           var html='<div class="view-item" style="width:200px;background-color:white; ">\
            		 <div style="padding: 0 6px;">\
			        	   <img  style="height: 100px;width: 80px;display:inline-block;" src="' + (g.data[f].picUrl) + '" onerror="javascript:$.loadErrorPic(this);"/>\
			        	   <div style="display:inline-block; vertical-align: middle;    line-height: 8px;"><p>ip:&nbsp;' + (g.data[f].machineip || "无") + '</p>" + "<p>CPU使用率:&nbsp;' + (g.data[f].cpusyl || "") + '</p>" + "<p>内存使用率:&nbsp; '+(g.data[f].memory || "")+' </p>" <p>硬盘使用率:&nbsp; '+(g.data[f].ncsyl || "")+' </p></div>\
			         </div>\
			        <div  style="width:198px;background-color: #EFEFEF; padding:  6px;"><p style="line-height: 22px;">'+ (g.data[f].machinename)+'</p><p style="line-height: 22px;">检测时间:&nbsp;' + (g.data[f].statusuptime || "无") + '</p></div>\
			      </div> '
           l.push(html);
         }
         c.html('<div class="img-box">' + l.join("") + "</div>")
     }
});
//加载列表
function initGrid(){	
	var toolbar = [{
        text:'查询',
        iconCls:'icon-search',
        handler:function(){doSearch();}
    }];
	$('#searchGrid').datagrid({
		toolbar : toolbar,
		bodyCls:'pic-datagrid',
		queryParams:getQueryParams(),
		url : 'ywmachinestatusinfoAction!get_ywmachinestatusinfo.do',
		onLoadSuccess:function(data){
			data.data=data.rows;
			data.totalSize=data.total;
			$('#searchGrid').datagrid("renderMachineData",data);
		},
		rownumbers:true,
		/*data: [
			{id:1,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:2,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:3,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:4,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:5,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:6,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:7,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"},
			{id:8,name:"智能媒体服务器",ip:"192.168.5.190",cpu:"54%",memory:"54%",yp:"54%",date:"2018-11-09 17:01"}
		],*/
		columns : [[
		            {
						field:'id',hidden:true,width:150, 
						formatter:function showClick(value,record,num){ 
							return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
						}
						},
					{field:'f1',title:'描述',width:120},
					{field:'f2',title:'rzly',width:120},
					{field:'vdId',hidden:true,width:150},
					{field:'channelId',hidden:true,width:150},
					{field:'picUrl',hidden:true,width:150},
					{field:'executeDate',hidden:true,width:150},
					{field:'executeRet',hidden:true,width:150},
					{field:'oprStatus',hidden:true,width:150},
					{field:'reason',hidden:true,width:150}
				]]
	});
}

function doSearch() {
	$('#searchGrid').datagrid('load', getQueryParams());
}

function getQueryParams(){
	var sParam = {};	
	sParam.machinename = $('#machinename').textbox("getValue");
	sParam.startTime = $("#LIKEczsjStart").datetimebox("getValue");
	sParam.endTime = $("#LIKEczsjEnd").datetimebox("getValue");
	return sParam;
}
function oprStatus(obj,oprStatus) {
	var id = $(obj).attr("tag");
	var m = {};
	m.table = "DrawPicTaskDetail";
	m.updateParams = " oprStatus="+oprStatus;
	m.params = "id='"+id+"'";
	doSearch();	
}
