<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增学校专业')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-major-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="majorType" 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">
                    <input name="majorCnName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">专业QS排名：</label>
                <div class="col-sm-8">
                    <input name="qs" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">专业图标：</label>
                <input name="majorIcon" type="hidden" id="majorIcon"/>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="singleFile" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">专业封面(大小:390*280)：</label>
                <input name="majorCover" type="hidden" id="majorCover"/>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="singleMajorCover" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学位中文名称：</label>
                <div class="col-sm-8">
                    <input name="degreeCnName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学位英文名称：</label>
                <div class="col-sm-8">
                    <input name="degreeEnName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学位类型：</label>
                <div class="col-sm-8">
                    <select id="degreeType" 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">
                    <input name="learnTime" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">雅思分数：</label>
                <div class="col-sm-8">
<!--                    <input name="ielts" class="form-control" type="text" required>-->
                    <select id="ielts" class="form-control select2-multiple">
                        <option value="N/A">N/A</option>
                        <option value="4.0">4.0</option>
                        <option value="4.5">4.5</option>
                        <option value="5.0">5.0</option>
                        <option value="5.5">5.5</option>
                        <option value="6.0">6.0</option>
                        <option value="6.5">6.5</option>
                        <option value="7.0">7.0</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学费：</label>
                <div class="col-sm-8">
                    <input name="tuition" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">入学时间：</label>
                <div class="col-sm-8">
                    <input name="enrollmentTime" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所需材料：</label>
                <div class="col-sm-8">
                    <label th:each="material:${@materialService.queryAll()}" class="check-box">
                        <input type ="checkbox" id="needMaterial" name="needMaterial"
                               th:value="${material.id}"
                               th:text ="${material.materialName}">
                    </label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否需要作品集：</label>
                <div class="col-sm-8">
                    <select id="needWorks" class="form-control select2-multiple">
                        <option value="0">不需要</option>
                        <option value="1">需要</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="needEducation" class="form-control select2-multiple">
                        <option value="0">不需要</option>
                        <option value="1">需要</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="needInterview" class="form-control select2-multiple">
                        <option value="0">不需要</option>
                        <option value="1">需要</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        $(document).ready(function() {
            <!--异步请求-->
            $.ajax({
                <!--请求路径，与后端对应-->
                url: ctx + "system/school/getList",
                <!--请求类型-->
                type: "get",
                <!--期待的返回数据类型-->
                dataType: "json",
                <!--前端接收数据成功是执行的该函数-->
                success: function (data) {
                    <!--清空下拉框中的缓存-->
                    // $("#city").empty();
                    <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                    for (var i = 0; i < data.length; i++)
                        $("#schoolId").append("<option value='" + data[i].id + "'>" + data[i].schoolCnName + "</option>");
                }
            });

            $.ajax({
                url: ctx+"system/dict/data/business_degree_type",
                type: "get",
                dataType: "json",
                success: function(data){
                    for(var i=0; i<data.length; i++){
                        $("#degreeType").append("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>");
                    }
                }
            });

            $.ajax({
                url: ctx+"system/dict/data/business_major_type",
                type: "get",
                dataType: "json",
                success: function(data){
                    for(var i=0; i<data.length; i++){
                        $("#majorType").append("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>");
                    }
                }
            });

            $("#singleFile").fileinput({
                uploadUrl: ctx + 'common/upload',
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("#majorIcon").val(rsp.fileName);
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            $("#singleMajorCover").fileinput({
                uploadUrl: ctx + 'common/upload',
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("#majorCover").val(rsp.fileName);
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
        });

        var prefix = ctx + "system/major"
        $("#form-major-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var a=$("#majorCover").val();
            var b=$("#majorIcon").val();
            if(b==null  || b.length<=0){
                alert("请上传专业图标");
                return ;
            }

            if(a==null  || a.length<=0){
                alert("请上传专业封面");
                return ;
            }

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-major-add').serialize()+
                    "&schoolId="+$("#schoolId")[0].value+
                    "&degreeType="+$("#degreeType")[0].value+
                "&majorType="+$("#majorType")[0].value+
                "&needWorks="+$('#needWorks')[0].value+
                "&needEducation="+$('#needEducation')[0].value+
                "&needInterview="+$('#needInterview')[0].value+
                "&ielts="+$('#ielts')[0].value);
            }
        }
    </script>
</body>
</html>