import { validateCommon } from "@/common/setup/validate";
import { RuleObject } from "ant-design-vue/lib/form/interface";
import { reactive, ref, UnwrapRef } from "vue";
import { FormState } from "./interface";

export function handleForm() {
    const formRef = ref();
    const v_num = async (rule: RuleObject, value: number) => {
        return validateCommon(value, '请输入协议价');
    };
    const formState: UnwrapRef<FormState> = reactive({
        price: 0,
    })
    const rules = {
        price: [
            { require: true, message: '请输入协议价', trigger: 'blur', type: 'number', validator: v_num },
        ],
    }
    return { rules, formState, formRef }
}

export function usePrice(formState: UnwrapRef<FormState>) {
    function increasePirce() {
        formState.price++
    }
    function decreasePrice() {
        if (formState.price) {
            formState.price--
        }
    }
    return { increasePirce, decreasePrice }
}
