<!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 :: summernote-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-account-edit" th:object="${playletPublicAccount}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">公众号名称：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">内容方向：</label>
            <div class="col-sm-8">
                <input name="publicType" th:field="*{publicType}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">认证标识：</label>
            <div class="col-sm-8">
                <label class="radio-box">
                    <input type="radio" th:checked="${playletPublicAccount.detailType == '01' ? true : false}" value="01" name="detailType">个人</label>
                <label class="radio-box">
                    <input type="radio" th:checked="${playletPublicAccount.detailType == '02' ? true : false}" value="02" name="detailType">企业</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">简介：</label>
            <div class="col-sm-8">
                <textarea name="introduction" th:field="*{introduction}" th:rows="4" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章默认作者名：</label>
            <div class="col-sm-8">
                <input name="authorAlias" th:field="*{authorAlias}" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">文章标签(逗号隔开)：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input name="detailTags" th:field="*{detailTags}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">公众号负责人：</label>
            <div class="col-sm-8">
                <select id="managerId" name="managerId" class="form-control m-b" required>
                    <option th:each="user:${users}" th:value="${user.userId}" th:text="${user.userName}" th:field="*{managerId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">运营人员：</label>
            <div class="col-sm-8">
                <select id="managerIds" class="form-control select2-multiple" multiple>
                    <option th:each="user:${users}" th:value="${user.userId}" th:text="${user.userName}" th:selected="${user.flag}" ></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">头像：</label>
            <div class="col-sm-8">
                <input name="logoUrl" th:field="*{logoUrl}" type="text" hidden="hidden">
                <div class="file-loading">
                    <input id="logoUrlFile" 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="address" th:field="*{address}" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">原创篇数：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input name="originalContentCount" th:field="*{originalContentCount}" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">关注人数：</label>
            <div class="col-sm-8">
                <input name="followersCount" th:field="*{followersCount}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户协议：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" th:field="*{remark}">
                <div class="summernote" id="remark"></div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/playlet/account";
    $("#form-account-edit").validate({
        focusCleanup: true
    });

    $(function() {
        $('#managerIds').select2({
            placeholder: "请选择运营人员",
            allowClear: true
        });
    })

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-account-edit").serializeArray();
            var managerIds = $.form.selectSelects("managerIds");
            data.push({"name": "managerIds", "value": managerIds});
            $.operate.save(prefix + "/edit", data);
        }
    }

    // 详情页
    $("#logoUrlFile").fileinput({
        uploadUrl: ctx + 'tool/oss/uploadFromPlaylet',
        maxFileCount: 1,
        dropZoneEnabled: false,      //是否显示拖拽区域
        showPreview: false,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        console.log(data);
        if(data.response.success){
            $("input[name='logoUrl']").val(data.response.msg)
        }else {
            alert("上传失败!");
        }
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
        $("input[name='logoUrl']").val('')
    })

    $(function() {
        $('.summernote').each(function(i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                height: 300,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.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.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function(error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });

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