import React, { useMemo, useState } from 'react'; import Wrap from '../wrap/Wrap'; import Icon from 'src/components/Icon/index'; import { Select } from 'antd'; import { returnClass } from '../unit'; import '../g.scss'; const { Option } = Select; function LabelSelect(props: ILabelSelect) { const { title, selectList = [], change, size = 'normal', value, paddingSize, selectLoading, suffixIcon, wrapStyle = { padding: '6px 20px 6px 20px' }, padding, customStyle = {}, dropdownMatchSelectWidth = true, // 下拉菜单和选择器同宽 placement = 'bottomLeft', // 选择框弹出的位置 isError, placeholder, allowClear = false, clearIcon, isRequired = false, mode } = props; const [selectValue, setSelectValue] = useState(value); const multipleChange = (value) => { setSelectValue(value); }; const returnOption = (rest: ISelectList, index: number) => { if (rest?.type === 'one') { return ( ); } else if (rest?.type === 'img') { return ( ); } else { return ( ); } }; const tagRender = (props) => { const { value } = props; return value ? {value}, : null; }; const Redio = useMemo(() => { return ( 0 : value) && (mode === 'multiple' ? !selectValue?.every((num) => selectList.some((obj) => obj.key === num) ) : !selectList?.some((item) => item?.key === value))) || (isError && !value) ? { alignItems: 'start', ...wrapStyle } : wrapStyle } > {title ? (
0 : value) && (mode === 'multiple' ? !selectValue?.every((num) => selectList.some((obj) => obj.key === num) ) : !selectList?.some((item) => item?.key === value))) || (isError && !value) ? { marginRight: paddingSize ? '' : padding, marginTop: 5 } : { marginRight: paddingSize ? '' : padding } } > {title}
) : ( <> )}
0 : value) && (mode === 'multiple' ? !selectValue?.every((num) => selectList.some((obj) => obj.key === num) ) : !selectList?.some((item) => item?.key === value))) || (isError && !value) ? { flexDirection: 'column', overflow: 'visible', alignItems: 'start' } : {} } className={ size === 'normal' ? 'zl-large-screen-setting-unit-content' : 'zl-large-screen-setting-unit-content-large' } > {isError ? ( {isError && (mode === 'multiple' ? selectValue?.length > 0 : value) && (mode === 'multiple' ? !selectValue?.every((num) => selectList.some((obj) => obj.key === num) ) : !selectList?.some((item) => item?.key === value)) ? '字段失效请重新选择' : isError && !value && isRequired ? '该字段是必填字段' : ''} ) : ( <> )}
); }, [selectList, value, title, allowClear, selectValue]); return Redio; } export default LabelSelect; export interface ILabelSelect { title: string | number; selectList: ISelectList[]; change: Function; size: string; value?: any; paddingSize?: string; selectLoading?: boolean; suffixIcon?: any; wrapStyle?: React.CSSProperties; padding?: number; customStyle?: React.CSSProperties; dropdownMatchSelectWidth?: boolean; placement?: string; isError?: boolean; placeholder?: string; allowClear?: boolean; clearIcon?: string; mode?: string; isRequired?: boolean; } export interface ISelectList { key: number | string; name: string | number; type: string; names?: string; img?: string; nameType?: string; nameColor?: string; }