$(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){
		 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++) {
        	 console.log("(g.data[f])",(g.data[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 style="font-size:14px;margin: 30px 0;width:54%;">'
            	 html+='<div style="height:34px;line-height:34px;padding:0 10px;background-color:#EFEFEF;">'+(g.data[f].name||"海康服务器")+'&nbsp;&nbsp;统计周期: 2018-11-08</div>'
            	 html+='<div style="padding:0 10px;border: 1px solid #efefef;">\
            		 <div style="padding:  6px;">\
		        	   <img  style="height: 100px;width: 80px;display:inline-block;" src="' + (g.data[f].picUrl) + '" onerror="javascript:$.loadErrorPic(this);"/>\
		        	   <div style="display:inline-block;     padding: 16px; line-height: 24px;"><p>状态:&nbsp;' + (g.data[f].machineip || "正常") + '</p><p>ip:&nbsp;' + (g.data[f].machineip || "无") + '</p><p>CPU:&nbsp;' + (g.data[f].cpusyl || "") + '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用率：74%</p><p>内存:&nbsp; '+(g.data[f].memory || "")+'&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;使用率：74% </p><p>硬盘:&nbsp; '+(g.data[f].ncsyl || "")+' &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;使用率：74%</p></div>\
		         </div>';
            html+='</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',
		onLoadSuccess:function(data){
			data.data=data.rows;
			data.totalSize=data.total;
			$('#searchGrid').datagrid("renderMachineData",data);
		},
		rownumbers:true,
		data: [
			{id:1,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:12,ncsyl:32,name:"媒体智能服务器"},
			{id:2,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:31,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:32,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:33,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:34,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:35,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:36,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:37,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:38,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32,name:"媒体智能服务器"},
			{id:39,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:3,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32},
			{id:4,f1:'value11', f2:'value12',picUrl:"12",vdId:1,channelId:2,executeDate:3,executeRet:4,oprStatus:5,reason:12,machineip:"192.123.2.1",cpusyl:12,memory:122,ncsyl:32}
		],
		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(){
	
}
function oprStatus(obj,oprStatus) {
	var id = $(obj).attr("tag");
	var m = {};
	m.table = "DrawPicTaskDetail";
	m.updateParams = " oprStatus="+oprStatus;
	m.params = "id='"+id+"'";
	doSearch();	
}
