<!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-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">公众号名称：</label>
            <div class="col-sm-8">
                <input name="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" 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" checked="" value="01" name="detailType">个人</label>
                <label class="radio-box">
                    <input type="radio" 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" class="form-control" th:rows="4"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公众号负责人：</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}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label is-required">运营人员：</label>
            <div class="col-xs-8">
                <select id="managerIds" class="form-control select2-multiple" multiple>
                    <option th:each="user:${users}" th:value="${user.userId}" th:text="${user.userName}" ></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章默认作者名：</label>
            <div class="col-sm-8">
                <input name="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="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 name="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">
                <input name="logoUrl" type="text" 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" 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" name="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"
    var remark = [[${defaultRemark}]];
    $("#form-account-add").validate({
        focusCleanup: true
    });

    // 详情页
    $("#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 submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-account-add").serializeArray();
            var managerIds = $.form.selectSelects("managerIds");
            data.push({"name": "managerIds", "value": managerIds});
            $.operate.save(prefix + "/add", data);
        }
    }

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

    $(function() {
        console.log(remark);
        $('.summernote').summernote({
            lang: 'zh-CN',
            height: 300,
            dialogsInBody: true,
            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("图片上传失败。");
                        }
                    });
                }
            }
        });
        $('#remark').summernote('code', remark);
    });
</script>
</body>
</html>