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";
|
import TreeSelectInput from "@/page/components/TreeSelectInput";
|
const MatnrModal = ({ open, setOpen }) => {
|
const refresh = useRefresh();
|
const translate = useTranslate();
|
|
|
const notify = useNotify();
|
|
const [formData, setFormData] = useState({
|
areaId: null,
|
groupId: null,
|
matnrId: null,
|
});
|
|
const { selectedIds, onUnselectItems } = useListContext();
|
|
const handleClose = (event, reason) => {
|
if (reason !== "backdropClick") {
|
setOpen(false);
|
reset()
|
refresh();
|
onUnselectItems()
|
}
|
};
|
|
const reset = () => {
|
setFormData({
|
areaId: null,
|
groupId: null,
|
matnrId: 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 = {
|
locId: selectedIds,
|
areaId: formData.areaId,
|
matnrId: formData.matnrId,
|
}
|
|
const res = await request.post(`/locAreaMatRela/matnr/bind`, parmas);
|
if (res?.data?.code === 200) {
|
handleClose()
|
|
} else {
|
notify(res.data.msg);
|
}
|
|
|
}
|
|
const [groupId, setGroupId] = useState();
|
|
const warehouseChange = (e) => {
|
setGroupId(e.target.value)
|
}
|
|
return (
|
<Dialog open={open} maxWidth="md" fullWidth>
|
<Form onSubmit={handleSubmit}>
|
<DialogCloseButton onClose={handleClose} />
|
<DialogTitle>{translate('toolbar.bindmatnr')}</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}>
|
<TreeSelectInput
|
label="table.field.locAreaMatRela.groupId"
|
resource={'matnrGroup'}
|
source="groupId"
|
value={formData.groupId}
|
onChange={(e) => handleChange(e.target.value, 'groupId')}
|
/>
|
</Grid>
|
|
|
<Grid item xs={4}>
|
<ReferenceArrayInput source="matnrId" reference="matnr" filter={{ groupId: formData.groupId }}>
|
<SelectArrayInput
|
label="table.field.locAreaMatRela.matnrId"
|
validate={required()}
|
value={formData.matnrId}
|
onChange={(e) => handleChange(e.target.value, 'matnrId')}
|
/>
|
</ReferenceArrayInput>
|
|
</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 MatnrModal;
|