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


//查询条件
function getQueryParams() {
    var sParam = {};
    sParam.LIKExhdmc = $('#LIKExhdmc').textbox("getValue");
    sParam.order = "order by xhdmc desc "
    return sParam;
}

//加载列表
function initGrid() {
    var toolbar = [
        {
            text: '查询',
            iconCls: 'icon-search',
            handler: doSearch
        },

        ,{
            text	:	'增加',
            iconCls	:	'icon-add',
            handler	:	doAddTask
        },{
            text	:	'修改',
            iconCls	:	'icon-cut',
            handler	:	doEdit
        },{
            text	:	'删除',
            iconCls	:	'icon-delete',
            handler	:	doDelete_batch
        },{
            text	:	'设置规则',
            iconCls	:	'icon-add',
            handler	:	doSetRule
        },{
            text	:	'选择集合',
            iconCls	:	'icon-add',
            handler	:	doChannelSet
        },
        {
            text: '启用',
            iconCls: 'icon-start',
            handler: switchOpen
        }, {
            text: '停止',
            iconCls: 'icon-end',
            handler: switchClose
        }];
    $('#searchGrid').datagrid({
        toolbar: toolbar,
        singleSelect: true,
        rownumbers: true,
        queryParams: getQueryParams(),
		url:'nhywjtxhdglAction!listNhywjtxhdglByPage.do',
        columns: [[
            {
                field: 'A',
                checkbox: 'true',
                width: 30
            },
            {
                field: 'xh', title: '编码', hidden: true, width: 120,
                formatter: function showClick(value, record, num) {
                    return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate(" + num + ")'>" + value + "</a>";
                }
            },

            {field: 'xhdmc', title: '信号灯名称', hidden: false, width: 120},
            {field: 'xhdbh', title: '信号灯编号', hidden: false, width: 120},
            {field: 'qymc', title: '区域名称', hidden: false, width: 120},
            {field: 'lkmc', title: '路口名称', hidden: false, width: 120},
            {field: 'jd', title: '经度', hidden: false, width: 120},
            {field: 'wd', title: '维度', hidden: false, width: 120},
            {field: 'csmc', title: '是否启用', hidden: false, width: 80}
        ]]

    });
}


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



function switchOpen() {				// 开启
    var selRows = $('#searchGrid').datagrid('getChecked');
//	console.log("selRows：",selRows);
    var ids = '';
    if (selRows === null || selRows.length==0) {
        $.showMsg('请先选择一行! ');
        return;
    } else {
        selRows.forEach(function (item) {
            ids += item.xh + ',';
        })
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: 'nhywjtxhdglAction!edit_Ywxhdinfo.do',
            data: {'ids': ids, 'detectionswitch': 1},
            success: function (res) {
                if (res) {
                    $.showMsg("操作成功！");
                    doSearch();
                } else {
                    $.showMsg("操作失败！");
                }
            }
        });
    }
}

function switchClose() {				// 关闭
    var selRows = $('#searchGrid').datagrid('getChecked');
    console.log("selRows：", selRows);
    var ids = '';
    if (selRows === null) {
        $.showMsg('请先选择一行! ');
        return;
    } else {
        selRows.forEach(function (item) {
            ids += item.xh + ',';
        })
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: 'nhywjtxhdglAction!edit_Ywxhdinfo.do',
            data: {'ids': ids, 'detectionswitch': 0},
            success: function (res) {
                if (res) {
                    $.showMsg("操作成功！");
                    doSearch();
                } else {
                    $.showMsg("操作失败！");
                }
            }
        });
    }
}

