<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增学校信息')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <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-school-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学校中文名称：</label>
                <div class="col-sm-8">
                    <input name="schoolCnName" id="schoolCnName" 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="schoolEnName" id="schoolEnName" 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="schoolCnCountry" id="schoolCnCountry" 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="schoolCnCity" id="schoolCnCity" 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="schoolEnCountry" id="schoolEnCountry" 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="schoolEnCity" id="schoolEnCity" 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="address" id="address" 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="lng" id="lng" 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="lat" id="lat" 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="phone" id="phone" 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="website" id="website" 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="schoolType" 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="schoolCampus" id="schoolCampus" 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="schoolArea" id="schoolArea" 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">
                    <textarea rows="8" cols="10" name="schoolIntroduction" id="schoolIntroduction" class="form-control" required>
                        </textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">QS世界排名：</label>
                <div class="col-sm-8">
                    <input name="qsWorld" id="qsWorld" 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="qsArea" id="qsArea" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">毕业后6个月就业率：</label>
                <div class="col-sm-8">
                    <input name="employmentRate" id="employmentRate" 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="qsEmployability" id="qsEmployability" 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="teachingLanguage" id="teachingLanguage" 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="internship" id="internship" 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="govAuth" class="form-control select2-multiple" required>
                        <option value="Y">是</option>
                        <option value="N">否</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学校logo(比例:1:1)：</label>
                <input name="schoolLogo" id="schoolLogo" type="hidden">
                <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="schoolCover" id="schoolCover" type="hidden">
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="singleSchoolCover" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学校背景图(大小:1920*300)：</label>
                <input name="backgroundImage" id="backgroundImage" type="hidden">
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="singleFile1" 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">
                    <select id="liveType" class="form-control select2-multiple" multiple>
                        <option value="1">校内</option>
                        <option value="2">校外公寓</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="airportPickup" class="form-control select2-multiple" required>
                        <option value="Y">是</option>
                        <option value="N">否</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/school"
        $("#form-school-add").validate({
            focusCleanup: true
        });

        $(document).ready(function() {
            $.ajax({
                url: ctx+"system/dict/data/business_school_type",
                type: "get",
                dataType: "json",
                success: function(data){
                    for(var i=0; i<data.length; i++){
                        $("#schoolType").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;
                $("#schoolLogo").val(rsp.fileName);
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

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

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

        function submitHandler() {
            if ($('#schoolLogo').val() == null) {
                $.modal.alertWarning("请先选择文件");
                return false;
            }

            if ($('#schoolCover').val() == null) {
                $.modal.alertWarning("请先选择文件");
                return false;
            }

            if ($('#backgroundImage').val() == null) {
                $.modal.alertWarning("请先选择文件");
                return false;
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-school-add').serialize()+
                    "&govAuth="+$("#govAuth").val()+
                "&liveType="+$("#liveType").val()+
                "&airportPickup="+$("#airportPickup").val()+
                "&schoolType="+$("#schoolType").val());
            }
            // var formData = new FormData();
            // formData.append('schoolCnName', $("#schoolCnName")[0].value);
            // formData.append('schoolEnName', $("#schoolEnName")[0].value);
            // formData.append('schoolCnCountry', $("#schoolCnCountry")[0].value);
            // formData.append('schoolCnCity', $("#schoolCnCity")[0].value);
            // formData.append('schoolEnCountry', $("#schoolEnCountry")[0].value);
            // formData.append('schoolEnCity', $("#schoolEnCity")[0].value);
            // formData.append('schoolType',$("#schoolType")[0].value);
            // formData.append('schoolLogo', $('#schoolLogo')[0].files[0]);
            // formData.append('backgroundImage', $('#backgroundImage')[0].files[0]);
            // formData.append('schoolCampus', $('#schoolCampus')[0].value);
            // formData.append('qsWorld', $('#qsWorld')[0].value);
            // formData.append('qsArea', $('#qsArea')[0].value);
            // formData.append('liveType',$("#liveType").val());
            // formData.append('airportPickup',$("#airportPickup")[0].value);
            // formData.append('schoolIntroduction',$("#schoolIntroduction")[0].value);
            // formData.append('schoolArea',$("#schoolArea")[0].value);
            // formData.append('employmentRate',$("#employmentRate")[0].value);
            // formData.append('qsEmployability',$("#qsEmployability")[0].value);
            // formData.append('teachingLanguage',$("#teachingLanguage")[0].value);
            // formData.append('internship',$("#internship")[0].value);
            // formData.append('govAuth',$("#govAuth")[0].value);

            // $.ajax({
            //     url: prefix + "/add",
            //     type: 'post',
            //     cache: false,
            //     data: formData,
            //     processData: false,
            //     contentType: false,
            //     dataType: "json",
            //     success: function(result) {
            //         $.operate.successCallback(result);
            //     }
            // });
        }
    </script>
</body>
</html>