<%--
  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_login_name = pub.trimNull(request.getParameter("s_login_name"));
    String s_dept_id = pub.trimNull(request.getParameter("dept_id"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    if ("".equals(page_size)) page_size = "10";
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        StringBuffer sb = new StringBuffer();
        List list = new ArrayList();
        sb.append("select t1.*  from t_book_admin t1  where (is_sys!='yes' or is_sys is null)  ");
        if(!"".equals(s_login_name)){
            sb.append(" and  t1.login_name like ?");
            list.add("%"+s_login_name+"%");
        }
        if(!"".equals(s_dept_id)){
            sb.append(" and t1.dept_id like ?");
            list.add("%"+s_dept_id+"%");
        }
        sb.append("  order by t1.add_time desc ");
        v_list = cf.doPageQueryWithCount(conn, sb.toString(), page_number, page_size, null, list.toArray());
        if (v_list == null) {
            out.println("查询用户出错"+cf.getMsg());
            return;
        }else{
            for(int i=0;i<v_list.size();i++){
                Hashtable ht = (Hashtable)v_list.get(i);
                Vector v_roles = cf.doQuery(conn,"select * from t_book_role t1 join t_book_user_role_rel t2 on t1.id=t2.role_id where t2.login_id=? order by t1.add_time asc",null,new Object[]{""+ht.get("login_id")});
                ht.put("roles",v_roles);
            }
        }
    } 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"));
%>
<div class="table-list" style="height:500px;overflow-y:auto;">
<table class="table table-hover table-bg table-sort">
    <thead>
    <tr class="text-c">
        <th width="80">姓名</th>
        <th width="80">帐号</th>
        <th width="120">角色</th>
        <th width="50">级别</th>
        <th width="90">状态</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 login_name = pub.trimNull((String) ht.get("login_name"));
                String login_id = pub.trimNull((String) ht.get("login_id"));
                Vector v_roles  = (Vector)ht.get("roles");
                String add_time = pub.trimNull((String) ht.get("add_time"));
                String status = pub.trimNull((String) ht.get("status"));
                String user_level = pub.trimNull((String) ht.get("user_level"));
                if("".equals(user_level))user_level="普通";
                String id = pub.trimNull((String) ht.get("id"));
    %>
    <tr class="text-c" <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%>>
        <td><%=login_name%></td>
        <td><%=login_id%>
        </td>
        <td>
            <%
                if (v_roles != null && v_roles.size() > 0) {
                    for (int j = 0; j < v_roles.size(); j++) {
                        Hashtable ht_role = (Hashtable) v_roles.get(j);
                        String role_id = pub.trimNull((String) ht_role.get("id"));
                        String role_name = pub.trimNull((String) ht_role.get("role_name"));
            %>
            <%=role_name%>;
            <%
                    }
                }
            %>
        </td>
        <td><%=user_level%>
        </td>
        <td class="td-status">
            <%if ("00".equals(status)) {%>
            <span class="label label-success radius">启用</span>
            <%} else {%>
            <span class="label   radius">禁用</span>
            <%}%>
        </td>
        <td class="td-manage">
            <a style="text-decoration:none" class="ml-5" name="changepass" onClick="change_password('修改密码','change_password-t.jsp?id=<%=id%>','10001','600','270')" href="javascript:;" title="修改密码"><i class="Hui-iconfont">修改密码</i></a>
            <a
                title="编辑" href="javascript:;" name="updatedata" onclick="member_edit('编辑','./member_add-t.jsp?action=toupdate&id=<%=id%>','800','','500')"
                class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">编辑</i></a>
            <a title="删除" name="deletedata" href="javascript:;" onclick="member_del(this,'<%=id%>')" class="ml-5"
               style="text-decoration:none"><i
                    class="Hui-iconfont">删除</i></a></td>
    </tr>
    <%
            }
        }
    %>
    </tbody>
</table>
</div>
<jsp:include page="../common/page_ajax.jsp" >
    <jsp:param name="page_number" value="<%=page_number%>" />
    <jsp:param name="rowCnt" value="<%=rowCnt%>" />
    <jsp:param name="page_size" value="<%=page_size%>" />
</jsp:include>
<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>