#
vincentlu
2025-12-15 4d97647ec29563c1cb0b0c01bafe9f8a70839977
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React from 'react';
import {
    Stack,
    TextField,
    Button,
    Typography,
    Box,
    Autocomplete,
    Checkbox,
} from '@mui/material';
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';
import { useTranslate } from 'react-admin';
 
const AreaBasicTab = ({
    name,
    setName,
    agvOptions,
    agvList,
    setAgvList,
    codeListText,
    onSave,
    disableSave,
}) => {
    const translate = useTranslate();
    const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
    const checkedIcon = <CheckBoxIcon fontSize="small" />;
 
    const getOptionLabel = (option) => {
        if (typeof option === 'string') {
            return option;
        }
        return option?.label ?? option?.name ?? option?.agvNo ?? option?.value ?? option?.id ?? '';
    };
 
    const getOptionId = (option) => {
        if (typeof option === 'string') {
            return option;
        }
        return option?.value ?? option?.id ?? option?.agvNo ?? option?.code ?? option?.name ?? '';
    };
 
    return (
        <Stack spacing={2}>
            <Stack direction="row" spacing={1} alignItems="center">
                <TextField
                    label={translate('page.map.area.name', { _: '名称' })}
                    fullWidth
                    value={name}
                    onChange={(e) => setName(e.target.value)}
                />
            </Stack>
 
            <Box>
                <Typography variant="subtitle2" gutterBottom>
                    {translate('page.map.area.agv', { _: '添加AGV小车' })}
                </Typography>
                <Autocomplete
                    multiple
                    disableCloseOnSelect
                    options={agvOptions || []}
                    value={agvList || []}
                    getOptionLabel={getOptionLabel}
                    isOptionEqualToValue={(option, value) => getOptionId(option) === getOptionId(value)}
                    onChange={(event, newValue) => {
                        setAgvList(newValue);
                    }}
                    renderOption={(props, option, { selected }) => (
                        <li {...props}>
                            <Checkbox
                                icon={icon}
                                checkedIcon={checkedIcon}
                                style={{ marginRight: 8 }}
                                checked={selected}
                            />
                            {getOptionLabel(option)}
                        </li>
                    )}
                    renderInput={(params) => (
                        <TextField
                            {...params}
                            placeholder={translate('page.map.area.agv.placeholder', { _: '选择AGV' })}
                        />
                    )}
                    ListboxProps={{ sx: { maxHeight: 280 } }}
                />
            </Box>
 
            <Box>
                <Typography variant="subtitle2" gutterBottom>
                    {translate('page.map.area.barcodes', { _: '区域内条码集合' })}
                </Typography>
                <TextField
                    placeholder={translate('page.map.area.barcodes.placeholder', { _: '每行一个条码' })}
                    fullWidth
                    multiline
                    minRows={6}
                    maxRows={10}
                    value={codeListText}
                    InputProps={{ readOnly: true }}
                />
            </Box>
 
            <Box display="flex" justifyContent="flex-start">
                <Button variant="contained" onClick={onSave} disabled={disableSave}>
                    {translate('common.action.save', { _: '保存' })}
                </Button>
            </Box>
        </Stack>
    );
};
 
export default AreaBasicTab;