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 = ({
|
areaName,
|
setAreaName,
|
agvOptions,
|
selectedAgvs,
|
setSelectedAgvs,
|
barcodeList,
|
onSave,
|
}) => {
|
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={areaName}
|
onChange={(e) => setAreaName(e.target.value)}
|
/>
|
<Button variant="contained" onClick={onSave}>
|
{translate('common.action.save', { _: '保存' })}
|
</Button>
|
</Stack>
|
|
<Box>
|
<Typography variant="subtitle2" gutterBottom>
|
{translate('page.map.area.agv', { _: '添加AGV小车' })}
|
</Typography>
|
<Autocomplete
|
multiple
|
disableCloseOnSelect
|
options={agvOptions || []}
|
value={selectedAgvs || []}
|
getOptionLabel={getOptionLabel}
|
isOptionEqualToValue={(option, value) => getOptionId(option) === getOptionId(value)}
|
onChange={(event, newValue) => {
|
setSelectedAgvs(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={barcodeList}
|
InputProps={{ readOnly: true }}
|
/>
|
</Box>
|
</Stack>
|
);
|
};
|
|
export default AreaBasicTab;
|