<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="70%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
              <Field :span="20" label="标题" prop="title" v-model="form.title" type="textarea" placeholder="请输入标题"/>
              <Field :span="20" label="封面"><imageUpload v-model="form.cover" prePath="/file/preview"/></Field>
              <Field :span="20" label="文章介绍" prop="introduction" v-model="form.introduction" type="textarea" placeholder="请输入文章介绍"/>
              <Field :span="20" label="内容" prop="content" v-model="form.content" rows="12"  type="textarea"  placeholder="请输入内容"/>
              <Field :span="20" label="内容html"><editor v-model="form.contentHtml" :min-height="256"/></Field>
              <Field :span="20" label="文章作者" prop="author" v-model="form.author" placeholder="请输入文章作者"/>

            </el-row>

            <form-buttons @submit='submitForm' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    export default {
        name: "ArticleDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("article")
        },
        data() {
            return {
                rows:20,
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "文章",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="article/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改文章";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "article/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增文章";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="article/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "文章详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    title : null,
                    cover : null,
                    introduction : null,
                    content : null,
                    contentHtml : null,
                    author : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
