import { reactive, ref, UnwrapRef } from "vue";
import { RuleObject } from 'ant-design-vue/lib/form/interface';
/**
 * 表单
 * @returns 
 */
export function handleForm() {
    interface FormState {
        InvoiceAmount: number | null
    }
    const formRef = ref();
    const formState: UnwrapRef<FormState> = reactive({
        InvoiceAmount: null,
    })

    const validate = async (value: number, message = '') => {
        if (value <= 0) {
            return Promise.reject(message)
        }
    }

    const rules = {
        InvoiceAmount: [{ required: true, validator: (rule: RuleObject, value: number) => validate(value) }],
    }
    return { rules, formState, formRef }
}