var proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;
var winId	= $.getUrlParam("winId");
var fwsbh = $.getUrlParam("fwsbh");
var xcdh = $.getUrlParam("xcdh");
$(function(){
	if(!fwsbh){
		fwsbh = "-1";//
	}
	initDefault();	
});
//默认
function initDefault(){
	initGrid();
}
//查询条件
function getQueryParams(){
	var sParam = {};
	sParam.LIKEchannelname = $('#LIKEtdmc').textbox("getValue");
	sParam.LIKEvideonum = $('#LIKEsbbh').textbox("getValue");
	sParam.fwsbh = fwsbh;
	sParam.xcdh = xcdh;
	sParam.order = "order by videonum,channelnum desc ";
	
	return sParam;
}
//加载列表
function initGrid(){	
	var toolbar = [{
    	text	:	'查询',
        iconCls	:	'icon-search',
        handler	:	doSearch
    }];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:false,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'nhywjtssxcsbAction!listJksbByFwsbh.do',
		columns : [[
		    {
				field: 'A',
				checkbox:'true',
				width:30
			},
		    {field:'xh',title:'xh',hidden:true,width:120, 
				formatter:function showClick(value,record,num){ 
					return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
				}
 			},
 			{field:'channelname',title:'通道名称',hidden:false,width:120},
			{field:'videonum',title:'设备编号',hidden:false,width:120},
			{field:'channelnum',title:'通道编号',hidden:false,width:120},
		]]
	});
}

function getSelectedRows(){
	var rows = $('#tableGrid').datagrid('getChecked'); 
	return rows;
}
//获取选中元素
parent.parent.$(".l-btn-text").on("click",function(){
	if($(this).text()=="关闭"){
		return;
	}
	var insertParam = {};
//	insertParam.channelsetid = channelsetid;
	var rows = $('#tableGrid').datagrid('getChecked'); 
	if(rows && rows.length>0){
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'nhywjtssxcsbAction!batch_add_Nhywjtssxcsb.do',
			data:{xcdh:xcdh,xcsblx:"0",param:JSON.stringify(rows)},
			success:function(value){
				if(value=="success"){
					$.showMsg("操作成功！");
					top.$("#"+winId).dialog('close');
					top.$("#"+winId).panel("options").data = true;
				}else if(value=="same"){
					$.showMsg("已存在！");
				}else{
					$.showMsg("操作失败！");
				}
			}
		});
	}
//	top.$("#"+winId).panel("options").data.insertParam = insertParam;
//	top.$("#"+winId).panel("options").data.channelsetid = channelsetid;
	
	
	
});
//查询
function doSearch(){	
	$('#tableGrid').datagrid('load',getQueryParams());
}
//保存
function saveNodeInfo(){
	var win		=	$.getTopWindowById(windowId);
	var jq		=	win.$;
	var model   =   $.getFormValues("childform",windowId);
	console.log(model);
	if(!win.$('#childform').form('enableValidation').form('validate')){
      return;
	}
	if(toEdit){//修改
		model.XGTJxh = jq('#xh').val();

		//model.checkparam = " and xh='"+model.xh+"' ";
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'sbtdspsrAction!update_Sbtdspsr.do',
			data:model,
			success:function(value){
				if(value=="success"){
					$.showMsg("操作成功！");
					top.$("#"+windowId).dialog('close');
					doSearch();
				}else if(value=="same"){
					$.showMsg("已存在！");
				}else{
					$.showMsg("操作失败！");
				}
			}
		});
	}else{
		//model.checkparam = " and xh='"+model.xh+"' ";
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'sbtdspsrAction!insert_Sbtdspsr.do',
			data:model,
			success:function(value){
				if(value=="success"){
					$.showMsg("操作成功！");
					top.$("#"+windowId).dialog('close');
					doSearch();
				}else if(value=="same"){
					$.showMsg("已存在！");
				}else{
					$.showMsg("操作失败！");
				}
			}
		});
	}
}
