<template>
  <el-card style="margin: 5px;margin-top: -20px">
    <el-form :model="formData" ref="dataForm" label-width="100px" style="margin-bottom: -15px">
      <el-button-group style="display: flex;margin: 0px 0 10px 80%; height: 35px">
        <el-button
          type="primary"
          @click.native="submit()"
        >保存
        </el-button>
      </el-button-group>

      <el-row>
        <el-col :span="10">
          <el-form-item label="部门名称:">
            <el-input v-model="formData.deptName" placeholder="请输入部门名称" style="width: 90%"
                      clearable disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="仓库名称:">
            <el-input v-model="formData.invName" placeholder="请输入仓库名称" style="width: 90%" clearable
                      disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="设备名称:">
            <el-input v-model="formData.deviceName" placeholder="请输入编码" style="width: 90%" clearable
                      disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="物资编码:">
            <el-input v-model="formData.code" placeholder="请输入物资编码" style="width: 90%" clearable
                      disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="时间频率:">
            <el-input v-model="formData.frequency" placeholder="请输入时间频率" style="width: 90%" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="时间频率单位:">
            <el-select v-model="formData.frequencyUnit"
                       placeholder="请选择时间单位"
                       clearable="true"
                       style="width: 90%"
            >
              <el-option label="年" :value="1"></el-option>
              <el-option label="月" :value="2"></el-option>
              <el-option label="日" :value="3"></el-option>
              <el-option label="小时" :value="4"></el-option>
              <el-option label="分钟" :value="5"></el-option>
              <el-option label="秒" :value="6"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="18">
          <el-form-item label="备注:">
            <el-input v-model="formData.remark" type="textarea" style="width: 100%" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>

</template>

<script>
import {findInspectSet, saveDeviceInspect} from "@/api/dev/deviceInspectSet";
import {isBlank} from "@/utils/strUtil";

export default {
  props: {
    code: {
      type: String,
      required: true
    },
    closeDialog: {
      type: Function,
      required: true
    }
  },
  name: "deptDeviceModifyDialog",
  data() {
    return {
      formData: {
        id: null,
        code: null,
        frequency: null,
        frequencyUnit: null,
        status: 1,
        remark: null,
        deptName: null,
        invName: null,
        deviceName: null
      },
    };
  },
  methods: {
    submit() {
      let type = isBlank(this.formData.id) ? "add" : "edit";
      saveDeviceInspect(this.formData, type).then((res) => {
        if (res.code === 20000) {
          this.$message.success("操作成功");
          this.closeDialog();
        } else {
          this.$message.error(res.message);
        }
      }).catch((error) => {
        this.$message.error(error.message);
      })
    },
    findSetInfo() {
      let params = {code: this.code};
      findInspectSet(params).then((res) => {
        this.formData = res.data;
      })
    },
  },
  created() {
    this.findSetInfo();
  },
}
</script>

<style scoped>

</style>
