<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="告警设备Id" prop="deviceId" v-model="form.deviceId" placeholder="请输入告警设备Id"/>
                            <Field label="告警设备编码" prop="deviceCode" v-model="form.deviceCode" placeholder="请输入告警设备编码"/>
                            <Field label="告警类型," prop="alarmType" v-model="form.alarmType" type="select" :enumData="dict.alarmType" placeholder="请选择告警类型,"/>
                            <Field label="告警级别" prop="alarmLevel" v-model="form.alarmLevel" type="select" :enumData="dict.alarmLevel" placeholder="请选择告警级别"/>
                            <Field label="告警详细内容" prop="alarmContent" v-model="form.alarmContent" type="textarea" placeholder="请输入告警详细内容"/>
                            <Field label="告警时间" prop="alarmTime" v-model="form.alarmTime" type="date" />

            </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";
    export default {
        mixins: [form],
        components: {
            dialogShow ,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "设备告警日志",
                // 是否显示弹出层
                open: false,
                toString:[
                    "alarmType",
                    "alarmLevel",
                ],
                // 表单校验
                rules: {
                    deviceCode: [
                        {required: true,message: "请输入告警设备编码", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    alarmType: [
                        {required: true,message: "请输入告警类型,", trigger: "blur" },
                    ],
                    alarmLevel: [
                        {required: true,message: "请输入告警级别", trigger: "blur" },
                    ],
                    alarmContent: [
                        {required: true,message: "请输入告警详细内容", trigger: "blur" },
                        {max: 512,message: "最多只能录入512个字符",trigger: "blur",},
                    ],
                    alarmTime: [
                        {required: true,message: "请选择告警时间" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="device/alarm/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改设备告警日志";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "device/alarm/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增设备告警日志";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="device/alarm/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 = {
                    deviceId : null,
                    deviceCode : "",
                    alarmType : null,
                    alarmLevel : null,
                    alarmContent : "",
                    alarmTime : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
