<%--
  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_role where role_name like ? order by add_time desc";
        v_list = cf.doPageQueryWithCount(conn, sql, page_number, page_size, null, new Object[]{"%" + s_role_name + "%"});
        if (v_list == null) {
            out.println("查询角色出错");
            return;
        }
    } catch (Exception e) {
        out.println("查询角色信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
    Hashtable ht_row = (Hashtable) v_list.get(0);
    String rowCnt = pub.trimNull((String) ht_row.get("ROWCOUNT"));
    String pageCnt = pub.trimNull((String) ht_row.get("PAGECOUNT"));
%>
<table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
    <tr class="text-c">
        <th width="25">序号</th>
        <th width="200">角色名称</th>
        <th width="">备注</th>
        <th width="130">添加时间</th>
        <th width="100">操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        if (v_list != null && v_list.size() > 0) {
            for (int i = 1; i < v_list.size(); i++) {
                Hashtable ht = (Hashtable) v_list.get(i);
                String role_name = pub.trimNull((String) ht.get("role_name"));
                String login_id = pub.trimNull((String) ht.get("login_id"));
                String add_time = pub.trimNull((String) ht.get("add_time"));
                String status = pub.trimNull((String) ht.get("status"));
                String bz = pub.trimNull((String) ht.get("bz"));
                String id = pub.trimNull((String) ht.get("id"));
    %>
    <tr class="text-c">
        <td><%=i%>
        </td>
        <td><%=role_name%>
        </td>
        <td><%=bz%>
        </td>
        <td><%=add_time%>
        </td>
        <td class="td-manage">
            <a
                    title="编辑" href="javascript:;" onclick="member_edit('编辑','./role_add-t.jsp?action=toupdate&id=<%=id%>','800','','500')"
                    class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
            <a title="删除" href="javascript:;" onclick="member_del(this,'<%=id%>')" class="ml-5"
               style="text-decoration:none"><i
                    class="Hui-iconfont">&#xe6e2;</i></a></td>
    </tr>
    <%
            }
        }
    %>
    </tbody>
</table>

<div class="page" style="margin-top:30px;">
    <div id="Pagination"></div>
</div>
<script type="text/javascript">
    $(function () {//页面加载时，进行绑定
        bind(0);
    });

    //点击分页时调用的函数，page_id为当前页的索引
    function pageselectCallback(page_id, jq) {
        document.getElementById("page_number").value = page_id + 1;
        searchModel();
    }

    function bind(pageIndex) {
        var temp = "";
        var total = <%=rowCnt%>;
        if (total != 0) {
            $("#Pagination").pagination(total, {
                callback: pageselectCallback, //点击分页时，调用的回调函数
                prev_text: '« 上一页', //显示上一页按钮的文本
                next_text: '下一页 »', //显示下一页按钮的文本
                items_per_page: <%=page_size%>, //每页显示的项数
                num_display_entries: 6, //分页插件中间显示的按钮数目
                current_page: <%=page_number%>-1, //当前页索引
                num_edge_entries: 1
            });
        }

    }
</script>