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

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

    const rules = {
        PricedPrice: [{ required: true, validator: (rule: RuleObject, value: number) => validate(value, '价格不能小于0') }],
        PricedQty: [{ required: true, validator: (rule: RuleObject, value: number) => validate(value, '数量不能小于0') }],
    }
    return { rules, formState, formRef }
}