import React, { useEffect, useState } from 'react'; import { Input, Modal } from 'antd'; import styles from './styles.less'; import { onBlurFn } from '../onBlurFn'; import { antiAssign } from '../../../../utils/utils'; import { ApolloTextAreaProps } from '../editInterface'; import { Consumer } from '../../../context'; export const ApolloTextArea = (props: ApolloTextAreaProps) => { const { maxLength, onChange, value, getDetail, rowData, onEmitChange, columnConfig, origin } = props; const { columnChsName } = columnConfig; const selfProps = antiAssign(props, ['columnConfig', 'onChange', 'value', 'cutLength', 'getDetail', 'rowData', 'onEmitChange']); const [curValue, setCurValue] = useState(value); const [visible, setVisible] = useState(false); useEffect(() => { if (origin !== 'editForm') { setCurValue(value); getMore(); } }, [value]); // useEffect(() => { // if (value && value.length === cutLength) { // getMore(); // } // }, []); const [inputVal, setInputVal] = useState(value) useEffect(() => { setInputVal(value); }, [value]); const changeValue = (e: any) => { if (typeof onChange === 'function') { onChange(e.target.value); } }; const inputOnBlurFn = () => { if (typeof onBlurFn === 'function') { onBlurFn(props); } }; const changeCurValue = (e: any) => { if (typeof onChange === 'function') { setCurValue(e.target.value); } }; const hide = () => { if (typeof onEmitChange === 'function') { onEmitChange(value); } setVisible(false); } const confirmChange = () => { if (typeof onEmitChange === 'function') { onEmitChange(curValue); } setVisible(false); } const getMore = async () => { if (getDetail && rowData) { let newValue = await getDetail({ rowId: rowData.id }); if (newValue) { newValue = newValue[0] && newValue[0].value; setCurValue(newValue); setVisible(true); } } }; if (origin === 'editForm') { return ( {({ locale }) => { return ( { changeValue(e) setInputVal(e.target.value) }} /> {!!maxLength && ( {`${locale.alreadyInput} ${(value || '').length}/${maxLength}`} )} ); }} ) } return ( {({ locale }) => { return ( {!!maxLength && ( {`${locale.alreadyInput} ${(curValue || '').length}/${maxLength}`} )} ); }} ); };