<%--
  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="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;
    String role_id = pub.trimNull(request.getParameter("role_id"));
    String action = pub.trimNull(request.getParameter("action"));
    Hashtable ht = new Hashtable();
    StringBuffer sql = new StringBuffer();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        if("update".equals(action)){
            sql.append("select * from zb_role where id=?");
            v_list = cf.doQuery(conn, sql.toString(), null, new Object[]{role_id});
        }
        if (v_list!=null&&v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
        }
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<style>
    .col-sm-2{
        width:14%;
    }
    .col-sm-3{
        width:19%;
    }
    .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="<%=role_id%>" name="role_id" id="role_id">
        <div id="content" 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">
                    <span class="c-red">*</span>角色名称&nbsp;：
                </label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" name="role_name" id="role_name" value="<%=pub.trimNull((String)ht.get("role_name"))%>" >
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>排序&nbsp;：
                </label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" name="order_num" id="order_num" value="<%=pub.trimNull((String)ht.get("order_num"))%>" >
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>备注&nbsp;：
                </label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" style="height:80px;line-height: 5px;" class="input-text" name="beizhu" id="beizhu" value="<%=pub.trimNull((String)ht.get("beizhu"))%>" >
                </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>

    function LayerOpen(title, url, w, h) {
        if($("#user_id").val()==''){
            layer.alert("请先保存用户再添加相关人员",{icon:5,title:"提示"});
            return false;
        }
        var abc = layer.open({
            title:title,
            type: 2,
            content: url,
            area: [w, h],
            maxmin: true
         });
        layer.full(abc);
    }
    function viewDeptOrUserInfo(title, url, w, h) {
        location.href=url;
    }
    function saveForm() {
        if($("#role_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 role_id = msg.substring(msg.indexOf(",")+1,msg.length);
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            //parent.searchModel();
                            parent.document.getElementById("check_role_id").value=role_id;
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // console.log("********************8")
                    });
                }
            }
        });
    }
    function deleteUser(user_id,p_user_id){
        layer.confirm('确认要删除吗？', function (index) {
			$.ajax({
				type: "POST",
				url: "./action.jsp?&p_user_id="+p_user_id+"&user_id="+user_id+"&action=delete",
				success: function (msg) {
					if (msg.indexOf("success") >= 0) {
						layer.msg('操作成功!', {icon: 1, time: 1000},
							function () {
								location.reload();
								if(rel_user_id!=''){
									window.parent.location.reload();
								}
								parent.searchModel();
							});
					} else {
						layer.msg('操作失败', {
							icon: 5,
							time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function () {
							// console.log("********************8")
						});
					}
				}
			});
		});
    }
</script>