<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="新闻ID" prop="newsId" v-model="form.newsId" placeholder="请输入新闻ID"/>
                            <Field label="查看人名称" prop="viewName" v-model="form.viewName" placeholder="请输入查看人名称"/>
                            <Field label="累计查看次数" prop="sumViews" v-model="form.sumViews" placeholder="请输入累计查看次数"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
                            <Field label="最后浏览时间" prop="viewTime" v-model="form.viewTime" 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: "NewsRecordDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("news/record")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "新闻访问记录信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                ],
                toDate:[
                    "viewTime",
                ],
                // 表单校验
                rules: {
                    viewName: [
                        {required: true,message: "请输入查看人名称", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    viewTime: [
                        {required: true,message: "请选择最后浏览时间" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="news/record/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改新闻访问记录信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "news/record/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增新闻访问记录信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="news/record/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 = {
                    newsId : null,
                    viewName : "",
                    sumViews : 0,
                    remark : "",
                    viewTime : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
