<%@ page language="C#" autoeventwireup="true" inherits="sysadmin_BookingAudit, App_Web_bookingaudit.aspx.ddba9769" enableviewstate="false" enableEventValidation="false" %>

<%@ Register Src="~/sadmin/NewHeader.ascx" TagPrefix="uc1" TagName="NewHeader" %>
<%@ Register Src="~/sadmin/NewFooter.ascx" TagPrefix="uc1" TagName="NewFooter" %>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>网上预约系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/control/plugin/bootstrap3/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/control/plugin/fullcalendar/fullcalendar.css" rel="stylesheet" />
    <link href="/control/css/msgbox.css" rel="stylesheet" />
    <!-- ionicons -->
    <link href="/lib/ionicons/ionicons.min.css" rel="stylesheet" />
    <!-- Animate -->
    <link href="/lib/animate/animate.min.css" rel="stylesheet" />
    <!-- base -->
    <link href="/css/base.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-3.1.1.min.js"></script>
    <!--[if lt IE 9]>
      <script src="/js/html5shiv.min.js"></script>
      <script src="/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="wrapper">
        <uc1:NewHeader runat="server" ID="NewHeader" />
        <div class="container">

            <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header">预约审核<small> 审核用户预约信息，分配使用时间 </small></h3>
                </div>
            </div>

            <div class="row">

                <div class="col-lg-4">

                    <div class="panel panel-default">
                        <div class="panel-body">

                            <!-- Add.aspx -->

                            <div class="form-group">
                                <label class=" control-label">
                                    预约用户：</label>
                                <div>
                                    <asp:Label ID="litUser" runat="server" Font-Size="15px">
                                    </asp:Label>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class=" control-label">
                                    预约设备：</label>
                                <div>
                                    <asp:Label ID="ddlb_eid" runat="server" Font-Size="15px">
                                    </asp:Label>
                                </div>
                                 <div>
                                    <asp:Label ID="txt_info" runat="server" Font-Size="15px">
                                    </asp:Label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    设备管理员：</label>
                                <div>
                                    <asp:Label ID="txt_admin" runat="server" Font-Size="15px">
                                    </asp:Label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    时间分配方式：</label>
                                <div>
                                    <asp:Label ID="txtb_stype" runat="server">
                                    </asp:Label>
                                </div>
                            </div>

                            <asp:Panel runat="server" ID="Panel_Time" class="form-group">
                                <label class=" control-label">
                                    用户指定预约时间：</label>
                                <div class="btime">
                                    <asp:Label ID="txtb_start" runat="server"></asp:Label>至
                                    <asp:Label ID="txtb_end" runat="server"></asp:Label>
                                </div>
                                <asp:Repeater ID="rpt_btime" runat="server">
                                    <ItemTemplate>
                                        <div class="btime">
                                            <span><%#Eval("bt_start","{0:yyyy-MM-dd HH:mm}")%></span>至
                                            <span><%#Eval("bt_end","{0:yyyy-MM-dd HH:mm}")%></span>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>

                            </asp:Panel>
                            <div class="form-group">
                                <label class=" control-label">
                                    课题名称<span class='rd'>*</span>：</label>
                                <div>
                                    <asp:Label ID="txt_pname" runat="server" MaxLength="4"></asp:Label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    实验内容<span class='rd'>*</span>：</label>
                                <div>
                                    <asp:Label ID="txt_pcontent" runat="server" MaxLength="4"></asp:Label>                         
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    预约时长(分钟)：</label>
                                <div>
                                    <asp:Label ID="txtb_btime" runat="server" MaxLength="4"></asp:Label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    预约说明：</label>
                                <div>
                                    <asp:Label ID="txtb_note" runat="server" Style="min-height: 100px"></asp:Label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label">
                                    提交预约申请日期：</label>
                                <div>
                                    <asp:Label ID="labCDate" runat="server"></asp:Label>

                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="col-lg-8">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <form id="from1" runat="server" >
                                <asp:HiddenField ID="hfeid" runat="server" />
                                <asp:HiddenField ID="hfstype" runat="server" />
                                <asp:HiddenField ID="hfbid" runat="server" />
                                <asp:HiddenField ID="hfauditType" runat="server" />

                                <script type="text/javascript">
                                    $(function () {
                                        $('#calendar').fullCalendar({
                                            events: {
                                                url: 'EquipmentUse.ashx',
                                                type: 'POST',
                                                data: {
                                                    eid: $("#hfeid").val()
                                                }
                                            },
                                            defaultView: "agendaWeek",
                                            allDayDefault: false,
                                            header: {
                                                left: 'prev,next today',
                                                center: 'title',
                                                right: 'month,listMonth,agendaWeek,listWeek,agendaDay,listDay'
                                            },
                                            views:
                                            {
                                                listMonth: { buttonText: '列' },
                                                listWeek: { buttonText: '列' },
                                                listDay: { buttonText: '列' }
                                            }
                                        });
                                        
                                        var type = $("#hfstype").val();

                                        if (type == "0" || type == "1") {
                                            $("#st0").val($("#txtb_start").text());
                                            $("#et0").val($("#txtb_end").text());
                                            btime(0);
                                            var timelist = $("div.btime");
                                            for(var i=1;i<timelist.length;i++)
                                            {
                                                addBU();
                                                $("#st" + i).val($(timelist[i]).find("span").eq(0).html());
                                                $("#et" + i).val($(timelist[i]).find("span").eq(1).html());
                                                btime(i);
                                            }
                                        }
                                    });
                                </script>

                                <div class="form-group">
                                    <div id="calendar"></div>
                                </div>
                                <div class="form-group  has-feedback ">
                                    <label for="exampleInputEmail1">分配使用时间：</label>
                                    <div id="bulist">
                                        <div class="row" id="bu0" index="0">

                                            <div class="col-xs-4">
                                                <input id="st0" name="st0" class="form-control" type="text" onblur="btime(0)" placeholder="起始日期" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" />
                                            </div>
                                            <div class="col-xs-4">
                                                <input id="et0" name="et0" class="form-control" type="text" onblur="btime(0)" placeholder="截止日期" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" />
                                            </div>
                                            <div class="col-xs-3">
                                                <input id="bt0" class="form-control warning" type="text" readonly="readonly" />
                                            </div>

                                            <input name="bu" value="0" type="hidden" />
                                        </div>
                                    </div>

                                    <script type="text/javascript">
                                        var buindex = 1;
                                        function addBU() {

                                            var sb = new StringBuilder();
                                            sb.append('<div class="row" id="bu' + buindex + '" index="' + buindex + '" style="margin-top:10px" >');
                                            sb.append('<div class="col-lg-4"><input id="st' + buindex + '" name="st' + buindex + '" class="form-control" onblur="btime(' + buindex + ')" type="text"  placeholder="起始日期"  onfocus=\'WdatePicker({dateFmt:"yyyy-MM-dd HH:mm"})\' /></div>');
                                            sb.append('<div class="col-lg-4"><input id="et' + buindex + '" name="et' + buindex + '" class="form-control" onblur="btime(' + buindex + ')" type="text"  placeholder="截止日期"  onfocus=\'WdatePicker({dateFmt:"yyyy-MM-dd HH:mm"})\' /></div>');
                                            sb.append('<div class="col-lg-3"><input id="bt' + buindex + '" class="form-control warning" type="text" readonly="readonly" /></div>');
                                            sb.append('<div class="col-lg-1"><button type="button" onclick="dbu(' + buindex + ')" class="btn btn-default" ><i class="glyphicon glyphicon-remove"></i></button>');
                                            sb.append('<input name="bu" value="' + buindex + '"  type="hidden" /></div>');
                                            $("#bulist").append(sb.tostring());
                                            buindex++;

                                        }

                                        function btime(index) {
                                            var start = new Date($("#st" + index).val());
                                            var end = new Date($("#et" + index).val());
                                            if (!isNaN(start) && !isNaN(end)) {
                                                var cha = end.getTime() - start.getTime()  //时间差的毫秒数

                                                var minutes = Math.floor(cha / (60 * 1000))

                                                $("#bt" + index).val(minutes + "分钟");
                                            }
                                        }

                                        function dbu(index) {
                                            $("#bu" + index).remove();
                                        }
                                      
                                    </script>

                                </div>

                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <button type="button" class="btn btn-default btn-min " onclick="addBU()"><i class="glyphicon glyphicon-plus"></i> 新增分配时间项</button>
                                            <p class="help-block">为一个预约分配多个使用时间段</p>
                                        </div>
                                        <div class="col-lg-6">
                                            <button type="button" class="btn  btn-default btn-min " onclick="isOverlap()"><i class="glyphicon glyphicon-random"></i> 判断是否重叠</button>
                                            <p class="help-block">判断时间是否重叠，如果使用时间重叠，请重新设置使用日期</p>
                                            <script type="text/javascript">

                                                function isOverlap() {

                                                    var bulist = $("#bulist").children();
                                            
                                                    var dates = new StringBuilder();
                                                    var size = bulist.length;
                                                 
                                                    for (var i = 0; i < size ; i++) {
                                                        var index = (bulist.eq(i)).attr("index");
                                                        var start = $("#st" + index).val();
                                                        var end = $("#et" + index).val();
                                                        if (start == "" || end == "") {
                                                            alert("请正确填写分配时间！");
                                                            return;
                                                        }
                                                        dates.append(start + "|" + end);
                                                        if (i != size - 1) {
                                                            dates.append(',');
                                                        }
                                                    }

                                                    ZENG.msgbox.show('判断中...', 6);
                                                    var eid = $("#hfeid").val();
                                                    $.ajax({
                                                        type: "POST",
                                                        url: "isOverlap.ashx",
                                                        dataType: "json",
                                                        data: { "eid": eid, "dates": dates.tostring() },
                                                        success: function (result) {
                                                            ZENG.msgbox._hide();
                                                            if (result.state == 1) {
                                                                alert("使用时间未重叠");
                                                            } else {
                                                                alert(result.data);
                                                            }
                                                        }
                                                    });

                                                }

                                            </script>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <button id="btnSubmit" type="button" 
                                                class="btn btn-default btn-lg btn-block btn-success"
                                                onclick="AuditYes()">
                                                通过审核
                                            </button>
                                        </div>
                                        <div class="col-lg-6">
                                            <button type="button" class="btn btn-default btn-lg btn-block btn-primary" data-toggle="modal" data-target="#myModal">未通过审核</button>
                                        </div>
                                    </div>
                                </div>

                                <script type="text/javascript">
                                    var options = {
                                        success: function (data) {
                                            ZENG.msgbox._hide();
                                            var result = $.evalJSON(data);
                                            if (result.state == -1) {
                                                alert(result.data);
                                            }
                                            else {
                                                location.href = "BookingAuditComplete.aspx?id=" + result.data;
                                            }
                                        }
                                    }

                                    function AuditYes() {

                                        var bulist = $("#bulist").children();
                                        var size = bulist.length;
                                        for (var i = 0; i < size ; i++) {
                                            var index = bulist.attr("index");
                                            var start = $("#st" + index).val();
                                            var end = $("#et" + index).val();
                                            if (start == "" || end == "") {
                                                alert("请完整填写的分配使用时间！");
                                                return;
                                            }
                                        }
                                        $("#hfauditType").val(1);
                                        ZENG.msgbox.show('提交审核中...', 6);
                                        $("#from1").ajaxSubmit(options);
                                    }
                                    function AuditNot() {
                                        $("#hfauditType").val(2);
                                        ZENG.msgbox.show('提交审核中...', 6);
                                        $("#from1").ajaxSubmit(options);
                                    }
                                </script>
                                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                                <h4 class="modal-title" id="myModalLabel">未通过原因</h4>
                                            </div>
                                            <div class="modal-body">
                                                <asp:TextBox ID="txtNotVerifyNote" runat="server" TextMode="MultiLine" Rows="5" CssClass="form-control"></asp:TextBox>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                                                <button type="button"  class="btn btn-default btn-primary" onclick="AuditNot()">提交审核</button>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>

                        </div>
                    </div>

                </div>
            </div>
   
        </div>
        <uc1:NewFooter runat="server" ID="NewFooter" />
    </div>

    <script src="/control/plugin/bootstrap3/js/bootstrap.min.js"></script>
    <script src="/js/custom.js"></script>
 
    <script src="/control/plugin/My97DatePicker/WdatePicker.js"></script>
    <script src="/control/plugin/fullcalendar/lib/moment.min.js"></script>
    <script src='/control/plugin/fullcalendar/fullcalendar.js'></script>
    <script src="/control/plugin/fullcalendar/locale/zh-cn.js"></script>
    <script src="/control/js/msgbox.js" type="text/javascript"></script>
    <script src="/control/plugin/form/jquery.form.min.js"></script>
    <script src="/control/js/String.js"></script>
</body>
</html>
