<%@ 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.
--%>
<%--
  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;
    String page_number = pub.trimNull(request.getParameter("page_number"));
    String s_role_name = pub.trimNull(request.getParameter("s_role_name"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    if ("".equals(page_size)) page_size = "4";
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        String sql = "select * from t_book_menu  order by menu_order asc";
        v_list = cf.doQuery(conn, sql, null, new Object[]{});
        if (v_list == 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()%>/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:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<table class="table">
    <tr>
        <td width="200" class="va-t">
            <ul id="treeDemo" class="ztree"></ul>
        </td>
        <td class="va-t">
            <iframe ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=no width=100% height=390px
                    SRC="./menu_add-t.jsp?menu_id=<%=request.getParameter("menu_id")%>"></iframe>
        </td>
    </tr>
</table>
<!--_footer 作为公共模版分离出去-->
<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) {
                    demoIframe.attr("src", "./menu_add-t.jsp?menu_id=<%=request.getParameter("menu_id")%>&id=" + treeNode.id);
                    return false;
                } else {
                    demoIframe.attr("src", "./menu_add-t.jsp?menu_id=<%=request.getParameter("menu_id")%>&id=" + treeNode.id);
                    return true;
                }
            }
        }
    };

    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 menu_name_1 = pub.trimNull((String) ht.get("menu_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: "<%=menu_name_1%>", open: true},
        <%}}%>
    ];

    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>