<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="siteId" v-model="form.siteId" placeholder="请输入站点Id"/>
                            <Field label="站点名称" prop="siteName" v-model="form.siteName" type="textarea" placeholder="请输入站点名称"/>
                            <Field label="设备ID，海康" prop="deviceId" v-model="form.deviceId" placeholder="请输入设备ID，海康"/>
                            <Field label="设备名称" prop="deviceName" v-model="form.deviceName" placeholder="请输入设备名称"/>
                            <Field label="设备编码" prop="deviceCode" v-model="form.deviceCode" type="textarea" placeholder="请输入设备编码"/>
                            <Field label="设备的MAC地址" prop="deviceMac" v-model="form.deviceMac" placeholder="请输入设备的MAC地址"/>
                            <Field label="设备位置" prop="deviceLocation" v-model="form.deviceLocation" type="textarea" placeholder="请输入设备位置"/>
                            <Field label="经度" prop="lon" v-model="form.lon" placeholder="请输入经度"/>
                            <Field label="纬度" prop="lati" v-model="form.lati" placeholder="请输入纬度"/>
                            <Field label="楼层" prop="floor" v-model="form.floor" placeholder="请输入楼层"/>
                            <Field label="楼栋" prop="build" v-model="form.build" placeholder="请输入楼栋"/>
                            <Field label="负责人" prop="leadingOfficial" v-model="form.leadingOfficial" placeholder="请输入负责人"/>
                            <Field label="联系电话" prop="leadingOfficialTelephone" v-model="form.leadingOfficialTelephone" placeholder="请输入联系电话"/>
                            <Field label="超时时间，单位天" prop="timeOutPeriod" v-model="form.timeOutPeriod" placeholder="请输入超时时间，单位天"/>
                            <Field label="临近时间，单位天" prop="nearTime" v-model="form.nearTime" placeholder="请输入临近时间，单位天"/>
                            <Field label="设备状态 " prop="deviceStatus" v-model="form.deviceStatus" type="select" :enumData="dict.deviceStatus" placeholder="请选择设备状态 "/>
                            <Field label="备注" prop="deviceRemark" v-model="form.deviceRemark" type="textarea" placeholder="请输入备注"/>

            </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:[
                    "deviceStatus",
                ],
                // 表单校验
                rules: {
                    deviceName: [
                        {required: true,message: "请输入设备名称", trigger: "blur" },
                        {max: 20,message: "最多只能录入20个字符",trigger: "blur",},
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="device/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改设备业务";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "device/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增设备业务";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="device/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 : "",
                    deviceId : "",
                    deviceName : "",
                    deviceCode : "",
                    deviceMac : "",
                    deviceLocation : "2",
                    lon : "",
                    lati : "",
                    floor : null,
                    build : null,
                    leadingOfficial : "",
                    leadingOfficialTelephone : "",
                    timeOutPeriod : null,
                    nearTime : null,
                    deviceStatus : null,
                    deviceRemark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
