<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="60%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                <Field :span="20"  label="站点Id" prop="siteId" v-model="form.siteId" placeholder="请输入站点Id"/>
                <Field :span="20" label="站点名称" prop="siteName" v-model="form.siteName" type="textarea" placeholder="请输入站点名称"/>
                <Field :span="20" label="告警时间" prop="alarmTime" v-model="form.alarmTime" type="date" />
                <Field :span="20"  label="告警类型" prop="alarmType" v-model="form.alarmType" placeholder="请输入告警类型"/>
                <Field :span="20" label="告警级别" prop="alarmLevel" v-model="form.alarmLevel" type="select" :enumData="dict.alarmLevel" placeholder="请选择告警级别"/>
                <Field :span="20"  label="接收人员" prop="alarmReceivePersonnel" v-model="form.alarmReceivePersonnel" placeholder="请输入接收人员"/>
                <Field :span="20"  label="接收人员电话" prop="receivePersonnelTelephone" v-model="form.receivePersonnelTelephone" placeholder="请输入接收人员电话"/>
                <Field :span="20" label="告警详细内容"><editor v-model="form.alarmContent" :min-height="256"/></Field>
                <Field :span="20" label="推送" prop="push" v-model="form.push" type="select" :enumData="dict.push" placeholder="请选择推送"/>
                <Field :span="20" label="备注信息" prop="remark" v-model="form.remark" 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: "AlarmRecordsDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("alarm/records")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "告警消息记录",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "alarmLevel",
                    "push",
                ],
                toDate:[
                    "alarmTime",
                ],
                // 表单校验
                rules: {
                    alarmType: [
                        {required: true,message: "请输入告警类型", trigger: "blur" },
                        {max: 32,message: "最多只能录入32个字符",trigger: "blur",},
                    ],
                    alarmLevel: [
                        {required: true,message: "请输入告警级别", trigger: "blur" },
                    ],
                    alarmReceivePersonnel: [
                        {required: true,message: "请输入接收人员", trigger: "blur" },
                        {max: 32,message: "最多只能录入32个字符",trigger: "blur",},
                    ],
                    receivePersonnelTelephone: [
                        {required: true,message: "请输入接收人员电话", trigger: "blur" },
                        {max: 11,message: "最多只能录入11个字符",trigger: "blur",},
                    ],
                    alarmContent: [
                        {required: true,message: "请输入告警详细内容", trigger: "blur" },
                        {max: 512,message: "最多只能录入512个字符",trigger: "blur",},
                    ],
                    remark: [
                        {required: true,message: "请输入备注信息", trigger: "blur" },
                        {max: 256,message: "最多只能录入256个字符",trigger: "blur",},
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="alarm/records/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改告警消息记录";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "alarm/records/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增告警消息记录";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="alarm/records/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 = {
                    siteId : null,
                    siteName : null,
                    alarmTime : null,
                    alarmType : null,
                    alarmLevel : 0,
                    alarmReceivePersonnel : null,
                    receivePersonnelTelephone : null,
                    alarmContent : null,
                    push : 0,
                    remark : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
