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'; 
 | 
import StatusSelectInput from "../../components/StatusSelectInput"; 
 | 
  
 | 
  
 | 
const BatchModal = ({ open, setOpen, fieldType }) => { 
 | 
    const refresh = useRefresh(); 
 | 
    const translate = useTranslate(); 
 | 
  
 | 
  
 | 
    const notify = useNotify(); 
 | 
  
 | 
    const [formData, setFormData] = useState({ 
 | 
        "warehouseId": null, 
 | 
        "areaId": null, 
 | 
        "type": null, 
 | 
        'status': null 
 | 
    }); 
 | 
  
 | 
    const { selectedIds, onUnselectItems } = useListContext(); 
 | 
  
 | 
    const handleClose = (event, reason) => { 
 | 
        if (reason !== "backdropClick") { 
 | 
            setOpen(false); 
 | 
            reset() 
 | 
            refresh(); 
 | 
            onUnselectItems() 
 | 
        } 
 | 
    }; 
 | 
  
 | 
    const reset = () => { 
 | 
        setFormData({ 
 | 
            "warehouseId": null, 
 | 
            "areaId": null, 
 | 
            "type": null, 
 | 
            "typeIds": null, 
 | 
            'status': null 
 | 
        }) 
 | 
    } 
 | 
  
 | 
    const handleReset = (e) => { 
 | 
        e.preventDefault(); 
 | 
    }; 
 | 
  
 | 
    const handleChange = (value, name) => { 
 | 
        setFormData((prevData) => ({ 
 | 
            ...prevData, 
 | 
            [name]: value 
 | 
        })); 
 | 
        refresh() 
 | 
    }; 
 | 
  
 | 
    const removeEmptyKeys = (obj) => { 
 | 
        return _.pickBy(obj, (value) => { 
 | 
            if (_.isObject(value)) { 
 | 
                const newObj = removeEmptyKeys(value); 
 | 
                return !_.isEmpty(newObj); 
 | 
            } 
 | 
            return !_.isNil(value) && (_.isNumber(value) ? value !== 0 : !_.isEmpty(value)); 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    const handleSubmit = async () => { 
 | 
        const parmas = { 
 | 
            id: selectedIds, 
 | 
            loc: removeEmptyKeys(formData) 
 | 
        } 
 | 
  
 | 
        const res = await request.post(`/loc/modify`, parmas); 
 | 
        if (res?.data?.code === 200) { 
 | 
            handleClose() 
 | 
  
 | 
        } else { 
 | 
            notify(res.data.msg); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    return ( 
 | 
        <Dialog open={open} maxWidth="xs" fullWidth> 
 | 
            <Form onSubmit={handleSubmit}> 
 | 
                <DialogCloseButton onClose={handleClose} /> 
 | 
                <DialogTitle>{translate('toolbar.batch')}</DialogTitle> 
 | 
                <DialogContent sx={{ mt: 2 }}> 
 | 
                    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> 
 | 
                        <Grid container spacing={2}> 
 | 
                            {fieldType === 'warehouseId' && 
 | 
                                <Grid item xs={6}> 
 | 
                                    <ReferenceInput 
 | 
                                        source="warehouseId" 
 | 
                                        reference="warehouse" 
 | 
                                    > 
 | 
                                        <AutocompleteInput 
 | 
                                            label="table.field.loc.warehouseId" 
 | 
                                            optionText="name" 
 | 
                                            value={formData.warehouseId} 
 | 
                                            filterToQuery={(val) => ({ name: val })} 
 | 
                                        /> 
 | 
                                    </ReferenceInput> 
 | 
                                </Grid> 
 | 
                            } 
 | 
                            {fieldType === 'areaId' && 
 | 
                                <Grid item xs={6}> 
 | 
                                    <ReferenceInput 
 | 
                                        source="areaId" 
 | 
                                        reference="warehouseAreas" 
 | 
                                    > 
 | 
                                        <AutocompleteInput 
 | 
                                            label="table.field.loc.areaId" 
 | 
                                            optionText="name" 
 | 
                                            onChange={(value) => handleChange(value, 'areaId')} 
 | 
                                            value={formData.areaId} 
 | 
                                            filterToQuery={(val) => ({ name: val })} 
 | 
                                        /> 
 | 
                                    </ReferenceInput> 
 | 
  
 | 
                                </Grid> 
 | 
                            } 
 | 
                            {fieldType === 'typeIds' && 
 | 
                                <Grid item xs={6}> 
 | 
                                    {/* <DictionarySelect 
 | 
                                    label={translate("table.field.loc.type")} 
 | 
                                    name="type" 
 | 
                                    value={formData.type} 
 | 
                                    onChange={(e) => handleChange(e.target.value, 'type')} 
 | 
                                    size="small" 
 | 
                                    dictTypeCode="sys_loc_type" 
 | 
                                /> */} 
 | 
                                    <ReferenceArrayInput source="typeIds" reference="locType" > 
 | 
                                        <SelectArrayInput label="table.field.loc.type" onChange={(e) => handleChange(e.target.value, 'typeIds')} /> 
 | 
                                    </ReferenceArrayInput> 
 | 
                                </Grid> 
 | 
                            } 
 | 
  
 | 
                            {fieldType === 'status' && 
 | 
                                <Grid item xs={6}> 
 | 
                                    <StatusSelectInput 
 | 
                                        onChange={(e) => handleChange(e.target.value, 'status')} 
 | 
                                        defaultValue={''} 
 | 
                                        require={false} 
 | 
                                    /> 
 | 
                                </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 />}> 
 | 
                            {translate('toolbar.confirm')} 
 | 
                        </Button> 
 | 
                    </Box> 
 | 
                </DialogActions> 
 | 
            </Form> 
 | 
        </Dialog> 
 | 
    ); 
 | 
} 
 | 
  
 | 
export default BatchModal; 
 |