<%@ 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">
<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: 10px;">
            修改</button>
        <button class="btn btn-success" onclick="delMx();" style="text-align:center;float:right;">
            删除</button>
        <input type="hidden" name="check_mx_id" id="check_mx_id">
        <input type="hidden" name="check_mx_day" id="check_mx_day">
        <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(mx_id) {
        $.ajax({
            type: "post",
            url: "right_list.jsp?number="+Math.random()+"&mx_id="+mx_id+"&day="+$("#check_mx_day").val(),
            success: function (msg) {
                $("#datalist").html(msg);
                $("#li_"+mx_id).css("backgroundColor","#cccccc");
            }
        });
    }
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            searchModel();
        }
    });
    function addUser() {
        var url = './editUser-t.jsp?action=add&dept_id=';
        var dept_id = document.getElementById("dept_id").value;
        if (dept_id == '') {
            layer.alert("请选择机构", {icon: 5, title: "提示"});
            return false;
        }
        url += dept_id;
        viewDeptOrUserInfo('人员信息', url, '1000', '500');
    }
    function optMx(type) {
        var url = './edit-t.jsp?action='+type;
        viewDeptOrUserInfo('新建模型', url, '1000', '500');
    }
    function updateMx(){
        var mx_id=$("#check_mx_id").val();
        if(mx_id==''){
            layer.alert("请选择模型", {icon: 5, title: "提示"});
            return false;
        }
        var url = './edit-t.jsp?action=update&mx_id='+mx_id;
        viewDeptOrUserInfo('修改模型', url, '1000', '500');
    }
    function delMx(){
        var mx_id=$("#check_mx_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_mx_id").val(),$("#check_mx_day").val());
            }
        });
        //layer.full(abc);
    }
    function openLi(mx_id,day) {
        $("#check_mx_id").val(mx_id);
        $("#check_mx_day").val(day);
        $("#leftMx ul li").each(function(){
            $(this).css("backgroundColor","#e0e4f6");
        })
        $("#li_"+mx_id).css("backgroundColor","#cccccc");
        searchModel1(mx_id);
    }
    function editUser(day_id,mx_id,zb_type) {
        var url = './selectUser-t.jsp?day_id='+day_id+"&mx_id="+mx_id+"&zb_type="+zb_type;
        var abc = layer.open({
            title: '选择人员',
            type: 2,
            content: url,
            area: ['1000px', '500px'],
            maxmin: true,
            end:function () {
                searchModel1($("#check_mx_id").val());
            }
        });
    }

</script>