<template>
  <el-dialog v-model="show" width="774px" top="10vh" :before-close="beforeClose" :close-on-click-modal="false">
    <template #header>
      <GapTitle title="处置反馈"></GapTitle>
    </template>
    <div class="feedback-body">
      <el-form :model="state.form" ref="form" :rules="state.rules" label-width="80px">
        <el-form-item label="预警状态" prop="status" v-if="props.isWarn">
          <el-radio-group v-model="state.form.status">
            <el-radio v-for="(value, key) in status" :key="key" :label="key">
              {{ value }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="结果反馈" prop="result">
          <el-input
            type="textarea"
            v-model="state.form.result"
            rows="5"
            maxlength="100"
            show-word-limit
            placeholder="请输入结果反馈"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <el-button size="default" @click="Close">关闭</el-button>
      <el-button type="primary" size="default" @click="Submit">保存</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { computed, reactive, ref } from "vue";
import GapTitle from "@/components/gap-title.vue";

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  beforeClose: {
    type: Function,
    default: () => {},
  },
  active_row: {
    type: Object,
    default: null,
  },
  isWarn: {
    type: Boolean,
    default: false,
  },
});
const state = reactive({
  form: {
    status: "",
    result: "",
  },
  rules: {
    status: [{ required: true, message: "请选择预警状态", trigger: "change" }],
    result: [{ required: true, message: "请输入结果反馈", trigger: "blur" }],
  },
});
const status = {
  1: "未恢复",
  2: "已恢复",
};
const emits = defineEmits(["update:visible"]);
const form = ref(null);
const Close = () => {
  form.value.resetFields();
  emits("update:visible", false);
};
const show = computed({
  get() {
    return props.visible;
  },
  set() {
    Close();
  },
});
const beforeClose = () => {
  props.beforeClose();
  Close();
};
const Submit = () => {
  form.value.validate((valid) => {
    if (valid) {
      console.log(state.form);
    } else {
      return false;
    }
  });
};
</script>

<style lang="scss" scoped>
.feedback-body {
  text-align: left;
  padding: 24px 16px 0;
}
</style>
