<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="设备名称" prop="deviceName" v-model="form.deviceName" placeholder="请输入设备名称"/>
                            <Field label="所属房间" prop="roomId" v-model="form.roomId" :enumData="dict.roomId" placeholder="请输入所属房间"/>
                            <Field label="设备编码,SN码等，默认为MAC地址" prop="deviceCode" v-model="form.deviceCode" type="textarea" placeholder="请输入设备编码,SN码等，默认为MAC地址"/>
                            <Field label="设备的MAC地址" prop="deviceMac" v-model="form.deviceMac" placeholder="请输入设备的MAC地址"/>
                            <Field label="站点Id，来源基础服务平台" prop="siteId" v-model="form.siteId" placeholder="请输入站点Id，来源基础服务平台"/>
                            <Field label="站点编号，来源基础服务平台" prop="siteCode" v-model="form.siteCode" type="textarea" placeholder="请输入站点编号，来源基础服务平台"/>
                            <Field label="站点名称" prop="siteName" v-model="form.siteName" type="textarea" placeholder="请输入站点名称"/>
                            <Field label="产品编码" prop="productCode" v-model="form.productCode" type="textarea" placeholder="请输入产品编码"/>
                            <Field label="产品名称" prop="productName" v-model="form.productName" type="textarea" placeholder="请输入产品名称"/>
                            <Field label="设备生产厂商名称" prop="deviceFirmname" v-model="form.deviceFirmname" placeholder="请输入设备生产厂商名称"/>
                            <Field label="分辨率" prop="resolution" v-model="form.resolution" type="select" :enumData="dict.resolution" placeholder="请选择分辨率"/>
                            <Field label="所属楼栋" prop="deviceInBuilding" v-model="form.deviceInBuilding" type="select" :enumData="dict.deviceInBuilding" placeholder="请选择所属楼栋"/>
                            <Field label="所属楼层" prop="deviceInFloor" v-model="form.deviceInFloor" type="select" :enumData="dict.deviceInFloor" placeholder="请选择所属楼层"/>
                            <Field label="保修期至" prop="defectsLiabilityPeriod" v-model="form.defectsLiabilityPeriod" type="date" />
                            <Field label="负责人" prop="leadingOfficial" v-model="form.leadingOfficial" placeholder="请输入负责人"/>
                            <Field label="设备位置" prop="deviceAddr" v-model="form.deviceAddr" placeholder="请输入设备位置"/>
                            <Field label="联系电话" prop="leadingOfficialTelephone" v-model="form.leadingOfficialTelephone" placeholder="请输入联系电话"/>
                            <Field label="设备图片" prop="devicePhotoPath" v-model="form.devicePhotoPath" type="textarea" placeholder="请输入设备图片"/>
                            <Field label="设备访问ip" prop="ip" v-model="form.ip" placeholder="请输入设备访问ip"/>
                            <Field label="中心设备编码" prop="centernum" v-model="form.centernum" placeholder="请输入中心设备编码"/>
                            <Field label="端口" prop="port" v-model="form.port" placeholder="请输入端口"/>
                            <Field label="设备状态 " prop="deviceStatus" v-model="form.deviceStatus" type="select" :enumData="dict.deviceStatus" placeholder="请选择设备状态 "/>
                            <Field label="启用状态 " prop="enabled" v-model="form.enabled" type="select" :enumData="dict.enabled" placeholder="请选择启用状态 "/>
                            <Field label="备注" prop="deviceRemark" v-model="form.deviceRemark" type="textarea" placeholder="请输入备注"/>
                            <Field label="最近上线时间" prop="onlineTime" v-model="form.onlineTime" type="date" />
                            <Field label="最近离线时间" prop="offlineTime" v-model="form.offlineTime" 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: "DeviceDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("device")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "设备管理",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "resolution",
                    "deviceInBuilding",
                    "deviceInFloor",
                    "deviceStatus",
                    "enabled",
                ],
                toDate:[
                    "defectsLiabilityPeriod",
                    "onlineTime",
                    "offlineTime",
                ],
                // 表单校验
                rules: {
                    deviceName: [
                        {required: true,message: "请输入设备名称", trigger: "blur" },
                        {max: 20,message: "最多只能录入20个字符",trigger: "blur",},
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                },urls: {
                currUrl: "/device/list",
                editUrl: "/device/edit",
                saveUrl: "/device/save",
              },
            };
        },

        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;
            },

          beforeSubmit(data) {
            data.roomName=this.dict.roomId[data.roomId]
            return data
          },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    deviceName : "",
                    roomId : null,
                    roomName : "",
                    deviceCode : "",
                    deviceMac : "",
                    siteId : 1,
                    siteCode : "",
                    siteName : "",
                    productCode : "",
                    productName : "",
                    deviceFirmname : "",
                    resolution : 0,
                    deviceInBuilding : null,
                    deviceInFloor : null,
                    defectsLiabilityPeriod : null,
                    leadingOfficial : "",
                    deviceAddr : "",
                    leadingOfficialTelephone : "",
                    devicePhotoPath : "",
                    ip : "",
                    centernum : "",
                    port : "",
                    deviceStatus : 0,
                    enabled : 1,
                    deviceRemark : "",
                    onlineTime : null,
                    offlineTime : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
