$(document).ready(function() {
	load();
})

function load(){
	var heightTemp=screen.height;
	var length;
	if(heightTemp==768){
		length=8;
	}else{
		length=11;
	}
	$.ajax({
		method : "post",
		url : "/pqs9000/devicereport/loadPloyInfo",
		data : {},
		beforeSend: function () {  
            i = ityzl_SHOW_LOAD_LAYER();  
        },
        error:function(data) {
        	alert("暂无数据");
			//***********关闭loading
        	ityzl_CLOSE_LOAD_LAYER(i); 
        },
		success : function(data) {
			var info = JSON.parse(data);
			var table=$('#nodelist').DataTable({
				scrollX : true,
				lengthChange : false,
				destroy : true,
				searching: false,
				
				language : {
					url: '/pqs9000/json/chine.json'
				},
				pageLength:length,
				data : info,
			    "columnDefs" : [ {
			        "targets": 0,
			        "visible": false,
			        "searchable": false
			      },{
//				    // 定义操作列,######以下是重点########
			    	"targets" : 4,//操作按钮目标列
				    "data" : null,
				    "orderable" : false,
			    	"render" : function(row) {
						return null;
			    	}
				    }],
			    "createdRow": function ( row, data, index ) {
			    	$btnExp = $('<button type="button" class="btn btn-danger glyphicon glyphicon-trash btn_exp" id="btn_exp" style="margin-left:10px">删除</button>');
			    	if(data[3] == "正常"){
				    	$('td', row).eq(3).append($btnExp);
			    	}
			    },
			    'fnDrawCallback': function(table) {    
				    $("#nodelist_paginate").append("<div style='float:right;padding-top:4px;padding-left:10px'>到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:28px;'> 页  <button class='btn btn-primary' id='dataTable-btn'>确定</button></div>");    
				    var oTable = $("#nodelist").dataTable(); 
				    $('#dataTable-btn').click(function(e) {
				        if($("#changePage").val() && $("#changePage").val() > 0) {    
				            var redirectpage = $("#changePage").val() - 1;    
				        } else {    
				            var redirectpage = 0;    
				        }    
				        oTable.fnPageChange(redirectpage);
				    });    
				}
			});
			
			table.buttons().container().css("display","inline-block");
			table.buttons().container().css("float","right");
			table.buttons().container().find("a").prepend("<i class='glyphicon glyphicon-share'></i>");
			table.buttons().container().appendTo('.header');			

			//***********关闭loading
        	ityzl_CLOSE_LOAD_LAYER(i); 
		}
	}); 
}

$('#nodelist').on("click", ".btn_exp", function() {
	objTable=$('#nodelist').DataTable();
	if (objTable != null) {
		var item = objTable.row($(this).closest('tr')).data();
		var modelIndex = item[0];
		var modelName = item[1];
		
		layer.confirm('是否确认？',function(){
			$.ajax({
				method : "post",
				url : "/pqs9000/devicereport/delPloyInfo",
				data : {
					modelIndex:modelIndex,
					modelName:modelName
				},
				async:false,
				success : function(data) {
					if(data.code==200){
						layer.msg('删除成功!',{icon:1,time:1000});
						load();
					}else{
						layer.msg('删除失败！',{icon:2,time:1000});
					}
				}
			})
		})
	}
})

$("#addnode").click(function(){
	layer.open({
		  type: 2,
		  title: '上传模板',
		  shadeClose: true,
          offset: '0px',
		  area: ['300px', '160px'],
		  maxmin : false,
		  content: 'upoffploy', 
		  scrollbar: false,
		  end:function(){
			  load();
		  }
		});
})