1
15 小时以前 12d9f4e03c0331efc9a656356e78b9f314639707
rsf-admin/src/page/components/WarehouseSelect.jsx
@@ -1,12 +1,11 @@
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([]);
@@ -16,7 +15,7 @@
    }, [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 {
@@ -29,36 +28,27 @@
        }
    };
    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;