<!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-partners-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" required>
                        <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="partnerName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合作院校的图片：</label>
                <input name="partnerImage" id="partnerImage" 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"></label>
                <div class="col-sm-8">
                    <input name="a" class="form-control" type="text" disabled="true" value="图片长宽比例为 1:1">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/partners"
        $("#form-partners-add").validate({
            focusCleanup: true
        });

        $(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>");
                }
            });

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

        function submitHandler() {
            if ($.validate.form()) {
                var b=$("#partnerImage").val();
                if(b == '' || b.length == 0){
                    $.modal.alertWarning("请选择院校图片！");
                    return ;
                }
                $.operate.save(prefix + "/add", $('#form-partners-add').serialize()+
                    "&schoolId="+$("#schoolId").val());
            }
        }
    </script>
</body>
</html>