<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                             <Field label="类型" :span="20" prop="categoryId" v-model="form.categoryId" type="radio" :enum-data="dict.categoryId" placeholder="请输入分类id"/>
              <Field :span="20" label="封面"><imageUpload v-model="form.titleLogoPath" prePath="/file/preview"/></Field>
              <Field label="标题" :span="20" prop="title" v-model="form.title"  placeholder="请输入标题"/>
              <Field :span="20" label="内容"><editor v-model="form.content" :min-height="256"/></Field>

              <Field :span="20" label="责任编辑" prop="editor" v-model="form.editor" placeholder="请输入责任编辑"/>

              <Field :span="20" label="发布部门" prop="deptId" v-model="form.deptId" placeholder="请输入发布部门"/>

              <Field :span="20" label="文章来源" prop="source" v-model="form.source" type="textarea" placeholder="请输入文章来源"/>

              <Field :span="20" label="声明" prop="statement" v-model="form.statement" type="textarea" 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: "NewsDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("news")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "新闻",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "top",
                    "viewNums",
                ],
                toDate:[
                    "publishTime",
                ],
                // 表单校验
                rules: {
                    title: [
                        {required: true,message: "请输入标题", trigger: "blur" },
                        {max: 512,message: "最多只能录入512个字符",trigger: "blur",},
                    ],
                    titleLogoPath: [
                        {required: true,message: "请输入标题logo", trigger: "blur" },
                        {max: 512,message: "最多只能录入512个字符",trigger: "blur",},
                    ],
                    top: [
                        {required: true,message: "请输入置顶 ", trigger: "blur" },
                    ],
                    viewNums: [
                        {required: true,message: "请输入浏览次数", trigger: "blur" },
                    ],
                    publishTime: [
                        {required: true,message: "请选择发布时间" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="news/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改新闻";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "news/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增新闻";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="news/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 = {
                    categoryId : null,
                    categoryName : "",
                    title : "",
                    titleLogoPath : "",
                    content : "",
                    top : 0,
                    viewNums : 0,
                    publishTime : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
