import React, { useRef } from 'react';
import { message } from 'antd';
import Search from '../../extra/associationSearch';
import { ApolloSearchProps } from '../editInterface';
import { antiAssign } from '../../../../utils/utils';
import { onBlurFn } from '../onBlurFn';
import s from './index.less';
export const ApolloSearch = (props: ApolloSearchProps) => {
const { onChange, maxCount, isMultiple, request, origin } = props;
const selfProps = antiAssign(props, ['columnConfig', 'onChange', 'isMultiple', 'options', 'request', 'maxCount']);
const isOpen = useRef();
if (isMultiple) {
selfProps.mode = 'multiple';
}
const changeValue = (value: any) => {
if (isMultiple && maxCount && maxCount < value.length) {
message.warn(`最多选择${maxCount}个`);
return;
}
if (typeof onChange === 'function') {
if (typeof onBlurFn === 'function' && !isOpen.current) {
onBlurFn({ ...props, value });
}
onChange(value, value);
}
};
const singleBlurFn = (e: boolean) => {
isOpen.current = e;
};
const multipleBlurFn = (e: boolean) => {
isOpen.current = e;
if (typeof onBlurFn === 'function' && !e) {
onBlurFn(props);
}
};
return (
origin === 'editForm' ?
:
);
};