import React from 'react'; import {Func, ExpressionFunc, Field, Funcs} from './types'; import {ThemeProps, themeable} from '../../theme'; import PopOverContainer from '../PopOverContainer'; import ListRadios from '../ListRadios'; import {autobind, findTree, noop} from '../../utils/helper'; import ResultBox from '../ResultBox'; import {Icon} from '../icons'; import Expression from './Expression'; import {Config} from './config'; export interface ConditionFuncProps extends ThemeProps { value: ExpressionFunc; onChange: (value: ExpressionFunc) => void; disabled?: boolean; config: Config; fields?: Field[]; funcs?: Funcs; allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>; fieldClassName?: string; } const option2value = (item: Func) => item.type; export class ConditionFunc extends React.Component { @autobind handleFuncChange(type: string) { const value = {...this.props.value}; value.func = type; this.props.onChange(value); } @autobind handleArgChange(arg: any, index: number) { const value = {...this.props.value}; value.args = Array.isArray(value.args) ? value.args.concat() : []; value.args.splice(index, 1, arg); this.props.onChange(value); } renderFunc(func: Func) { const {classnames: cx, fields, value, funcs, config, disabled} = this.props; return (
( {Array.isArray(func.args) && func.args.length ? (
{func.args.map((item, index) => ( ))}
) : null} )
); } render() { const {value, classnames: cx, fieldClassName, funcs, disabled} = this.props; const func = value ? findTree(funcs!, item => (item as Func).type === value.func) : null; return (
( )} > {({onClick, ref, isOpened}) => (
)}
{func ? ( this.renderFunc(func as Func) ) : ( 方法未定义 )}
); } } export default themeable(ConditionFunc);