<!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"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-article-edit" th:object="${cmsArticle}">
        <input name="articleId" th:field="*{articleId}" type="hidden">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label">文章标题：</label>
                    <div class="col-sm-10">
                        <input th:field="*{articleTitle}" maxlength="50" required id="articleTitle" name="articleTitle"
                               class="form-control"
                               type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">文章作者：</label>
                    <div class="col-sm-8">
                        <input th:field="*{articleAuthor}" maxlength="20" id="articleAuthor" name="articleAuthor"
                               required class="form-control"
                               type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">是否转载：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input th:checked="${cmsArticle.copyFlag == '1' ? true : false}" type="checkbox" id="isCopy"
                                   name="isCopy">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="div_isCopy_extend" th:hidden="${cmsArticle.copyFlag==1}">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">原文链接：</label>
                    <div class="col-xs-10">
                        <input th:field="*{copyFlag}" type="hidden" name="copyFlag" id="copyFlag" value="0">
                        <inpu th:field="*{articleLink}" type="text" required class="form-control" id="articleLink"
                              name="articleLink"
                              value=""/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">栏目分类：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input id="treeId" name="categoryId" type="hidden" th:field="*{categoryId}"/>
                            <input required class="form-control" type="text" onclick="selectCategoryTree()"
                                   id="treeName"
                                   readonly="true" th:value="${categoryName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">启用评论：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input th:checked="${cmsArticle.commentFlag == '1' ? true : false}" type="checkbox"
                                   id="commentFlag" name="commentFlag">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">关键词：</label>
                    <div class="col-sm-8">
                        <input th:field="*{articleKeywords}" maxlength="20" name="articleKeywords" id="articleKeywords"
                               class="form-control"
                               type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">封面图片：</label>
                    <div class="col-sm-8">
                        <input th:field="*{materialId}" required name="materialId" id="materialId"
                               class="form-control" type="text"
                               style="display: none;">
                        <div class="input-group">
                            <input th:value="${materialName}" required id="materialName" name="coverImage"
                                   readonly="true" onclick="selectImage()"
                                   class="form-control valid" type="text">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-xs-4 control-label">文章状态：</label>
                    <div class="col-xs-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('cms_article_status')}">
                            <input type="radio" th:id="${'available_' + dict.dictCode}" name="articleStatus"
                                   th:value="${dict.dictValue}" th:field="*{articleStatus}">
                            <label th:for="${'available_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" name="articleStatus" disabled
                                   value="3" th:field="*{articleStatus}">
                            <label th:for="available_197_1">已发布</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" name="articleStatus" disabled
                                   value="4" th:field="*{articleStatus}">
                            <label th:for="available_197_1">审核拒绝</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span>所属商户：</label>
                <div class="col-sm-8">
                    <select id="merchantId" class="form-control" name="merchantId" required>
                        <option value="">--系统商户--</option>
                        <option th:each="post:${mts}"
                                th:value="${post.merchantId}"
                                th:text="${post.merchantName}" th:field="*{merchantId}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">文章摘要：</label>
                    <div class="col-xs-10">
                            <textarea required maxlength="200" rows="4" class="form-control" name="articleDescription"
                                      placeholder="描述"
                                      id="articleDescription">[[*{articleDescription}]]</textarea>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">文章内容</h4>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">正文:</label>
                    <div class="col-xs-10">
                        <script id="editor" name="content" type="text/plain"></script>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" id="content_s" th:value="${content}">
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: ueditor"/>
<script type="text/javascript">
    function selectImage() {
        var url = ctx + "/bussiness_cms/material/material_group";
        $.modal.openFull("封面图片选择", url);
    }

    /*栏目分类选择*/
    function selectCategoryTree() {
        var prefixTemp = ctx + "/bussiness_cms/category"
        var options = {
            title: '文章分类选择',
            width: "380",
            url: prefixTemp + "/selectCategoryTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    var ue = UE.getEditor('editor');

    function getContent() {
        return UE.getEditor('editor').getContent();
    }

    function getContentTxt() {
        return UE.getEditor('editor').getContentTxt();
    }
</script>

<script type="text/javascript">
    $(function () {
        $("#editor").css("height", "380px");
        $("#isCopy").on("change", function () {
            var v = $(this).prop("checked");
            if (v) {
                $("#copyFlag").val("1");//转载标志
                $("#div_isCopy_extend").show();
            } else {
                $("#copyFlag").val("0");
                $("#div_isCopy_extend").hide();
            }
        });

        ue.ready(function () {//编辑器初始化完成再赋值
            var content_s=$("#content_s").val();
            ue.setContent(content_s);  //赋值给UEditor
        });

    })
    var prefix = ctx + "bussiness_cms/article"
    $("#form-article-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var copyFlag = $("#copyFlag").val();
            if (copyFlag == '1') {
                var article_link = $("#article_link").val();
                if (!article_link) {
                    $.modal.alertWarning("请输入原文链接!");
                    return;
                }
            }
            var c = getContentTxt();
            if (c == '' || c.length == 0) {
                $.modal.alertWarning("请输入正文！");
                return;
            }
            var params = $("#form-article-edit").serialize();
            //var commentFlag = $("input[id='commentFlag']").is(':checked') == true ? 1 : 0;
            $.operate.save(prefix + "/edit", params);
        }
    }
</script>
</body>
</html>