| import React, { useState, useRef, useEffect, useMemo } from "react"; | 
| import { | 
|     useTranslate, | 
|     TextInput, | 
|     NumberInput, | 
|     BooleanInput, | 
|     DateInput, | 
|     SelectInput, | 
|     ReferenceInput, | 
|     ReferenceArrayInput, | 
|     AutocompleteInput, | 
|     Toolbar, | 
|     required, | 
|     useDataProvider, | 
|     useNotify, | 
|     Form, | 
| } from 'react-admin'; | 
| import { | 
|     Dialog, | 
|     DialogActions, | 
|     DialogContent, | 
|     DialogTitle, | 
|     Stack, | 
|     Grid, | 
|     Box, | 
|     Button, | 
| } from '@mui/material'; | 
| import DialogCloseButton from "../components/DialogCloseButton"; | 
| import CheckIcon from '@mui/icons-material/Check'; | 
| import request from '@/utils/request' | 
|   | 
| const LocInit = (props) => { | 
|     const { open, setOpen } = props; | 
|   | 
|     const translate = useTranslate(); | 
|     const notify = useNotify(); | 
|   | 
|     const handleClose = (event, reason) => { | 
|         if (reason !== "backdropClick") { | 
|             setOpen(false); | 
|         } | 
|     }; | 
|   | 
|     const onSubmit = (data) => { | 
|         request.post('/loc/init', { ...data }).then(res => { | 
|             const { code, msg, data } = res.data; | 
|             if (code === 200) { | 
|                 setOpen(false); | 
|                 notify('common.response.success', { type: 'success' }); | 
|             } else { | 
|                 notify(msg, { type: 'error', messageArgs: { _: msg } }); | 
|             } | 
|         }).catch(error => { | 
|             notify(error, { type: 'error', messageArgs: { _: error } }); | 
|         }) | 
|     }; | 
|   | 
|     return ( | 
|         <> | 
|             <Dialog | 
|                 open={open} | 
|                 onClose={handleClose} | 
|                 aria-labelledby="form-dialog-title" | 
|                 fullWidth | 
|                 disableRestoreFocus | 
|                 maxWidth="md"   // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 
|             > | 
|                 <Form onSubmit={onSubmit}> | 
|                     <DialogTitle id="form-dialog-title" sx={{ | 
|                         position: 'sticky', | 
|                         top: 0, | 
|                         backgroundColor: 'background.paper', | 
|                         zIndex: 1000 | 
|                     }} | 
|                     > | 
|                         {translate('page.loc.init')} | 
|                         <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}> | 
|                             <DialogCloseButton onClose={handleClose} /> | 
|                         </Box> | 
|                     </DialogTitle> | 
|                     <DialogContent> | 
|                         <Grid container rowSpacing={2} columnSpacing={2}> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <ReferenceInput | 
|                                     source="zoneId" | 
|                                     reference="zone" | 
|                                 > | 
|                                     <AutocompleteInput | 
|                                         label="table.field.loc.zoneId" | 
|                                         optionText="name" | 
|                                         filterToQuery={(val) => ({ name: val })} | 
|                                         validate={required()} | 
|                                     /> | 
|                                 </ReferenceInput> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <ReferenceInput | 
|                                     source="locSts" | 
|                                     reference="locSts" | 
|                                 > | 
|                                     <AutocompleteInput | 
|                                         label="table.field.loc.locSts" | 
|                                         optionText="name" | 
|                                         filterToQuery={(val) => ({ name: val })} | 
|                                         validate={required()} | 
|                                     /> | 
|                                 </ReferenceInput> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.start.row" | 
|                                     source="startRow" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.end.row" | 
|                                     source="endRow" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.start.bay" | 
|                                     source="startBay" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.end.bay" | 
|                                     source="endBay" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.start.lev" | 
|                                     source="startLev" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.end.lev" | 
|                                     source="endLev" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.levOffset" | 
|                                     source="levOffset" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <NumberInput | 
|                                     label="page.loc.bottomOffset" | 
|                                     source="bottom" | 
|                                     validate={required()} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <SelectInput | 
|                                     label="table.field.loc.compDirect" | 
|                                     source="compDirect" | 
|                                     choices={[ | 
|                                         { id: 1, name: '大于' }, | 
|                                         { id: 0, name: '小于' }, | 
|                                     ]} | 
|                                 /> | 
|                             </Grid> | 
|                             <Grid item xs={6} display="flex" gap={1}> | 
|                                 <ReferenceInput | 
|                                     source="locType" | 
|                                     reference="locType" | 
|                                 > | 
|                                     <AutocompleteInput | 
|                                         label="table.field.loc.locType" | 
|                                         optionText="name" | 
|                                         filterToQuery={(val) => ({ name: val })} | 
|                                     /> | 
|                                 </ReferenceInput> | 
|                             </Grid> | 
|                         </Grid> | 
|                     </DialogContent> | 
|                     <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> | 
|                         <Toolbar sx={{ width: '100%', justifyContent: 'space-between' }}  > | 
|                             <Button variant="contained" type="submit" startIcon={<CheckIcon />}>{translate('ra.action.confirm')}</Button> | 
|                         </Toolbar> | 
|                     </DialogActions> | 
|                 </Form> | 
|             </Dialog> | 
|         </> | 
|     ) | 
| } | 
|   | 
| export default LocInit; |