
import { reactive, ref, UnwrapRef } from 'vue';
import { FormState } from './interface';

export function handleForm() {
    const formRef = ref();
    const formState: UnwrapRef<FormState> = reactive(initFormState());
    const rules = {
        agreementno: [{ required: true, message: '请输入协议编号', trigger: 'blur' }],
        agreementname: [{ required: true, message: '请输入协议名称', trigger: 'blur' }],
        agreementtype: [{ required: true, message: '请选择协议类型', type: 'number' }],
        agreementcontent: [{ required: true, message: '请输入协议内容', trigger: 'blur' }],
    };
    return { formRef, formState, rules }
}

/**
 * 初始化表单数据
 * @returns 
 */
export function initFormState(): FormState {
    return {
        agreementno: '',
        agreementname: '',
        agreementcontent: '',
        agreementtype: undefined,
    }
}
