<template>
  <el-dialog v-model="visible" title="请填写结论建议" :on-close="fnClose">
    <div>
      <el-input
        v-model="advice"
        type="textarea"
        :autosize="{
          minRows: 3,
        }"
      />
    </div>
    <template #footer>
      <el-button @click="fnClose">取 消</el-button>
      <el-button type="primary" @click="fnSubmit">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { useVModels } from "@vueuse/core";
import { debounce } from "throttle-debounce";
import {
  setEnterpriseReportConclusionAdd,
  setEnterpriseReportConclusionEdit,
} from "@/request/continuous_improvement.js";

const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
    default: false,
  },
  advice: {
    type: String,
    required: true,
    default: "",
  },
  corpAdvice: {
    type: Object,
    required: true,
    default: () => ({}),
  },
  month: {
    type: String,
    required: true,
    default: "",
  },
});
const emits = defineEmits(["update:visible", "update:advice", "submit"]);
const { visible, advice } = useVModels(props, emits);
const fnClose = () => {
  visible.value = false;
};
const fnSubmit = debounce(
  1000,
  async () => {
    if (props.corpAdvice.CORPADVICE_ID) {
      await setEnterpriseReportConclusionEdit({
        ...props.corpAdvice,
        ADVICE: advice.value,
      });
    } else {
      await setEnterpriseReportConclusionAdd({
        ADVICE_DATE: props.month,
        ADVICE: advice.value,
      });
    }
    fnClose();
    emits("submit");
  },
  { atBegin: true }
);
</script>

<style scoped lang="scss"></style>
