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({
        MerUserID: undefined,// uint64 跟单员ID
        TradeUserID: undefined,// uint64 交易员ID
        SaleUserID: undefined, // uint64 业务员ID
        Remark: ''
    })
    // 验证跟单员
    async function v_MerUser(rule: RuleObject, value: number) {
        return validateCommon(value, '请选择跟单员')
    }
    // 验证交易员
    async function v_TradeUser(rule: RuleObject, value: number) {
        return validateCommon(value, '请选择交易用户')
    }
    // 验证业务员
    async function v_SaleUser(rule: RuleObject, value: number) {
        return validateCommon(value, '请选择业务员')
    }
    const rules = {
        MerUserID: [{ required: true, validator: v_MerUser, trigger: 'blur' }],
        TradeUserID: [{ required: true, validator: v_TradeUser, trigger: 'blur' }],
        SaleUserID: [{ required: true, validator: v_SaleUser, trigger: 'blur' }],
    }
    return { rules, formState, formRef }
}