<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="设备名称"
          prop="deviceName"
          v-model="form.deviceName"
          placeholder="请输入设备名称"
        />
        <Field
          label="设备类型"
          prop="deviceType"
          v-model="form.deviceType"
          type="select"
          :enumData="dict.deviceType"
          placeholder="请选择设备类型"
        />
        <Field
          label="Mac地址"
          prop="deviceMac"
          v-model="form.deviceMac"
          placeholder="请输入Mac地址"
        />
        <Field
          label="设备型号"
          prop="modelNum"
          v-model="form.modelNum"
          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="设备IP"
          prop="ip"
          v-model="form.ip"
          placeholder="请输入设备IP"
        />
        <Field
          label="端口号"
          prop="port"
          v-model="form.port"
          placeholder="请输入设备端口"
        />
        <Field
          label="账号"
          prop="manageUser"
          v-model="form.manageUser"
          placeholder="请输入账号"
        />
        <Field
          label="密码"
          prop="managePWD"
          v-model="form.managePWD"
          placeholder="请输入密码"
        />
        <Field
          label="负责人"
          prop="leadingOfficial"
          v-model="form.leadingOfficial"
          placeholder="请输入负责人"
        />
        <Field
          label="电话"
          prop="telephone"
          v-model="form.telephone"
          placeholder="请输入电话"
        />
        <Field
          label="所在楼栋"
          prop="building"
          v-model="form.building"
          type="select"
          :enumData="dict.building"
          placeholder="请选择所在楼栋"
        />
        <Field
          label="所在楼层"
          prop="floor"
          v-model="form.floor"
          type="select"
          :enumData="dict.floor"
          placeholder="请选择所在楼层"
        />
        <Field
          label="设置位置"
          prop="address"
          v-model="form.address"
          placeholder="请输入设置位置（X坐标，Y坐标）"
        />
        <!-- <Field
          label="经度"
          prop="longitude"
          v-model="form.longitude"
          placeholder="请输入经度"
        />
        <Field
          label="纬度"
          prop="latitude"
          v-model="form.latitude"
          placeholder="请输入纬度"
        /> -->
        <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          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,
      // 表单校验
      rules: {},
    };
  },

  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 = {
        deviceName: null,
        deviceMac: "",
        modelNum: null,
        deviceFirmname: "",
        resolution: null,
        deviceType: null,
        ip: null,
        port: null,
        manageUser: null,
        managePWD: "",
        leadingOfficial: null,
        approver: "",
        telephone: "",
        building: null,
        floor: null,
        remark: "",
        latitude: "",
        longitude: "",
        address: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
