
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    Vector v_roles=null;
    String action = pub.trimNull(request.getParameter("action"));
    String user_id = pub.trimNull(request.getParameter("user_id"));
    Hashtable ht = new Hashtable();
    StringBuffer sql = new StringBuffer();
    int order_num=1;
    String have_roles="";
    String add_user = pub.trimNull((String) session.getAttribute("session_login_id"));
    if ("".equals(add_user)) {
        System.out.println("当前没有用户信息");
    }
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        Vector maxOrder = cf.doQuery(conn, "select max(order_num) as order_num from zb_user", null, new Object[]{});
        if("update".equals(action)){
            sql.append("select * from zb_user where id=?");
            v_list = cf.doQuery(conn, sql.toString(), null, new Object[]{user_id});
        }
        if (v_list!=null&&v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
            order_num = Integer.parseInt(pub.trimNull((String)ht.get("order_num")));
        }else{
            Hashtable ht_order = (Hashtable) maxOrder.get(0);
            if("".equals(pub.trimNull((String)ht_order.get("order_num")))){
                order_num=1;
            }else{
                order_num = Integer.parseInt(pub.trimNull((String)ht_order.get("order_num")))+1;
            }
        }
        if(!"".equals(add_user)){
            v_roles = cf.doQuery(conn, "select * from t_book_user_role_rel where login_id=?", null, new Object[]{user_id});
            if(v_roles!=null&& v_roles.size()>0){
                have_roles = v_roles.toString();
            }
        }
        v_roles = cf.doQuery(conn, "select * from t_book_role order by add_time asc", null, new Object[]{});

    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<style>
    .input-three {
        width: 22%
    }
    .input-two {
        width: 32%
    }
    .col-sm-2{
        width:34%;
    }
    .col-sm-3{
        width:34%;
    }
    .input-text{

    }
    .btn-red{ background-color:red;border: red}
    .btn-green{ background-color:green;border: green}


</style>
<div class="">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" value="<%=action%>" name="action" id="action">
        <input type="hidden" value="<%=user_id%>" name="user_id" id="user_id">
        <input type="hidden" value="<%=pub.trimNull((String)ht.get("user_name"))%>" id="userName">
        <div class="cl pd-5  bk-gray divOverflow" style="overflow:hidden;margin-bottom: 20px;">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">人员姓名：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="user_name" id="user_name"  value="<%=pub.trimNull((String)ht.get("user_name"))%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">电话号码：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="tel" id="tel"  value="<%=pub.trimNull((String)ht.get("tel"))%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">工号：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="gh" value="<%=pub.trimNull((String)ht.get("gh"))%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">登陆密码：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="pwd" value="<%=pub.trimNull((String)ht.get("pwd"))%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">序号：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="order_num" value="<%=order_num%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">角色：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <%
                        if (v_roles != null && v_roles.size() > 0) {
                            for (int i = 0; i < v_roles.size(); i++) {
                                Hashtable ht_role = (Hashtable) v_roles.get(i);
                                String role_id = pub.trimNull((String) ht_role.get("id"));
                                String role_name = pub.trimNull((String) ht_role.get("role_name"));
                    %>
                    <input type="checkbox" name="role_ids" value="<%=role_id%>"
                           <%if(have_roles.indexOf(role_id)>0){%>checked<%}%>  /><%=role_name%>
                    <%
                            }
                        }
                    %>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="cl mb-10  bk-gray " style="height: 50px;">
    <div class="col-sm-3 pd-10" style="width:100%;text-align: center;">
        <input class="btn btn-primary radius btn-green" type="button" onclick="javascript:saveForm();" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
    </div>
</div>
<script src="<%=request.getContextPath()%>/js/Convert_Pinyin.js"></script>
<script>
    function viewDeptOrUserInfo(title, url, w, h) {
        location.href=url;
    }
    function saveForm() {
        if($("#user_name").val()==''){
            layer.alert("用户名称不能为空",{icon:5,title:"提示"});
            return false;
        }
        $.ajax({
            type: "POST",
            url: "./action.jsp",
            data: $('#form-admin-add').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    var user_id=msg.substring(msg.indexOf(",")+1,msg.length);
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            parent.searchModel();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    });
                }
            }
        });
    }
</script>