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

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

    const rules = {
        Amount: [{ required: true, validator: (rule: RuleObject, value: number) => validate(value, '金额不能小于0') }],
    }
    return { rules, formState, formRef }
}