#
vincentlu
2025-12-15 7b371b53241357b07af688831b94db66340d6893
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import React from 'react';
import {
    Stack,
    TextField,
    Button,
    Typography,
    Box,
    Autocomplete,
    Checkbox,
    Chip,
    Paper,
} 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,
    codeList,
    onSave,
    disableSave,
}) => {
    const translate = useTranslate();
    const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
    const checkedIcon = <CheckBoxIcon fontSize="small" />;
 
    const getOptionLabel = (option) => {
        return option?.uuid ?? '';
    };
 
    const getOptionId = (option) => {
        return option?.id;
    };
 
    return (
        <Stack spacing={3}>
            <Stack direction="row" spacing={1} alignItems="center">
                <TextField
                    label={translate('page.map.area.name', { _: '名称' })}
                    size="small"
                    fullWidth
                    variant="outlined"
                    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);
                    }}
                    renderTags={(value, getTagProps) =>
                        value.map((option, index) => (
                            <Chip
                                {...getTagProps({ index })}
                                key={getOptionId(option)}
                                label={getOptionLabel(option)}
                                size="small"
                                sx={{ mr: 0.5, fontWeight: 'bold' }}
                            />
                        ))
                    }
                    ListboxProps={{
                        sx: {
                            maxHeight: 240,
                            '& .MuiAutocomplete-option': { py: 0.5, fontSize: 13 },
                        },
                    }}
                    renderOption={(props, option, { selected }) => {
                        const { key, ...optionProps } = props;
                        return (
                            <li
                                key={key}
                                {...optionProps}
                                style={{
                                    fontSize: 13,
                                    display: 'flex',
                                    alignItems: 'center',
                                    height: 30,
                                    ...(optionProps.style || {}),
                                }}
                            >
                                <Checkbox
                                    icon={icon}
                                    checkedIcon={checkedIcon}
                                    sx={{ mr: 1, '& .MuiSvgIcon-root': { fontSize: 18 } }}
                                    checked={selected}
                                />
                                <Typography variant="body2">{getOptionLabel(option)}</Typography>
                            </li>
                        );
                    }}
                    renderInput={(params) => (
                        <TextField
                            {...params}
                            size="small"
                            variant="outlined"
                            placeholder={translate('page.map.area.agv.placeholder', { _: '' })}
                        />
                    )}
                />
            </Box>
 
            <Box>
                <Typography variant="subtitle2" gutterBottom>
                    {translate('page.map.area.barcodes', { _: '区域内条码集合' }) + " (" + codeList.length + ")"}
                </Typography>
                <Paper
                    variant="outlined"
                    sx={{
                        minHeight: 220,
                        maxHeight: 320,
                        overflowY: 'auto',
                        p: 1,
                        display: 'flex',
                        flexWrap: 'wrap',
                        gap: 0.75,
                    }}
                >
                    {(codeList || []).length > 0 ? (
                        codeList.map((code) => (
                            <Chip
                                key={code}
                                label={code}
                                size="small"
                                sx={{ fontFamily: 'monospace', fontSize: 12 }}
                            />
                        ))
                    ) : (
                        <Typography variant="body2" color="text.secondary">
                            {translate('page.map.area.barcodes.empty', { _: '暂无条码' })}
                        </Typography>
                    )}
                </Paper>
            </Box>
 
            <Box display="flex" justifyContent="flex-start">
                <Button variant="contained" onClick={onSave} disabled={disableSave}>
                    {translate('common.action.save', { _: '保存' })}
                </Button>
            </Box>
        </Stack>
    );
};
 
export default AreaBasicTab;