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 formState: UnwrapRef<FormState> = reactive({
        accountid: undefined,
        OrderQty: 0,
        FixedPrice: 0,
        PriceMove: 0
    })
    const v_price = async (rule: RuleObject, value: number) => {
        return validateCommon(value, '请输入挂牌价格');
    };
    const v_num = async (rule: RuleObject, value: number) => {
        return validateCommon(value, '请输入挂牌数量');
    };
    const rules = {
        accountid: [{ required: true, message: '请选择交易账户' }],
        OrderQty: [
            { required: true, trigger: 'blur', type: 'number', validator: v_num },
        ],
        FixedPrice: [
            { required: true, trigger: 'blur', type: 'number', validator: v_price },
        ],

    }
    return { rules, formState, formRef }

}
