<%@ page import="com.censoft.db.DBUtil" %>
<%@ include file="../getMenuList.jsp"%>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
	Vector v_list_1 = null;
    String page_number = pub.trimNull(request.getParameter("page_number"));
	String s_id = pub.trimNull((String) session.getAttribute("session_login_id"));
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        String sql = "select * from t_book_dept  order by dept_order asc";
        v_list = cf.doQuery(conn, sql, null, new Object[]{});
        if (v_list == null) {
            out.println("查询角色出错");
            return;
        }
		String sql_1 = "select * from t_book_dept where length(id)<32";
        v_list_1 = cf.doQuery(conn, sql_1, null, new Object[]{});
        if (v_list_1 == null) {
            out.println("查询角色出错");
            return;
        }
    } catch (Exception e) {
        out.println("查询角色信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/pagination.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pagination.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/zTree/v3/css/zTreeStyle/zTreeStyle.css"
      type="text/css">
<%--<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> <%=menu_name%>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                               href="javascript:void(0);" onclick="window.location.reload();"
                                               title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>--%>
<style>
    body{
       /* background-color: #fff;*/
    }
</style>
<div class="page-container">
        <div style="width:100%;height:30px;margin-top:20px;margin-left: 10px;" id="dept_div"></div>
        <div class="left-tree" style="top:15%;">
            <div class="tree-div">
                <ul id="treeDemo" class="ztree" ></ul>
            </div>
        </div>
        <div class="right-contant" style="top:15%;">
        <form action="memberlist_ajax.jsp" method="post" id="data_form_search" >
            <input type="hidden" name="page_number" id="page_number" value="1"/>
            <input type="hidden" name="dept_id" id="dept_id" value=""/>
            <div class="text-r">
				<%if(!"".equals(s_id)&&"admin".equals(s_id)){%>
					<input class="btn btn-primary radius" type="button"  value="&nbsp;&nbsp;共有机构<%=v_list_1.size()%>个&nbsp;&nbsp;">
				<%}%>
                <input type="text" class="input-text" style="width:100px" placeholder="输入" name="s_login_name">
                <button type="button" onclick="document.getElementById('page_number').value='1';searchModel();"
                        class="btn btn-success radius" id="aaa" name=""><i class="Hui-iconfont">&#xe665;</i>
                    搜用户
                </button>
                <a
                        href="javascript:;" name="tjgly" onclick="member_add('添加管理员','./member_add-t.jsp','800','500')"
                        class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a>
            </div>
        </form>

        <div class="mt-20" id="datalist">

        </div>
    </div>
</div>

<script type="text/javascript">
    searchModel();

    function searchModel() {
        //   alert(document.getElementById("page_number").value)
        $.ajax({
            type: "post",
            url: "memberlist_ajax.jsp",
            data: $('#data_form_search').serialize(),
            success: function (msg) {
                $("#datalist").html(msg);
                //changeBtn();
            }
        });
    }

    /*用户-添加*/
    function member_add(title, url, w, h) {
        var dept_id = document.getElementById("dept_id").value;
        url +="?dept_id="+dept_id;
        var abc = layer_show(title, url, w, h);
    }

    /*用户-查看*/
    function member_show(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*用户-编辑*/
    function member_edit(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*密码-修改*/
    function change_password(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: './member_add-t.jsp?action=delete&id=' + id,
                success: function (data) {
                    layer.msg('已删除!', {
                        icon: 1, time: 1000
                    }, function () {
                        searchModel();
                    });
                },
                error: function (data) {
                    layer.msg('删除失败!', {
                        icon: 1, time: 1000
                    });
                },
            });
        });
    }
</script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
    var setting = {
        view: {
            dblClickExpand: false,
            showLine: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj("tree");
                if (treeNode.isParent) {
                    getDept(treeNode.id);
                    return false;
                } else {
                    getDept(treeNode.id);
                    return true;
                }
            }
        }
    };
    getDept("","");
    function getDept(id,p_id){
        document.getElementById("dept_id").value = id;
        searchModel();
        $.ajax({
            type: "post",
            url: "./dept_ajax.jsp?p_id="+p_id+"&id="+id,
            success: function (msg) {
                $("#dept_div").html(msg);
               // changeBtn();
            }
        });
    }
    var zNodes = [
        <%
        if (v_list != null && v_list.size() > 0) {
        for (int i = 0; i < v_list.size(); i++) {
            Hashtable ht = (Hashtable) v_list.get(i);
            String dept_name = pub.trimNull((String) ht.get("dept_name"));
            String id = pub.trimNull((String) ht.get("id"));
            String p_id = pub.trimNull((String) ht.get("p_id"));
        %>
        {id: "<%=id%>", pId: "<%=p_id%>", name: "<%=dept_name%>", open: false},
        <%}}%>
    ];

    var code;

    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>" + str + "</li>");
    }

    $(document).ready(function () {
        var t = $("#treeDemo");
        t = $.fn.zTree.init(t, setting, zNodes);
        demoIframe = $("#testIframe");
        var zTree = $.fn.zTree.getZTreeObj("tree");
    });
</script>