<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增企业荣誉')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-company_honour-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">荣耀标题：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="title" id="title" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">荣誉描述：</label>
                <div class="col-sm-8">
                    <textarea name="des" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">荣誉图片：</label>
                <div class="col-sm-8">
                    <input id="input-img" name="img"  type="hidden">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-preview thumbnail" style="width: 200px; height: 150px;">

                        </div>
                        <div>
                            <span class="btn btn-white btn-file">
                                <span class="fileinput-new">选择图片</span>
                                <span class="fileinput-exists">更改</span>
                                <input id="input-fileinput" type="file">
                            </span>
                            <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script type="text/javascript">
        var prefix = ctx + "company/honour"
        $("#form-company_honour-add").validate({
            focusCleanup: true
        });
        /*选择后提交图片到服务器*******/
        $('.fileinput').on('change.bs.fileinput ', function (e) {
            if ($("#input-fileinput").val() == '') {
                return;
            }var data = new FormData();
            data.append('file', document.getElementById('input-fileinput').files[0]);
            $.ajax({
                url:ctx+"common/upload",
                type:"post",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $("#input-img").val(result.data.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error:function(result) {
                    alert("上传失败")
                }
            });
        });
        function submitHandler() {
            if($("#input-img").val()==undefined||$("#input-img").val()==""){
                $.modal.msgError("请选择荣誉图片")
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-company_honour-add').serialize());
            }
        }


    </script>
</body>
</html>