<%@ page contentType="text/html;charset=UTF-8" %>
<%@ 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;
    String id = request.getParameter("id");
    String userid = request.getParameter("userid");
    Vector v_list=null;
    String dept_id="";
    try {

        conn = com.censoft.db.DBUtil.getConnection();
        String sql="select dept_id from t_book_admin where login_id=?";
        v_list = cf.doQuery(conn, sql, null, new Object[]{userid});
        if (v_list == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }
        if(v_list.size()>0){
            Hashtable ht = (Hashtable)v_list.get(0);
            dept_id=pub.trimNull((String)ht.get("dept_id"));
        }
    } 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">
<div class="page-container">
    <div class="left-tree" style="width:20%;">
        <div class="tree-div">
            <ul id="treeDemo" class="ztree" ></ul>
        </div>
    </div>
    <div class="right-contant" style="width:78%;float:right;">
        <div class="search-form">
            <form action="right_user_list.jsp" method="post" id="data_form_search" name="data_form_search">
                <input type="hidden" name="dept_id" id="dept_id" value=""/>
                <input type="hidden" name="id" id="id" value="<%=id%>"/>
                <input type="hidden" name="userid" id="userid" value="<%=userid%>"/>
            </form>
        </div>
        <div class="datalist mt-20 " id="datalist">

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

<script type="text/javascript" src="<%=request.getContextPath()%>/js/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
    var detpId='<%=dept_id%>';
    function queren(id) {
        var val=$('input:radio[name="radio_single"]:checked').val();
        if(val==null){
            layer.msg('没有选中用户', {
                icon: 5,
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            }, function () {
            });
            return false;
        }
        else{
            parent.document.getElementById(id).value=val.substring(0,val.indexOf("_"));
            parent.document.getElementById(id+"_1").value=val.substring(val.indexOf("_")+1,val.length);
        }
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function searchModel() {
            $.ajax({
                type: "post",
                url: "right_user_list.jsp",
                data: $('#data_form_search').serialize(),
                success: function (msg) {
                    $("#datalist").html(msg);
                }
            });
    }

    var setting = {
        view: {
            dblClickExpand: false,
            showLine: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                document.getElementById("dept_id").value = treeNode.id;
                searchModel();
            }
        }
    };
    var zNodes = "";
    function searchDept() {
        $.ajax({
            type: "post",
            url: "./list_dept_ajax.jsp",
            data: $('#data_form_search').serialize(),
            success: function (data) {
                zNodes = data;
                var t = $("#treeDemo");
                t = $.fn.zTree.init(t, setting, zNodes);
                if(detpId!=''){
                    document.getElementById("dept_id").value=detpId;
                    t.selectNode(t.getNodeByParam("id",detpId,null));
                    searchModel();
                }
            }
        });

    }
    searchDept();
</script>