| | |
| | | useTranslate, useNotify, required |
| | | } from 'react-admin'; |
| | | import request from '@/utils/request'; |
| | | import { Select, MenuItem, FormControl, InputLabel } from '@mui/material'; |
| | | import { Autocomplete, TextField, FormControl } from '@mui/material'; |
| | | |
| | | const DictSelect = (props) => { |
| | | const { dictTypeCode, label, group, value, onChange, ...params } = props; |
| | |
| | | } |
| | | }; |
| | | |
| | | const handleChange = (event) => { |
| | | const selectedValue = event.target.value; |
| | | const validValueObj = list.find(item => item.value === value) || null; |
| | | |
| | | const handleChange = (event, newValue) => { |
| | | if (onChange) { |
| | | onChange(event); |
| | | onChange({ target: { value: newValue ? newValue.value : '' } }); |
| | | } |
| | | }; |
| | | |
| | | const validValue = list.some(item => item.value === value) ? value : ''; |
| | | |
| | | return ( |
| | | <FormControl fullWidth> |
| | | <InputLabel id="demo-select-small-label">{label}</InputLabel> |
| | | <Select |
| | | labelId="demo-select-small-label" |
| | | value={validValue} |
| | | variant="filled" |
| | | <FormControl fullWidth size="small"> |
| | | <Autocomplete |
| | | value={validValueObj} |
| | | onChange={handleChange} |
| | | size='small' |
| | | > |
| | | {list.map((item) => ( |
| | | <MenuItem key={item.value} value={item.value}> |
| | | {item.label} |
| | | </MenuItem> |
| | | ))} |
| | | </Select> |
| | | options={list} |
| | | getOptionLabel={(option) => option.label || ''} |
| | | isOptionEqualToValue={(option, val) => option.value === val.value} |
| | | size="small" |
| | | ListboxProps={{ style: { maxHeight: '200px' } }} |
| | | renderInput={(p) => ( |
| | | <TextField |
| | | {...p} |
| | | label={label} |
| | | variant="filled" |
| | | /> |
| | | )} |
| | | {...params} |
| | | /> |
| | | </FormControl> |
| | | ); |
| | | }; |
| | | |
| | | export default DictSelect; |
| | | export default DictSelect; |