<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="140px">
            <el-row>
               <Field label="消息的标题" span="20" prop="title" v-model="form.title" type="textarea" placeholder="请输入消息的标题"/>
                            <Field span="20" label="消息的内容"><editor v-model="form.content" :min-height="256"/></Field>
                            <Field label="已读" span="20" prop="read" v-model="form.read" type="radio" :enumData="dict.read" />
                            <Field span="20" label="消息的优先级" prop="priority" v-model="form.priority" placeholder="请输入消息的优先级"/>
                            <Field span="20" label="消息的过期时间" prop="expireTime" v-model="form.expireTime" type="date" />
                            <Field span="20" label="消息的来源类型" prop="sourceType" v-model="form.sourceType" placeholder="请输入消息的来源类型"/>

            </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" v-if="pageInfo.type !== 'view'" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    import dialogShow from "./dialogshow";
    import Editor from '@/components/Editor';
    export default {
        mixins: [form],
        components: {
            dialogShow ,
            Editor,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "用户消息",
                // 是否显示弹出层
                open: false,
                toString:["read","sourceType"
                ],
              toDate:["expireTime"
              ],
                // 表单校验
                rules: {
                    title: [
                        {required: true,message: "请输入消息的标题", trigger: "blur" },
                        {max: 255,message: "最多只能录入255个字符",trigger: "blur",},
                    ],
                    content: [
                        {required: true,message: "请输入消息的内容", trigger: "blur" },
                        {max: 1024,message: "最多只能录入1024个字符",trigger: "blur",},
                    ],
                    priority: [
                        {required: true,message: "请输入消息的优先级，越高表示越紧急，不为空", trigger: "blur" },
                    ],
                    sourceType: [
                        {required: true,message: "请输入消息的来源类型，例如“系统”、“好友”等，可以为空", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="notice/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改用户消息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "notice/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增用户消息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="notice/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 = {
                    userId : null,
                    title : "",
                    content : "",
                    read : null,
                    priority : 0,
                    expireTime : null,
                    sourceType : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
