<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="reason">
          <el-input
            type="textarea"
            v-model="state.form.reason"
            rows="5"
            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,
  },
});
const state = reactive({
  form: {
    reason: "",
  },
  rules: {
    reason: [{ required: true, message: "请输入关闭原因", trigger: "blur" }],
  },
});
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>
