$(function(){
	$("#LIKEczsjStart").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
	$("#LIKEczsjEnd").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	initGrid();
});
$.extend($.fn.datagrid.methods,
		{
	renderSoftwareData: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;">'
            	 html+='<div style="height:34px;line-height:34px;padding:0 10px;background-color:#EFEFEF;">'+g.data[f].name+'</div>'
            	 html+='<div style="padding:0 10px;border: 1px solid #efefef;">'
            for(var i=0;g.data[f].item[i];i++){
            	html+='<div style="margin:0 4px;padding:4px 6px;width:250px;display:inline-block;">\
            					<img  style="height: 100px;width: 80px;display:inline-block;" src="' + (g.data[f].picUrl) + '" onerror="javascript:$.loadErrorPic(this);"/>\
     			        	     <div style="display:inline-block;height: 100px;  vertical-align: top;  width: 140px;    line-height: 38px;"><p> '+ (g.data[f].item[i].name || "无") + '</p><p>状态:&nbsp;' + (g.data[f].item[i].status || "") + '</p><p>'+(g.data[f].item[i].date || "")+' </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({
		bodyCls:'pic-datagrid',
		onLoadSuccess:function(data){
			data.data=data.rows;
			data.totalSize=data.total;
			$('#searchGrid').datagrid("renderSoftwareData",data);
		},
		rownumbers:true,
		data: [
			{id:1,name:"智能媒体应用平台",item:[{name:"海康代理",status:"正常",date:"2018-11-08 15:32"},{name:"大华代理",status:"异常",date:"2018-11-08 15:32"}]},
			{id:2,name:"长宜联动平台",item:[{name:"web平台",status:"正常",date:"2018-11-08 15:32"},{name:"数据接口",status:"异常",date:"2018-11-08 15: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();	
}
