<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html >
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>新增模板</title>
	<link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css"
	media="all">
<link rel="stylesheet" href="${ctx}/css/basic.css">
<link rel="stylesheet" href="${ctx}/css/plugin/metroStyle/metroStyle.css">
<link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.css">
<link rel="stylesheet" href="${ctx}/css/plugin/animate/animate.min.css">
<link rel="stylesheet" href="${ctx}/css/plugin/iconfont/iconfont.css">
<link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/dataTables.bootstrap.css">
<link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap-datetimepicker.css">
	<style type="text/css">
		html { overflow: hidden; }
	</style>
</head>
<body class="bg-white">
<div class="left-menu" style="color:#333;top:0;bottom:0;overflow-y:scroll;">
	<div id="tree" class="ztree" style="padding:8px 0px;"></div>
</div>
<div  id="rightContent" style="position:absolute;left:270px;right:20px;top:100px;bottom:0;z-index:1;">
	<div class="layui-form-item layui-form-text" style="width:320px">
		<label class="layui-form-label" style="width:100px">名称</label>
		<div class="layui-input-block">
			<input type="text" id="tPName" placeholder="请输入" autocomplete="off" maxlength="32"
				   class="layui-input">
		</div>
	</div>

	<div class="layui-form-item layui-form-text" style="width:320px">
		<label class="layui-form-label" style="width:100px">描述</label>
		<div class="layui-input-block">
			<input type="text" id="describe" placeholder="请输入" autocomplete="off" maxlength="64"
				   class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block"style="width:320px">
			<button type="button" class="layui-btn themeBGColor" id="addNode" style="margin-left:10px" >提交</button>
			<button type="reset" class="layui-btn cancleBGColor" style="margin-left:45px" id="cancleAdd">取消</button>
		</div>
	</div>
</div>
<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="${ctx}/js/plugin/ztree/jquery.ztree.core.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/jquery.dataTables.min.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/dataTables.bootstrap.min.js"></script>
	<script src="${ctx}/js/plugin/layui/layer.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
	<script src="${ctx}/js/basic.js"></script>
	<script src="${ctx}/js/plugin/ztree/jquery.ztree.excheck.js"></script>
	<script src="${ctx}/js/plugin/xss/xss.js"></script>
	<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
    <script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/jspJS/settings/tfLgPloyTree.js"></script>
<script type="text/javascript">
    $(document).ready(function() {

    });

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

    $("#cancleAdd").click(function(){
        parent.layer.close(index);
    });

    $("#addNode").click(function(){
        var treecheck = [];
        var zTree = jQuery.fn.zTree.getZTreeObj("tree");
        var totalcount = zTree.getCheckedNodes(true).length;
        if (zTree != null) {
            var nodes = zTree.getCheckedNodes(true);
            for ( var i = 0; i < totalcount; i++) {
                if(nodes[i].isParent == true){

                }else{
                    treecheck.push(nodes[i].rd_Index);
                }
            }
        }
        var tPName =$("#tPName").val();
        tPName=filterXSS(tPName);
        var describe =$("#describe").val();
        describe=filterXSS(describe);
        if(treecheck.length == 0){
            layer.msg('暂未选择变压器',{icon:2,time:2000});
		}else if(totalcount < 4){
            layer.msg('暂未选择变压器！',{icon:2,time:2000});
        }else if(tPName==null||tPName==""){
            layer.tips('名称不可为空', '#tPName', {
                tips: [1, 'red'] //还可配置颜色
            });
        }else{
           $.ajax({
                url:'/pqs9900/tflp/addTfLgPloy',
                type:'POST',
                dataType:"text",
                data:{
                	tPName:tPName,
                    describe:describe,
                    treecheck:JSON.stringify(treecheck)
                },
                success:function(data){
                    var info=$.parseJSON(data);
                    if(info.code==200){
                        layer.msg(info.message,{icon:1,time:1000});
                        parent.queryPloy();
                        parent.layer.close(index);
                    }else if(info.code==400){
                        layer.msg(info.message,{icon:2,time:1000});
                    }else{
                        layer.msg(info.message,{icon:2,time:1000});
                    }
                }

            });
        }
    });
</script>
</body>
</html>