<%@ 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}/css/plugin/bootstrap/bootstrap.min.css">
	<link rel="stylesheet" href="${ctx}/css/plugin/metroStyle/metroStyle.css">
	<link rel="stylesheet" href="${ctx}/css/plugin/datatables/datatables.bootstrap.css">
	<link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctx}/css/basic.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:0;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="name" placeholder="请输入" autocomplete="off" maxlength="64"
				   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.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.core.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.excheck.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}/jspJS/report/areaPloyTree.js"></script>
<script src="${ctx}/js/basic.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script src="${ctx}/js/plugin/xss/xss.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    	getTree();
    });

    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");
        if (zTree != null) {
            var totalcount = zTree.getCheckedNodes(true).length;
            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 name =$("#name").val();
        name=filterXSS(name);
        var describe =$("#describe").val();
        describe=filterXSS(describe);
        if(name==null||name==""){
            layer.tips('名称不可为空', '#name', {
                tips: [1, 'red'] //还可配置颜色
            });
        }else if(describe==null||describe==""){
            layer.tips('描述不可为空', '#describe', {
                tips: [1, 'red'] //还可配置颜色
            });
        }else if(treecheck.length == 0){
            layer.tips('请至少选择一个配置项', '#tree', {
                tips: [1, 'red'] //还可配置颜色
            });
        }else{
            $.ajax({
                url:'/pqs9900/report/addareaPloy',
                type:'POST',
                dataType:"text",
                data:{
                    name:name,
                    describe:describe,
                    treecheck:JSON.stringify(treecheck)
                },
                success:function(data){
                    var info=$.parseJSON(data);
                    if(info.code==200){
                        layer.msg('添加成功!',{icon:1,time:1000});
                        window.parent.location.reload();//刷新父页面
                        parent.layer.close(index);
                    }else if(info.code==400){
                        layer.msg('添加失败！名称已存在',{icon:2,time:1000});
                    }else{
                        layer.msg('添加失败！',{icon:2,time:1000});
                    }
                }

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