| | |
| | | import { useState, useEffect } from 'react'; |
| | | import { |
| | | useTranslate, useNotify, required |
| | | useTranslate, useNotify, required, AutocompleteInput |
| | | } from 'react-admin'; |
| | | import request from '@/utils/request'; |
| | | import { Select, MenuItem, FormControl, InputLabel } from '@mui/material'; |
| | | |
| | | const WarehouseSelect = (props) => { |
| | | const { dictTypeCode, label, value, onChange, ...params } = props; |
| | | const { dictTypeCode, label, name, validate, onChange, ...params } = props; |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const [list, setList] = useState([]); |
| | |
| | | }, [dictTypeCode]); |
| | | |
| | | const http = async () => { |
| | | const res = await request.post('/warehouseAreas/page', {current: 1, pageSize: 100}); |
| | | const res = await request.post('/warehouseAreas/page', { current: 1, pageSize: 100 }); |
| | | if (res?.data?.code === 200) { |
| | | setList(res.data.data.records.map((item) => { |
| | | return { |
| | |
| | | } |
| | | }; |
| | | |
| | | const handleChange = (event) => { |
| | | const selectedValue = event.target.value; |
| | | console.log(event); |
| | | if (onChange) { |
| | | onChange(event); |
| | | } |
| | | }; |
| | | |
| | | const validValue = list.some(item => item.id === value) ? value : ''; |
| | | |
| | | return ( |
| | | <FormControl fullWidth> |
| | | <InputLabel id="demo-select-small-label">{label}</InputLabel> |
| | | <Select |
| | | labelId="demo-select-small-label" |
| | | value={validValue} |
| | | variant="filled" |
| | | onChange={handleChange} |
| | | size='small' |
| | | > |
| | | {list.map((item) => ( |
| | | <MenuItem |
| | | key={item.id} |
| | | value={item.id}> |
| | | {item.name} |
| | | </MenuItem> |
| | | ))} |
| | | </Select> |
| | | </FormControl> |
| | | <AutocompleteInput |
| | | source={name} |
| | | label={label} |
| | | choices={list} |
| | | validate={validate} |
| | | onChange={(val) => { |
| | | if (onChange) { |
| | | onChange({ target: { value: val } }); |
| | | } |
| | | }} |
| | | options={{ |
| | | ListboxProps: { |
| | | style: { maxHeight: '200px' } |
| | | }, |
| | | ...(params.options || {}) |
| | | }} |
| | | fullWidth |
| | | {...params} |
| | | /> |
| | | ); |
| | | }; |
| | | |
| | | export default WarehouseSelect; |
| | | export default WarehouseSelect; |