<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增入学时间')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-time-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学校：</label>
                <div class="col-sm-8">
                    <select id="schoolId" class="form-control select2-multiple">
                        <option>请选择学校</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">专业：</label>
                <div class="col-sm-8">
                    <select id="majorCnName" class="form-control select2-multiple">
                        <option>请选择专业</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学位：</label>
                <div class="col-sm-8">
                    <select id="degreeCnName" class="form-control select2-multiple">
                        <option>请选择学位</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">入学时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="enrollmentTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">申请开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="applyStartDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">申请结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="applyEndDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/time"
        $("#form-time-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-time-add').serialize()+
                    "&schoolId="+$('#schoolId')[0].value+
                "&majorId="+$('#degreeCnName')[0].value);
            }
        }

        $("input[name='enrollmentTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='applyStartDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='applyEndDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(document).ready(function() {
            <!--异步请求-->
            $.ajax({
                <!--请求路径，与后端对应-->
                url: ctx + "system/school/getList",
                <!--请求类型-->
                type: "get",
                <!--期待的返回数据类型-->
                dataType: "json",
                <!--前端接收数据成功是执行的该函数-->
                success: function (data) {
                    <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                    for (var i = 0; i < data.length; i++)
                        $("#schoolId").append("<option value='" + data[i].id + "'>" + data[i].schoolCnName + "</option>");
                }
            });

            $('#schoolId').change(function () {
                var sid=$('#schoolId')[0].value;
                $.ajax({
                    <!--请求路径，与后端对应-->
                    url: prefix + "/selectMajor/"+sid,
                    <!--请求类型-->
                    type: "get",
                    <!--期待的返回数据类型-->
                    dataType: "json",
                    <!--前端接收数据成功是执行的该函数-->
                    success: function (data) {
                        <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                        for (var i = 0; i < data.length; i++)
                            $("#majorCnName").append("<option value='" + data[i].majorCnName + "'>" + data[i].majorCnName + "</option>");
                    }
                });
            });

            $('#majorCnName').change(function () {
                var sid=$('#schoolId')[0].value;
                var majorName=$('#majorCnName')[0].value;
                $.ajax({
                    <!--请求路径，与后端对应-->
                    url: prefix + "/selectDegree/"+sid+"/"+majorName,
                    <!--请求类型-->
                    type: "get",
                    <!--期待的返回数据类型-->
                    dataType: "json",
                    <!--前端接收数据成功是执行的该函数-->
                    success: function (data) {
                        <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                        for (var i = 0; i < data.length; i++)
                            $("#degreeCnName").append("<option value='" + data[i].id + "'>" + data[i].degreeCnName + "</option>");
                    }
                });
            });

        });
    </script>
</body>
</html>