<%--
  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 login_id = (String) session.getAttribute("session_login_id");
    if ("".equals(login_id)) {
        System.out.println("当前没有用户信息");
    }
    String role_id = pub.trimNull(request.getParameter("role_id"));
    StringBuffer sql = new StringBuffer();
    sql.append("select t2.id,t2.user_name,t2.tel,t2.gh,t2.order_num,t2.role_num from zb_role_user t1 join zb_bgs_user t2 on " +
            "t1.user_id=t2.id where t1.role_id=? order by t2.order_num asc ");
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doQuery(conn, sql.toString(), null, new Object[]{role_id});
%>
<div >
    <a class="btn btn-primary " onclick="addUser('<%=role_id%>');">
        包含人员</a>
</div>
<table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
    <tr class="text-c">
        <th width="100">姓名</th>
        <th width="50">电话号码</th>
        <th width="120">工号</th>
        <th width="120">角色内排序</th>
        <th width="50">操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        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 user_id = pub.trimNull((String) ht.get("id"));
                String user_name = pub.trimNull((String) ht.get("user_name"));
                String tel = pub.trimNull((String) ht.get("tel"));
                String gh = pub.trimNull((String) ht.get("gh"));
                String role_num = pub.trimNull((String) ht.get("role_num"));
    %>
    <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
        <td><%=user_name%>
        </td>
        <td><%=tel%>
        </td>
        <td><%=gh%>
        </td>
        <td>
            <input type="text" style="width:120px;" class="input-text" name="role_num_<%=i+1%>" id="role_num_<%=i+1%>" value="<%=role_num%>" >
        </td>
        <td>
            <a  onclick="optOrder('<%=user_id%>','<%=role_id%>','role_num_<%=i+1%>');" style="padding:4px 0px;font-size:12px;">
                设置排序</a>
        </td>
    </tr>
    <%
            }
        }
    %>
    </tbody>
</table>

<script type="text/javascript">
    function deleteUser(user_id){
      layer.confirm('确认要删除吗？', function (index) {
			$.ajax({
				type: "POST",
				url: "./action.jsp?user_id="+user_id+"&action=delete",
				success: function (msg) {
					if (msg.indexOf("success") >= 0) {
						layer.msg('操作成功!', {icon: 1, time: 1000},
							function () {
								searchModel();
							});
					} else {
						layer.msg('操作失败', {
							icon: 5,
							time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function () {
							// console.log("********************8")
						});
					}
				}
			});
		})
    }
    function optOrder(user_id,role_id,inputId){
        var roleNum=$("#"+inputId).val();
        $.ajax({
            type: "post",
            url: "action.jsp?action=optRoleNum&user_id="+user_id+"&role_num="+roleNum,
            success: function (data) {
                if (data.indexOf("success") >= 0) {
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            //searchModel();
                            parent.searchModel1(role_id);
                        });
                } else {
                    layer.msg('操作失败，'+data, {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // console.log("********************8")
                    });
                }
            }
        });
    }
</script>
<%
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>