<!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-edit" th:object="${noticeSupply}">
            <input name="id" th:field="*{id}" type="hidden">


                    <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="请选择所属分类" th:field="*{typeName}" class="form-control"
                                       readonly="readonly" required>
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>

<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">关联商品类别表id：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="typeId" th:field="*{typeId}" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">商户名称</label>
                <div class="col-sm-8">
                    <input name="merchantId" th:field="*{merchantId}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">供应信息标题：</label>
                <div class="col-sm-8">
                    <input name="supplyTitle" th:field="*{supplyTitle}" class="form-control" type="text" required>
                </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" th:field="*{supplyDetails}"  name="supplyDetails" type="hidden">
                        <div id="editor"  class="summernote"></div>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">生产厂家：</label>
                <div class="col-sm-8">
                    <input name="manufacturer" th:field="*{manufacturer}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系人：</label>
                <div class="col-sm-8">
                    <input name="contacts" th:field="*{contacts}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="telephone" th:field="*{telephone}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发布时间：</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" th:value="${#dates.format(noticeSupply.releaseTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" 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="@{*{picture}}">
                            </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" th:field="*{status}" name="status" value="0" checked /> 征集中 </label>
                        <label class="radio-box"> <input type="radio" th:field="*{status}" 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";
        $("#form-supply-edit").validate({
            focusCleanup: true
        });

        $(function() {
            $('.summernote').summernote({
                placeholder: '请输入内容',
                height : 192,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                }
            });
            var content = $("#supplyDetails").val();
            $('#editor').summernote('code', content);

        });

        /******************选择分类树**********************************/
        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("图片上传失败。");
                }
            });
        }

        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 + "/edit", $('#form-supply-edit').serialize());
            }
        }

        $("input[name='releaseTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>