var windowId, proName = window.location.pathname.split("/")[1],
    sysUrl = "http://" + window.location.host + "/" + proName, toEdit;
$(function () {
    initDefault();
});

//默认
function initDefault() {

    initGrid();
}

//查询条件
function getQueryParams() {
    var sParam = {};
//	var startTime = $('#startTime').datetimebox("getValue");	
//	var endTime = $('#endTime').datetimebox("getValue");

    sParam.LIKEledmc = $('#LIKEledmc').textbox("getValue");
//	sParam.startTime = startTime;
//	sParam.endTime = endTime;
    return sParam;
}

//加载列表
function initGrid() {
    var toolbar = [{
        text: '查询',
        iconCls: 'icon-search',
        handler: doSearch
    }];
    $('#tableGrid').datagrid({
        toolbar: toolbar,
        singleSelect: true,
        rownumbers: true,
        queryParams: getQueryParams(),
        url: 'nhywjtledydpglAction!listYwAllydpstatusinfo.do',
        columns: [[
            /* {
                 field: 'A',
                 checkbox:'true',
                 width:30
             },*/

            {field:'xh',title:'序号',hidden:true,width:120},
            {field:'ledmc',title:'LED名称',hidden:false,width:120},
            {field:'ledbh',title:'LED编号',hidden:false,width:120},
            {field:'sccs',title:'生产厂商',hidden:false,width:120},
            {field:'pp',title:'品牌',hidden:true,width:120},
            {field:'ggxh',title:'规格型号',hidden:true,width:120},
            {field:'qybh',title:'区域编号',hidden:false,width:120},
            {field:'qymc',title:'区域名称',hidden:false,width:120},
            {field:'lkh',title:'路口号',hidden:false,width:120},
            {field:'lkmc',title:'路口名称',hidden:false,width:120},
            {field:'lkxw',title:'路口相位',hidden:false,width:120},
            {field:'azsj',title:'安装时间',hidden:true,width:120},
            {field:'azdw',title:'安装单位',hidden:true,width:120},
            {field:'qdfs',title:'取电方式',hidden:true,width:120},
            {field:'sszbx',title:'所属坐标系',hidden:true,width:120},
            {field:'jd',title:'经度',hidden:false,width:120},
            {field:'wd',title:'维度',hidden:false,width:120},
            {field: 'xjsj', title: '检测时间', hidden: false, width: 120},
            {
                field: 'sbzt', title: '当前状态', hidden: false, width: 60,
                formatter: function showClick(value, record, num) {
                    if (value == 1) {
                        return "<div style='height:13px;width:13px;background-color:green;border-radius:50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;margin:0 auto;'></div>";
                    } else if (value == 0){
                        return "<div style='height:13px;width:13px;background-color:#fe0000;border-radius:50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;margin:0 auto;'></div>";
                    }
                    else {
                        return "未知";
                    }
                }
            },
            {
                field: 'A', title: '操作', hidden: false, width: 70,
                formatter: function showClick(value, record, num) {
                    return '<a href="javascript:;" style="background: #67c23a;color:white;padding: 2px,5px;" class="l-btn l-btn-small" onclick="lookHistory(' + num + ')"  group="" id=""><span class="l-btn-left"><span class="l-btn-text">详情</span></span></a>';
                }
            }
        ]]
    });
}

// 查看历史记录
function lookHistory(index) {

    //console.log("历史跳转：",index);
    var selRows = $('#tableGrid').datagrid('getRows')[index];
    windowId = top.$.createWin({
        title: '历史记录',
        width: 800,
        height: 500,
        data: selRows,
        url: sysUrl + "/yw/recordalarm/nhywjtydpglstate/ywydphistorystate.jsp?xh=" + selRows.xh
    });
}


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


