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

export function handleForm() {
    const formRef = ref();
    const formState: UnwrapRef<FormParam> = reactive({
        AppointmentDate: ref<Moment>(),
        ContactName: '',
        ContactNum: '',
        AppointmentRemark: '',
        OutQty: 0,
    })
    const v_group = async (rule: RuleObject, value: number) => {
        return validateCommon(value, '请选择预约日期');
    };
    const rules = {
        AppointmentDate: [{ required: true, validator: v_group, trigger: 'change' }],
        ContactName: [{ required: true, message: '请输入提货人', trigger: 'blur' }],
        ContactNum: [{ required: true, message: '请输入联系方式', trigger: 'blur' }],
        OutQty: [{ required: true, message: '请输入挂牌数量', trigger: 'blur', type: 'number', min: 1, }],
    }
    return { rules, formState, formRef }
}
