<%--
  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" %>
<%@ page import="com.censoft.db.Logger" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    Vector v_list_day = null;
    String user_names ="";
    String login_id = (String) session.getAttribute("session_login_id");
    if ("".equals(login_id)) {
        System.out.println("当前没有用户信息");
    }
    String page_number = pub.trimNull(request.getParameter("page_number"));
    String zb_type = pub.trimNull(request.getParameter("zb_type"));
    String day_id = pub.trimNull(request.getParameter("day_id"));
    String mx_id = pub.trimNull(request.getParameter("mx_id"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    if ("".equals(page_size)) page_size = "10";
    StringBuffer sql = new StringBuffer();
    List list = new ArrayList();
    sql.append("select t2.id,t2.user_name,t2.tel,t2.gh,t2.order_num from zb_role_user t1 join zb_bgs_user t2 on " +
            "t1.user_id=t2.id join zb_role t3 on t1.role_id=t3.id where t3.role_name=? order by t2.id desc ");
    list.add(zb_type);
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doPageQueryWithCount(conn, sql.toString(), page_number, page_size, null, list.toArray());
        if (v_list == null) {
            out.println("查询用户出错");
            return;
        }
        v_list_day = cf.doQuery(conn, "select user_name from zb_mx_day where id=?", null, new Object[]{day_id});
        if (v_list_day != null && v_list_day.size()>0) {
            Hashtable ht1= (Hashtable) v_list_day.get(0);
            user_names = pub.trimNull((String) ht1.get("user_name"));
        }
        Hashtable ht_row = (Hashtable) v_list.get(0);
        String rowCnt = pub.trimNull((String) ht_row.get("ROWCOUNT"));
%>
<div style="margin-top: 10px;">
    <a class="btn btn-primary radius" onclick="saveGroupForm('<%=mx_id%>');" >
        确定
    </a>
</div>
<form action="selectUser-t.jsp" method="post" id="groupUser" name="groupUser">
    <input type="hidden" name="day_id" id="day_id" value="<%=day_id%>">
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
        <tr class="text-c">
            <th width="30">序号</th>
            <th width="30">
                <input id="checkboxAll" type="checkbox" onclick="checkAll(this);"></input>
            </th>
            <th width="100">人员姓名</th>
            <th width="100">联系电话</th>
            <th width="100">工号</th>
        </tr>
        </thead>
        <tbody id="groupUserInfo">
        <%
            Hashtable ht_1 =null;
            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 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"));
        %>
        <tr class="text-c">
            <td><%=i%>
            </td>
            <td >
                <input type="checkbox" class="info" id="userids" name="userids" value="<%=user_name%>"
                       <%if(user_names.indexOf(user_name)>=0){%>checked="checked"<%}%>/>
            </td>
            <td><%=user_name%>
            </td>
            <td><%=tel%>
            </td>
            <td><%=gh%>
            </td>
        </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
</form>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/pagination.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pagination.js"></script>
<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">
    var checkAll = function (checkbox) {
        $(".info").prop("checked", checkbox.checked);
    }
    function saveGroupForm(mx_id){
        var isChecked=false;
        var us = document.getElementsByName("userids");
        for(var i=0;i<us.length;i++){
            if(us[i].checked){
                isChecked = true;
            }
        }
        if(!isChecked){
            layer.alert("请勾选用户",{icon:5,title:"提示"});
            return false;
        }
        $.ajax({
            type: "POST",
            url: "./action.jsp?action=addUser",
            data: $('#groupUser').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        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) {
            }
        }
    }
%>