import { Dialog, DialogActions, DialogContent, DialogTitle, Box, LinearProgress } from "@mui/material";
|
import React, { useState, useRef, useEffect, useMemo } from "react";
|
import {
|
List,
|
DatagridConfigurable,
|
SearchInput,
|
TopToolbar,
|
Button,
|
SelectColumnsButton,
|
EditButton,
|
FilterButton,
|
CreateButton,
|
ExportButton,
|
BulkDeleteButton,
|
WrapperField,
|
Toolbar,
|
useRecordContext,
|
useTranslate,
|
useNotify,
|
useListContext,
|
FunctionField,
|
TextField,
|
NumberField,
|
DateField,
|
BooleanField,
|
ReferenceField,
|
TextInput,
|
DateTimeInput,
|
DateInput,
|
SelectInput,
|
NumberInput,
|
ReferenceInput,
|
ReferenceArrayInput,
|
AutocompleteInput,
|
DeleteButton,
|
Form,
|
SaveButton,
|
useRefresh,
|
useGetList,
|
} from 'react-admin';
|
import DialogCloseButton from "../../components/DialogCloseButton";
|
import { styled } from '@mui/material/styles';
|
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting';
|
import { Grid, Stack, width } from "@mui/system";
|
import request from '@/utils/request';
|
import SaveIcon from '@mui/icons-material/Save';
|
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
|
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
|
'& .css-1vooibu-MuiSvgIcon-root': {
|
height: '.9em'
|
},
|
'& .RaDatagrid-row': {
|
cursor: 'auto'
|
},
|
'& .status': {
|
width: 90
|
},
|
}));
|
|
const WarehouseHistories = (props) => {
|
const { open, setOpen, record } = props;
|
const translate = useTranslate();
|
const [params, setParams] = useState({});
|
const [item, setItem] = useState({});
|
const [poItemDialog, setPoItemDialog] = useState(false);
|
const [drawerVal, setDrawerVal] = useState(false);
|
const refresh = useRefresh();
|
|
const handleClose = (event, reason) => {
|
if (reason !== "backdropClick") {
|
setOpen(false);
|
}
|
};
|
// const CustomFilter = () => {
|
// const { filterValues, setFilters, refetch } = useListContext('deliveryItem');
|
// const [formValues, setFormValues] = useState(filterValues);
|
// const handleChange = (event) => {
|
// if (event.target == undefined || event.target == null) { return }
|
// setFormValues(formValues => ({
|
// ...formValues,
|
// [event.target.name]: event.target.value
|
// }));
|
// };
|
|
// const handleSubmit = (event) => {
|
// setParams(formValues)
|
// };
|
|
// return (
|
// <Box sx={{ width: '100%', margin: 1, marginBottom: 8, "& .MuiDialogActions-root": { padding: 0 } }}>
|
// <Form>
|
// <Grid container rowSpacing={2} columnSpacing={2} sx={{ padding: 2 }}>
|
// <Stack>
|
// <TextInput
|
// source="condition"
|
// label="common.action.search"
|
// resettable
|
// defaultValue={params?.condition}
|
// onChange={handleChange} />
|
// </Stack>
|
// </Grid>
|
// <DialogActions>
|
// <Toolbar sx={{ width: '100%', justifyContent: 'end' }} >
|
// <SaveButton onClick={handleSubmit} label={"toolbar.query"} />
|
// </Toolbar>
|
// </DialogActions>
|
// </Form>
|
// </Box>
|
// );
|
// };
|
return (
|
<Box>
|
<Dialog
|
open={open}
|
onClose={handleClose}
|
aria-labelledby="form-dialog-title"
|
aria-hidden
|
fullWidth
|
disableRestoreFocus
|
maxWidth="xl"
|
>
|
<DialogTitle id="form-dialog-title" sx={{
|
position: 'sticky',
|
top: 0,
|
backgroundColor: 'background.paper',
|
zIndex: 1000
|
}}>
|
<Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}>
|
<DialogCloseButton onClose={handleClose} />
|
</Box>
|
</DialogTitle>
|
<Grid container rowSpacing={2} columnSpacing={2}>
|
<DialogContent>
|
<Grid item sx={24}>
|
<Box display="flex">
|
<List
|
resource="warehouse/stock/histories"
|
sx={{
|
flexGrow: 1,
|
transition: (theme) =>
|
theme.transitions.create(['all'], {
|
duration: theme.transitions.duration.enteringScreen,
|
}),
|
marginRight: 0,
|
}}
|
title={"menu.stockItem"}
|
empty={false}
|
filter={{ stock: record, aggType: record?.aggType }}
|
sort={{ field: "create_time", order: "desc" }}
|
actions={(
|
<TopToolbar>
|
<SelectColumnsButton preferenceKey='stockHistories' />
|
{/* <MyExportButton /> */}
|
</TopToolbar>
|
)}
|
perPage={DEFAULT_ITEM_PAGE_SIZE}
|
>
|
<DynamicFields />
|
</List>
|
</Box>
|
</Grid>
|
</DialogContent>
|
</Grid>
|
</Dialog >
|
</Box>
|
)
|
}
|
|
export default WarehouseHistories;
|
|
|
const ConfirmSelectButton = ({ setOpen, setPoItemDialog, setItem }) => {
|
const { selectedIds, onUnselectItems } = useListContext();
|
const confirmSelect = async (event) => {
|
setItem(selectedIds[0])
|
onUnselectItems();
|
setPoItemDialog(true)
|
setOpen(false);
|
}
|
|
return (
|
<Button label={"toolbar.confirm"} variant="contained" color="primary" size="medium" startIcon={<SaveIcon />} onClick={confirmSelect} />
|
)
|
}
|
|
|
const DynamicFields = (props) => {
|
const { setDrawerVal, setCreateDialog, setSelect, filters } = props
|
const translate = useTranslate();
|
const notify = useNotify();
|
const [columns, setColumns] = useState([]);
|
const { isLoading } = useListContext();
|
const refresh = useRefresh();
|
useEffect(() => {
|
getDynamicFields();
|
}, []);
|
|
const getDynamicFields = async () => {
|
const { data: { code, data, msg }, } = await request.get("/fields/enable/list");
|
if (code == 200) {
|
const arr = [
|
<NumberField source="id" />,
|
<NumberField source="orderId" label="table.field.stockItem.orderId" />,
|
<TextField source="orderCode" label="table.field.stockItem.orderCode" />,
|
<TextField source="sourceItemId" label="table.field.stockItem.sourceItemId" />,
|
<TextField source="matnrId" label="table.field.stockItem.matnrId" />,
|
<TextField source="matnrCode" label="table.field.stockItem.matnrCode" />,
|
<TextField source="maktx" label="table.field.stockItem.maktx" />,
|
<NumberField source="anfme" label="table.field.stockItem.anfme" />,
|
<TextField source="stockUnit" label="table.field.stockItem.stockUnit" />,
|
<NumberField source="workQty" label="table.field.stockItem.workQty" />,
|
<NumberField source="qty" label="table.field.stockItem.qty" />,
|
<TextField source="splrCode" label="table.field.stockItem.splrCode" />,
|
<TextField source="batch" label="table.field.stockItem.batch" />,
|
<TextField source="splrBatch" label="table.field.stockItem.splrBatch" />,
|
<TextField source="splrName" label="table.field.stockItem.splrName" />,
|
<TextField source="trackCode" label="table.field.stockItem.trackCode" />,
|
<TextField source="barcode" label="table.field.stockItem.barcode" />,
|
<TextField source="prodTime" label="table.field.stockItem.prodTime" />,
|
<TextField source="packName" label="table.field.stockItem.packName" />,
|
]
|
const fields = data.map(el => <TextField key={el.fields} source={`extendFields.[${el.fields}]`} label={el.fieldsAlise} />)
|
const lastArr = [
|
<TextField source="updateBy$" label="common.field.updateBy" />,
|
<DateField source="updateTime" label="common.field.updateTime" showTime />,
|
<TextField source="createBy$" label="common.field.createBy" />,
|
<DateField source="createTime" label="common.field.createTime" showTime />,
|
<TextField source="memo" label="common.field.memo" sortable={false} />,
|
]
|
setColumns([...arr, ...fields, ...lastArr]);
|
|
data.map(el => {
|
var i = 0;
|
filters.map((item) => {
|
if (item.key === el.fields) {
|
i = 1;
|
}
|
})
|
i === 0 && filters.push(<TextInput key={el.fields} source={el.fields} label={el.fieldsAlise} />)
|
})
|
// setFilters([...filters, ...inputFields])
|
|
} else {
|
notify(msg);
|
}
|
}
|
|
return (
|
<Box sx={{ position: 'relative', minHeight: "60vh", }}>
|
{isLoading && (
|
<LinearProgress
|
sx={{
|
height: "2px",
|
position: 'absolute',
|
top: 0,
|
left: 0,
|
right: 0,
|
}}
|
/>
|
)}
|
{columns.length > 0 &&
|
<StyledDatagrid
|
preferenceKey='stockHistories'
|
bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />}
|
rowClick={(id, resource, record) => false}
|
expand={false}
|
expandSingle={true}
|
omit={['id', 'createTime', 'orderId', 'sourceItemId', 'matnrId', 'createBy', 'barcode', 'splrCode', 'splrBatch', 'updateBy$', 'createBy$', 'memo']}
|
>
|
{columns.map((column) => column)}
|
</StyledDatagrid>}
|
</Box>
|
)
|
}
|