<template>
  <el-dialog v-model="visible" title="修改" :before-close="fnClose">
    <el-form ref="formRef" :rules="rules" :model="form" label-width="100px">
      <el-form-item label="检查内容" prop="CHECK_CONTENT">
        <el-input
          v-model="form.CHECK_CONTENT"
          type="textarea"
          :autosize="{ minRows: 3 }"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="fnClose">取消</el-button>
      <el-button type="primary" @click="fnSubmit"> 确定 </el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import { useVModels } from "@vueuse/core";
import { debounce } from "throttle-debounce";
import useFormValidate from "@/assets/js/useFormValidate.js";
import { setRiskControlLedgerAllocationEdit } from "@/request/risk_control.js";
import { ElMessage } from "element-plus";

const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
    default: false,
  },
  form: {
    type: Object,
    required: true,
    default: () => ({}),
  },
});
const emits = defineEmits(["update:visible", "update:form", "get-data"]);
const { visible, form } = useVModels(props, emits);
const rules = {
  CHECK_CONTENT: [
    { required: true, message: "检查内容不能为空", trigger: "blur" },
  ],
};
const formRef = ref(null);
const fnClose = () => {
  formRef.value.resetFields();
  visible.value = false;
};
const fnSubmit = debounce(
  1000,
  async () => {
    await useFormValidate(formRef);
    await setRiskControlLedgerAllocationEdit({ ...form.value });
    ElMessage.success("操作成功");
    fnClose();
    emits("get-data");
  },
  { atBegin: true }
);
</script>

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