<template>
  <div>
    <BasicForm @register="registerForm" />
  </div>
</template>

<script lang="ts" setup>
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { formSchema } from '../OroqenCultureContent.data';
  import { saveOrUpdate } from '../OroqenCultureContent.api';

  // Emits
  const emit = defineEmits(['success', 'register']);

  const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
    labelWidth: 100,
    schemas: formSchema,
    showActionButtonGroup: false,
    actionColOptions: {
      span: 23,
    },
  });

  // 暴露内部方法
  defineExpose({
    setFieldsValue,
    resetFields,
    validate,
    handleSubmit,
  });

  /**
   * 提交表单
   */
  async function handleSubmit() {
    try {
      const values = await validate();
      await saveOrUpdate(values, values.id);
      emit('success');
    } catch (error) {
      console.error('表单提交失败:', error);
    }
  }
</script>