<%@ page contentType="text/html;charset=UTF-8" %>
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/pagination.css">
<div class="page-container">
        <div class="left-tree">
            <div class="panel-header">
                组织机构
            </div>
            <div class="tree-div">
                <ul id="treeDemo" class="ztree" ></ul>
            </div>
        </div>
        <div style="height:10px;background-color: #d9e4f6">
        </div>
        <div class="right-content" >
            <div class="search-form">
                <form  method="post" id="data_form_search" name="data_form_search">
                    <input type="hidden" name="page_number" id="page_number" value="1"/>
                    <input type="hidden" name="zd_id" id="zd_id" value=""/>
                    <input type="hidden" name="page_size" id="page_size" value="10"/>
                </form>
            </div>
            <div class="datalist " id="datalist">
            </div>
        </div>
</div>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
    function searchDept() {
        var setting = {
            view: {
                dblClickExpand: false,
                showLine: false,
                selectedMulti: false
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: ""
                }
            },
            callback: {
                onClick: function (event, treeId, treeNode) {
                    $("#zd_id").val(treeNode.id);
                    searchModel();
                }
            }
        };
        $.ajax({
            type: "post",
            url: "./dept_tree_ajax.jsp",
            success: function (data) {
                if (data != null && data.length == 0) {

                } else {
                    $.fn.zTree.init($("#treeDemo"), setting, data);
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo");//获取ztree对象
                    var node = zTree.getNodes()[0];//获取id为1的点
                    zTree.selectNode(node);//选择点
                    zTree.setting.callback.onClick(null, zTree.setting.treeId, node);//调用事件
                }


            }
        });
    }
    function searchModel() {
        $.ajax({
            type: "post",
            url: "zd_col_list_ajax.jsp",
            data: $('#data_form_search').serialize(),
            success: function (msg) {
                $("#datalist").html(msg);
            }
        });
    }
    function searchUserModel() {
        $("#page_number").val("1");
        searchModel();
    }
    $(function(){
        //searchModel();
        searchDept();
    });

    function chongzhi(){

        $("#page_size").val("10");
        data_form_search.reset();
        searchUserModel();
    }


    /*用户-编辑*/
    function addRules(title, url) {
        layer_show(title, url, "800", "500");
    }
    function updateById(id,zd_id){
        layer_show("编辑", "./zd_col_add-t.jsp?update_id="+id+"&zd_id="+zd_id, "800", "500");
    }
    function deleteById(id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: "POST",
                url: "./action_col.jsp",
                data: {"action":"delete","delete_id":id},
                success: function (msg) {
                    if (msg.indexOf("success") >= 0) {
                        layer.msg('操作成功!', {icon: 1, time: 1000},
                            function () {
                                searchModel();
                            });
                    } else {
                        layer.msg('操作失败', {
                            icon: 5,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                        });
                    }
                }
            });
        })
    }
</script>