<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增供应信息')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: datetimepicker-css" />
    <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-supply-add">
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>供应信息标题：</label>
                <div class="col-sm-8">
                    <input name="supplyTitle" class="form-control" type="text" required>
                </div>
            </div>

                    <div class="form-group">
                        <input name="typeId" type="hidden" id="input_typeId">
                        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>商品分类：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="typeName" onclick="selectTypeTree()" id="input_typeTreeName" type="text" placeholder="请选择所属分类" class="form-control"
                                       readonly="readonly" required>
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>



            <div class="row">
                <div class="form-group">
                    <label class="col-sm-3 control-label"><span style="color: red; ">*</span>供应信息详情：</label>
                    <div class="col-sm-8">
                        <input id="supplyDetails" name="supplyDetails" type="hidden">
                        <div class="summernote"></div>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>生产厂家：</label>
                <div class="col-sm-8">
                    <input name="manufacturer" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>联系人：</label>
                <div class="col-sm-8">
                    <input name="contacts" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>联系电话：</label>
                <div class="col-sm-8">
                    <input name="telephone" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>发布时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="releaseTime" class="form-control"  type="text">
                    </div>
                </div>
            </div>

                <div class="form-group">
                    <input id="fmzFile" name="picture" type="hidden"/>
                    <label class="col-sm-3 control-label"><span style="color: red; ">*</span>商品图片：</label>
                    <div class="col-sm-8">
                        <div class="fileinput fileinput-new" data-provides="fileinput">
                            <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                                <img th:src="@{/img/profile.jpg}">
                            </div>
                            <div id="fmz" class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;">

                            </div>
                            <div>
                                <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file"></span>
                                <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                            </div>
                        </div>
                    </div>
                </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">供应信息状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <label class="radio-box"> <input type="radio"  name="status" value="0" checked /> 征集中 </label>
                        <label class="radio-box"> <input type="radio"  name="status" value="1" /> 已结束 </label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script type="text/javascript">
        var prefix = ctx + "notice/supply"

        $(function(){
            $("input[name='releaseTime']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
        })
        $("#form-supply-add").validate({rules: {
                typeName: "required",
                lastname: "required",
                username: {
                    required: true,
                    minlength: 2
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                }
            },
            focusCleanup: true
        });

        $('.summernote').summernote({
            placeholder: '请输入内容',
            height : 192,
            lang : 'zh-CN',
            followingToolbar: false,
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
                $("#supplyDetails").val(sHTML);
                var file = $('#fmz').find('img').attr('src');
                if(file == undefined){
                    $.modal.alertWarning("请上传图片");
                    return;
                }
                $('#fmzFile').val(file);
                $.operate.save(prefix + "/add", $('#form-supply-add').serialize());
            }
        }
        /******************选择分类树**********************************/
        function selectTypeTree() {
            var typeId = "0";
            var url = ctx + "goods/type/selectTypeTree/" + typeId;
            var options1 = {
                title: '选择商品类型',
                width: "380",
                url: url,
                callBack: selectType
            };
            $.modal.openOptions(options1);
        }
        function selectType(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#input_typeId").val(body.find('#treeId').val());
            $("#input_typeTreeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        /************************上传文件******************************/
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


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