<script setup lang="ts">
import ErrorBaseEquipmentTypeFormatter from "@/plugin/formatter/ErrorBaseEquipmentTypeFormatter.ts";
import {computed, ref} from "vue";
import BaseErrorApi from "@/api/baseError.ts";
import type {AppServeDataResponse} from "@/interface/api/AppServeDataResponse.ts";
import type {IAppBaseErrorInfo} from "@/model/table/IAppBaseErrorInfo.ts";
import {AppServeResponseCodeEnum} from "@/constant/enums/AppServeResponseCodeEnum.ts";
import MessageUtils from "@/utils/MessageUtils.ts";

const modelValue = defineModel('modelValue', {required: true, default: false});
const props = defineProps(['formData']);
const close = () => { modelValue.value = false; };
const errorBaseEquipmentTypeFormatter = new ErrorBaseEquipmentTypeFormatter(); // 设备报警基础资料设备型号格式化
let formData = computed(() => props.formData);
const errorDetail = ref<IAppBaseErrorInfo>({});

// 获取数据
const getData = () => {
  errorDetail.value = {};
  if(formData.value.equipmentType == null || formData.value.errCode == null) {
    console.log(formData.value);
    return;
  }
  BaseErrorApi.getBaseError(formData.value.equipmentType, formData.value.errCode).then(res => {
    const response = JSON.parse(JSON.stringify(res.data)) as AppServeDataResponse<IAppBaseErrorInfo>;
    if(response.code == AppServeResponseCodeEnum.SUCCESS && response.data != null) {
      errorDetail.value = response.data;
      return;
    }
    MessageUtils.errMessageBox(response.msg);
  }).catch(() => {});
}
</script>

<template>
  <el-dialog v-model="modelValue" title="报警信息资料" @close="close" :close-on-click-modal="false" @opened="getData">
    <el-scrollbar style="height:50vh;">
      <el-form :model="formData" label-position="right" label-width="100px" require-asterisk-position="right" style="width: calc(100% - 10px)">
        <el-form-item label="设备类型:" required>
          <el-select v-model="formData.equipmentType" disabled>
            <el-option v-for="item in errorBaseEquipmentTypeFormatter.equipmentType" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报警编号:" required>
          <el-input v-model="formData.errCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="报警信息:" required>
          <el-input v-model="errorDetail.errMsg" placeholder="无信息" type="textarea" :maxlength="100" :rows="5" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="建议:">
          <el-input v-model="errorDetail.suggest" placeholder="无建议" type="textarea" :maxlength="100" :rows="5" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="备注:">
          <el-input v-model="errorDetail.remark" placeholder="无备注"></el-input>
        </el-form-item>
      </el-form>
    </el-scrollbar>
    <template #footer>
      <el-button-group>
        <el-button type="danger" @click="close">关闭窗口</el-button>
      </el-button-group>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>