<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="shareName" v-model="form.shareName" placeholder="请输入分享人名称"/>
                            <Field label="累计分享次数" prop="sumShares" v-model="form.sumShares" placeholder="请输入累计分享次数"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
                            <Field label="最近分享时间" prop="shareTime" v-model="form.shareTime" 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: "NewsShareDetail",
        mixins: [form],
        components: {

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

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