<%@ 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();

%>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/pagination.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pagination.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/zTree/v3/css/zTreeStyle/zTreeStyle.css"
      type="text/css">
<div class="page-container">
    <div class="left-tree">
        <button class="btn btn-success" onclick="optMx('add');" style="text-align:center;float:left;">
            新建</button>
        <button class="btn btn-success" onclick="updateMx();" style="text-align:center;float:left;margin-left: 20px;">
            修改</button>
        <button class="btn btn-success" onclick="delMx();" style="text-align:center;float:right;">
            删除</button>
        <input type="hidden" name="check_role_id" id="check_role_id">
        <div id="deptinfo" class="deptinfo" style="width:100%;">
        </div>
    </div>
    <div class="right-contant" >
        <div id="datalist">
        </div>
    </div>
</div>
</div>
<script type="text/javascript">
    searchModel();
    function searchModel() {
        $.ajax({
            type: "post",
            url: "left_list.jsp",
            //data: $('#data_form_search').serialize(),
            success: function (msg) {
                $("#deptinfo").html(msg);
            }
        });
    }
    function searchModel1(role_id) {
        $.ajax({
            type: "post",
            url: "right_list.jsp?number="+Math.random()+"&role_id="+role_id,
            success: function (msg) {
                $("#datalist").html(msg);
                $("#li_"+role_id).css("backgroundColor","#cccccc");
            }
        });
    }
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            searchModel();
        }
    });
    function addUser(role_id) {
        if(role_id==''){
            layer.alert("请选择角色", {icon: 5, title: "提示"});
            return false;
        }
        var url = './selectUser-t.jsp?role_id='+role_id;
        viewDeptOrUserInfo('设置包含信息', url, '1000', '500');
    }
    function optMx(type) {
        var url = './edit-t.jsp?action='+type;
        viewDeptOrUserInfo('新建角色', url, '1000', '500');
    }
    function updateMx(){
        var role_id=$("#check_role_id").val();
        if(role_id==''){
            layer.alert("请选择角色", {icon: 5, title: "提示"});
            return false;
        }
        var url = './edit-t.jsp?action=update&role_id='+role_id;
        viewDeptOrUserInfo('修改角色', url, '1000', '500');
    }
    function delMx(){
        var mx_id=$("#check_role_id").val();
        if(mx_id==''){
            layer.alert("请选择模型", {icon: 5, title: "提示"});
            return false;
        }
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: "POST",
                url: "./action.jsp?mx_id="+mx_id+"&action=delete",
                success: function (msg) {
                    if (msg.indexOf("success") >= 0) {
                        layer.msg('操作成功!', {icon: 1, time: 1000},
                            function () {
                                searchModel();
                                window.location.reload();
                            });
                    } else {
                        layer.msg('操作失败', {
                            icon: 5,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            // console.log("********************8")
                        });
                    }
                }
            });
        });
    }
    function viewDeptOrUserInfo(title, url, w, h) {
        var abc = layer.open({
            title: title,
            type: 2,
            content: url,
            area: [w+'px', h+'px'],
            maxmin: true,
            end:function () {
                searchModel();
                openLi($("#check_role_id").val());
            }
        });
        //layer.full(abc);
    }
    function openLi(role_id) {
        $("#check_role_id").val(role_id);
        $("#leftMx ul li").each(function(){
            $(this).css("backgroundColor","#e0e4f6");
        })
        $("#li_"+role_id).css("backgroundColor","#cccccc");
        searchModel1(role_id);
    }
    function editUser(day_id,mx_id) {
        var url = './selectUser-t.jsp?day_id='+day_id+"&mx_id="+mx_id;
        var abc = layer.open({
            title: '选择人员',
            type: 2,
            content: url,
            area: ['1000px', '500px'],
            maxmin: true,
            end:function () {
                searchModel1($("#check_role_id").val());
            }
        });
    }

</script>