import React, { useState, useRef, useEffect, useMemo } from "react";
|
import {
|
CreateBase,
|
useTranslate,
|
TextInput,
|
NumberInput,
|
BooleanInput,
|
DateInput,
|
SaveButton,
|
SelectInput,
|
ReferenceInput,
|
ReferenceArrayInput,
|
AutocompleteInput,
|
Toolbar,
|
required,
|
useDataProvider,
|
useNotify,
|
Form,
|
useCreateController,
|
useListContext,
|
useRefresh,
|
SelectArrayInput
|
} from 'react-admin';
|
import {
|
Dialog,
|
DialogActions,
|
DialogContent,
|
DialogTitle,
|
Grid,
|
TextField,
|
Box,
|
Button,
|
Paper,
|
TableContainer,
|
Table,
|
TableHead,
|
TableBody,
|
TableRow,
|
TableCell,
|
Tooltip,
|
IconButton,
|
styled
|
|
|
} from '@mui/material';
|
import DialogCloseButton from "../../components/DialogCloseButton";
|
import DictionarySelect from "../../components/DictionarySelect";
|
import { useForm, Controller, useWatch, FormProvider, useFormContext } from "react-hook-form";
|
import SaveIcon from '@mui/icons-material/Save';
|
import request from '@/utils/request';
|
import { Add, Edit, Delete } from '@mui/icons-material';
|
import _ from 'lodash';
|
import { DataGrid } from '@mui/x-data-grid';
|
|
|
|
|
const InitModal = ({ open, setOpen }) => {
|
const refresh = useRefresh();
|
const translate = useTranslate();
|
|
|
const notify = useNotify();
|
const [disabled, setDisabled] = useState(false)
|
|
|
const handleClose = (event, reason) => {
|
if (reason !== "backdropClick") {
|
setOpen(false);
|
}
|
};
|
|
const handleReset = (e) => {
|
e.preventDefault();
|
};
|
|
const handleChange = (value, name) => {
|
setFormData((prevData) => ({
|
...prevData,
|
[name]: value
|
}));
|
};
|
|
const handleSubmit = async (value) => {
|
setDisabled(true)
|
const res = await request.post(`/deviceSite/init`, value);
|
if (res?.data?.code === 200) {
|
setOpen(false);
|
refresh();
|
} else {
|
notify(res.data.msg);
|
}
|
setDisabled(false)
|
}
|
|
|
return (
|
<Dialog open={open} maxWidth="lg" fullWidth>
|
<Form onSubmit={handleSubmit}>
|
<DialogCloseButton onClose={handleClose} />
|
<DialogTitle>{translate('toolbar.siteInit')}</DialogTitle>
|
<DialogContent sx={{ mt: 2 }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
<Grid container spacing={2}>
|
<Grid item xs={4}>
|
<DictionarySelect
|
label={translate("table.field.deviceSite.type")}
|
name="typeIds"
|
dictTypeCode="sys_task_type"
|
multiple
|
/>
|
|
</Grid>
|
|
<Grid item xs={4}>
|
<DictionarySelect
|
label={translate("table.field.deviceSite.device")}
|
name="deviceType"
|
dictTypeCode="sys_device_type"
|
/>
|
</Grid>
|
<Grid item xs={4}>
|
<TextInput
|
label={translate("table.field.deviceSite.channel")}
|
name="channel"
|
size="small"
|
type="number"
|
/>
|
</Grid>
|
<Grid item xs={4}>
|
<ReferenceInput
|
source="deviceSites"
|
reference="basStation"
|
>
|
<SelectInput
|
label="table.field.deviceSite.deviceSite"
|
optionText="stationName"
|
/>
|
</ReferenceInput>
|
</Grid>
|
<Grid item xs={4}>
|
<ReferenceInput
|
source="site"
|
reference="basStation"
|
>
|
<SelectInput
|
label="table.field.deviceSite.site"
|
optionText="stationName"
|
/>
|
</ReferenceInput>
|
|
</Grid>
|
<Grid item xs={4}>
|
<TextInput
|
label={translate("table.field.deviceSite.target")}
|
name="target"
|
placeholder={translate('common.action.inputPlaceholder')}
|
size="small"
|
// type="number"
|
/>
|
</Grid>
|
<Grid item xs={6} display="flex" gap={1}>
|
<ReferenceInput source="areaIdStart" label="table.field.deviceBind.typeId" reference="warehouseAreas" filter={{}}>
|
<AutocompleteInput optionValue="id" optionText="name" label={translate('table.field.deviceSite.areaIdStart')} />
|
</ReferenceInput>
|
</Grid>
|
<Grid item xs={6} display="flex" gap={1}>
|
<ReferenceInput source="areaIdEnd" label="table.field.deviceBind.typeId" reference="warehouseAreas" filter={{}}>
|
<AutocompleteInput optionValue="id" optionText="name" label={translate('table.field.deviceSite.areaIdEnd')} />
|
</ReferenceInput>
|
</Grid>
|
<Grid item xs={4}>
|
<SelectInput
|
label="table.field.deviceSite.flagInit"
|
source="flagInit"
|
choices={[
|
{ id: 0, name: '否' },
|
{ id: 1, name: '是' },
|
]}
|
/>
|
</Grid>
|
|
|
</Grid>
|
|
</Box>
|
</DialogContent>
|
<DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
|
<Box sx={{ width: '100%', display: 'flex', justifyContent: 'space-between' }}>
|
<Button disabled={disabled} type="submit" variant="contained" startIcon={<SaveIcon />} >
|
{translate('toolbar.confirm')}
|
</Button>
|
</Box>
|
|
</DialogActions>
|
</Form>
|
</Dialog>
|
);
|
}
|
|
export default InitModal;
|