<template>
  <a-modal :title="title" :width="width" centered :visible="visible" @ok="handleOk" :okButtonProps="{ class: { 'jee-hidden': disableSubmit }, loading: loading }" @cancel="handleCancel" cancelText="关闭">
    <WjxWjxxTmlbDjForm ref="registerForm" @ok="submitCallback" @closeLoading="closeLoading" :formDisabled="disableSubmit" :formBpm="false"></WjxWjxxTmlbDjForm>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, nextTick, defineExpose } from 'vue';
  import WjxWjxxTmlbDjForm from './WjxWjxxTmlbDjForm.vue'

  const title = ref<string>('');
  const width = ref<string>('80%');
  const visible = ref<boolean>(false);
  const loading = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);

  /**
   * 编辑
   * @param record
   */
  function edit(record,isDisabled) {
    title.value = disableSubmit.value ? '详情' : '编辑';
    visible.value = true;
    loading.value = false;
    nextTick(() => {
      registerForm.value.edit(record,isDisabled);
    });
  }

  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    loading.value = true;
    registerForm.value.submitForm();
  }

  /**
   * 确定按钮点击事件
   */
  function closeLoading() {
    loading.value = false;
  }


  /**
   * form保存回调事件
   */
  function submitCallback() {
    loading.value = false;
    handleCancel();
    emit('success');
  }

  /**
   * 取消按钮回调事件
   */
  function handleCancel() {
    visible.value = false;
  }

  defineExpose({
    edit,
    disableSubmit,
  });
</script>

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
</style>
