<template>
  <div class="oroqen-product-form">
    <BasicForm @register="registerForm" />
  </div>
</template>

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

  const props = defineProps({
    formData: {
      type: Object,
      default: () => ({})
    }
  });

  const emit = defineEmits(['submit']);

  //表单配置
  const [registerForm, { setFieldsValue, validate, resetFields }] = useForm({
    schemas: formSchema,
    showActionButtonGroup: false,
    baseColProps: { span: 24 }
  });

  // 监听表单数据变化
  watch(() => props.formData, (newData) => {
    if (newData && Object.keys(newData).length > 0) {
      setFieldsValue(newData);
    }
  }, { immediate: true, deep: true });

  // 暴露方法给父组件
  defineExpose({
    validate,
    resetFields,
    setFieldsValue
  });
</script>

<style scoped>
.oroqen-product-form {
  padding: 16px;
}
</style>