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

<script lang="ts" setup>
  import { ref, nextTick, defineExpose } from 'vue';
  import YinyongTikuDcList from './YinyongTikuDcList.vue'
  
  const title = ref<string>('');
  const width = ref<string>('80%');
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);

  
  /**
   * 编辑
   * @param record
   */
  function init(record) {
    title.value = '题库';
    visible.value = true;
    nextTick(() => {
      registerForm.value.init(record);
    });
  }
  
  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    registerForm.value.submitForm();
  }

  /**
   * form保存回调事件
   */
  function submitCallback(record) {
    console.log(`🚀 ~ submitCallback ~ record:`, record)
    handleCancel();
    emit('success',record);
  }

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

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

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