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, 
 | 
} 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 [formData, setFormData] = useState({ 
 | 
        "areaId": undefined, 
 | 
        "endBay": undefined, 
 | 
        "endLev": undefined, 
 | 
        "endRow": undefined, 
 | 
        "locType": "", 
 | 
        "startBay": undefined, 
 | 
        "startLev": undefined, 
 | 
        "startRow": undefined, 
 | 
        "type": "" 
 | 
    }); 
 | 
  
 | 
    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 () => { 
 | 
        const res = await request.post(`/loc/init`, formData); 
 | 
        if (res?.data?.code === 200) { 
 | 
            setOpen(false); 
 | 
            refresh(); 
 | 
        } else { 
 | 
            notify(res.data.msg); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    return ( 
 | 
        <Dialog open={open} maxWidth="md" fullWidth> 
 | 
            <Form onSubmit={handleSubmit}> 
 | 
                <DialogCloseButton onClose={handleClose} /> 
 | 
                <DialogTitle>{translate('toolbar.locInit')}</DialogTitle> 
 | 
                <DialogContent sx={{ mt: 2 }}> 
 | 
                    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> 
 | 
                        <Grid container spacing={2}> 
 | 
                            <Grid item xs={4}> 
 | 
                                <ReferenceInput 
 | 
                                    source="areaId" 
 | 
                                    reference="warehouseAreas" 
 | 
                                > 
 | 
                                    <AutocompleteInput 
 | 
                                        label="table.field.loc.areaId" 
 | 
                                        optionText="name" 
 | 
                                        onChange={(value) => handleChange(value, 'areaId')} 
 | 
                                        value={formData.areaId} 
 | 
                                        validate={[required()]} 
 | 
                                        filterToQuery={(val) => ({ name: val })} 
 | 
                                    /> 
 | 
                                </ReferenceInput> 
 | 
  
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <DictionarySelect 
 | 
                                    label={translate("table.field.loc.locType")} 
 | 
                                    name="locType" 
 | 
                                    value={formData.locType} 
 | 
                                    onChange={(e) => handleChange(e.target.value, 'locType')} 
 | 
                                    size="small" 
 | 
                                    dictTypeCode="sys_width_type" 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <DictionarySelect 
 | 
                                    label={translate("table.field.loc.type")} 
 | 
                                    name="type" 
 | 
                                    value={formData.type} 
 | 
                                    onChange={(e) => handleChange(e.target.value, 'type')} 
 | 
                                    size="small" 
 | 
                                    validate={[required()]} 
 | 
                                    dictTypeCode="sys_loc_type" 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.startBay")} 
 | 
                                    name="startBay" 
 | 
                                    value={formData.startBay} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'startBay')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.startLev")} 
 | 
                                    name="startLev" 
 | 
                                    value={formData.startLev} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'startLev')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.startRow")} 
 | 
                                    name="startRow" 
 | 
                                    value={formData.startRow} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'startRow')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.endBay")} 
 | 
                                    name="endBay" 
 | 
                                    value={formData.endBay} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'endBay')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.endLev")} 
 | 
                                    name="endLev" 
 | 
                                    value={formData.endLev} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'endLev')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </Grid> 
 | 
  
 | 
                            <Grid item xs={4}> 
 | 
                                <TextInput 
 | 
                                    label={translate("table.field.loc.endRow")} 
 | 
                                    name="endRow" 
 | 
                                    value={formData.endRow} 
 | 
                                    onChange={(e) => handleChange(+e.target.value, 'endRow')} 
 | 
                                    size="small" 
 | 
                                    type="number" 
 | 
                                    validate={[required()]} 
 | 
                                /> 
 | 
                            </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 type="submit" variant="contained" startIcon={<SaveIcon />}> 
 | 
                            确认 
 | 
                        </Button> 
 | 
                    </Box> 
 | 
                </DialogActions> 
 | 
            </Form> 
 | 
        </Dialog> 
 | 
    ); 
 | 
} 
 | 
  
 | 
export default InitModal; 
 |