<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="页面名称" prop="pageName" v-model="form.pageName" placeholder="请输入页面名称"/>
                            <Field label="页面类型" prop="pageType" v-model="form.pageType" type="select" :enumData="dict.pageType" placeholder="请选择页面类型"/>
                            <Field label="页面短链接" prop="pageUrl" v-model="form.pageUrl" placeholder="请输入页面短链接"/>
                            <Field label="可以是一个包含其他页面信息的JSON对象或单独的字段，根据页面的具体需求来设计" prop="otherDetail" v-model="form.otherDetail" type="textarea" placeholder="请输入可以是一个包含其他页面信息的JSON对象或单独的字段，根据页面的具体需求来设计"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
                            <Field label="收藏时间" prop="favoriteTime" v-model="form.favoriteTime" type="date" />

            </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: "PageDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("page")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "页面信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "pageType",
                ],
                toDate:[
                    "favoriteTime",
                ],
                // 表单校验
                rules: {
                    pageName: [
                        {required: true,message: "请输入页面名称", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    pageUrl: [
                        {required: true,message: "请输入页面短链接", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    favoriteTime: [
                        {required: true,message: "请选择收藏时间" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="page/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改页面信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "page/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增页面信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="page/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 = {
                    pageName : "",
                    pageType : null,
                    pageUrl : "",
                    otherDetail : "",
                    remark : "",
                    favoriteTime : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
