#
vincentlu
2025-12-16 920bb5635c88c2f2f9a21134c81ebbc344539987
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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,
    onDelete,
    canDelete = false,
}) => {
    const translate = useTranslate();
    const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
    const checkedIcon = <CheckBoxIcon fontSize="small" />;
 
    const normalizeAgvId = (agv) => {
        if (agv == null) {
            return '';
        }
        if (typeof agv === 'object') {
            return String(agv.uuid ?? '');
        }
        return String(agv);
    };
 
    const getOptionId = (option) => {
        return normalizeAgvId(option)
    };
 
    const getOptionLabel = (option) => {
        return option?.uuid ?? '';
    };
 
    const handleSaveClick = () => {
        if (disableSave) {
            return;
        }
        const confirmMsg = translate('page.map.area.saveConfirm', { _: '确认保存当前修改?' });
        if (window.confirm(confirmMsg)) {
            onSave?.();
        }
    };
 
    const handleDeleteClick = () => {
        if (!canDelete) {
            return;
        }
        const confirmMsg = translate('page.map.area.deleteConfirm', { _: '删除后将无法恢复,确认删除?' });
        if (window.confirm(confirmMsg)) {
            onDelete?.();
        }
    };
 
    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) => {
                        return getOptionId(option) === getOptionId(value);
                    }}
                    onChange={(event, newValue) => {
                        setAgvList(newValue);
                    }}
                    renderTags={(value, getTagProps) =>
                        value.map((option, index) => (
                            <Chip
                                {...getTagProps({ index })}
                                key={getOptionId(option) || index}
                                label={normalizeAgvId(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="space-between" alignItems="center">
                <Button variant="contained" onClick={handleSaveClick} disabled={disableSave}>
                    {translate('common.action.save', { _: '保存' })}
                </Button>
                <Button variant="text" color="error" onClick={handleDeleteClick} disabled={!canDelete}>
                    {translate('common.action.delete', { _: '删除' })}
                </Button>
            </Box>
        </Stack>
    );
};
 
export default AreaBasicTab;