import React, { useState, useEffect } from "react";
|
import {
|
Dialog,
|
DialogActions,
|
DialogContent,
|
DialogTitle,
|
Stack,
|
Grid,
|
Box,
|
Button,
|
Paper,
|
styled,
|
Tooltip,
|
IconButton,
|
TextField,
|
} from '@mui/material';
|
|
import { EDIT_MODE, DEFAULT_START_PAGE, DEFAULT_ITEM_PAGE_SIZE, DEFAULT_PAGE_SIZE, REFERENCE_INPUT_PAGESIZE } from '@/config/setting';
|
import DialogCloseButton from "../../components/DialogCloseButton";
|
import {
|
useTranslate, useNotify, useRefresh, List, FilterButton, NumberField,
|
DateField, ReferenceInput, AutocompleteInput, TextInput, DatagridConfigurable,
|
BooleanField, SearchInput,
|
} from 'react-admin';
|
import TreeSelectInput from "@/page/components/TreeSelectInput";
|
import { Add, Edit, Delete, Save } from '@mui/icons-material';
|
import SaveIcon from '@mui/icons-material/Save';
|
import { DataGrid } from '@mui/x-data-grid';
|
import request from '@/utils/request';
|
|
|
|
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
|
'& .css-1vooibu-MuiSvgIcon-root': {
|
height: '.9em'
|
},
|
'& .RaDatagrid-row': {
|
cursor: 'auto'
|
},
|
'& .column-name': {
|
},
|
'& .opt': {
|
width: 180
|
},
|
}));
|
|
|
|
const SelectLocsRevise = (props) => {
|
const { open, setOpen, data, setData } = props;
|
const translate = useTranslate();
|
const refresh = useRefresh();
|
const notify = useNotify();
|
|
const handleClose = (event, reason) => {
|
if (reason !== "backdropClick") {
|
setOpen(false);
|
}
|
};
|
|
const dicts = JSON.parse(localStorage.getItem('sys_dicts'))?.filter(dict => (dict.dictTypeCode == 'sys_stock_revise_type')) || [];
|
const [formData, setFormData] = useState({});
|
const [tableData, setTableData] = useState([]);
|
const [dyFields, setDyFields] = useState([]);
|
const [selectedRows, setSelectedRows] = useState([]);
|
const [page, setPage] = useState({ page: DEFAULT_START_PAGE, pageSize: DEFAULT_PAGE_SIZE });
|
const [rowCount, setRowCount] = useState(0);
|
const [isLoading, setIsLoading] = useState(false);
|
const handleChange = (e) => {
|
const { name, value } = e.target;
|
setFormData(() => ({
|
[name]: value
|
}));
|
};
|
|
const reset = () => {
|
setFormData({
|
name: '',
|
code: '',
|
groupId: 0
|
})
|
}
|
|
const handleSubmit = () => {
|
const hasarr = data.map(el => +el.matnrId)
|
const selectedData = selectedRows.filter(item => !hasarr.includes(item)).map(id => (tableData.find(row => row.id === id)));
|
const value = selectedData.map((el => {
|
const dynamicFields = dyFields.reduce((acc, item) => {
|
acc[item.fields] = el['extendFields']?.[item.fields] || '';
|
return acc;
|
}, {});
|
return {
|
matnrId: el.id,
|
maktx: el.name,
|
matnrCode: el.code,
|
stockUnit: el.stockUnit || '',
|
purUnit: el.purchaseUnit || '',
|
...dynamicFields
|
}
|
}))
|
setData([...data, ...value]);
|
setOpen(false);
|
reset();
|
};
|
|
const filters = [
|
<SearchInput source="condition" alwaysOn />,
|
]
|
|
const getData = async () => {
|
setIsLoading(true)
|
const res = await request.post(`/locItem/page`, {
|
...formData,
|
current: page?.page,
|
pageSize: page?.pageSize,
|
orderBy: "create_time desc"
|
});
|
if (res?.data?.code === 200) {
|
setTableData(res.data.data.records);
|
setRowCount(res.data?.data?.total);
|
|
} else {
|
notify(res.data.msg);
|
}
|
setIsLoading(false)
|
|
};
|
|
useEffect(() => {
|
getData();
|
}, [open, page]);
|
|
const handleSearch = () => {
|
getData()
|
};
|
|
return (
|
<Dialog
|
open={open}
|
onClose={handleClose}
|
aria-labelledby="form-dialog-title"
|
fullWidth
|
disableRestoreFocus
|
maxWidth="xl"
|
>
|
<DialogTitle id="form-dialog-title" sx={{
|
position: 'sticky',
|
top: 0,
|
backgroundColor: 'background.paper',
|
zIndex: 1000
|
}}>
|
{translate("common.action.newAddMats")}
|
<Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}>
|
<DialogCloseButton onClose={handleClose} />
|
</Box>
|
</DialogTitle>
|
<DialogContent sx={{ mt: 2 }}>
|
{/* <Box>
|
<List
|
sx={{
|
flexGrow: 1,
|
marginRight: 1,
|
transition: (theme) =>
|
theme.transitions.create(['all'], {
|
duration: theme.transitions.duration.enteringScreen,
|
}),
|
}}
|
resource="loc"
|
title={"menu.loc"}
|
empty={false}
|
filter={{ useStatus: 'F' }}
|
filters={filters}
|
sort={{ field: "'row'" }}
|
actions={false}
|
perPage={DEFAULT_PAGE_SIZE}
|
aside={false}
|
>
|
<StyledDatagrid
|
preferenceKey='loc'
|
align="left"
|
bulkActionButtons={false}
|
rowClick={() => false}
|
omit={['id', 'areaId', 'type', 'barcode']}
|
>
|
<NumberField source="id" />
|
<TextField source="code" label="table.field.locItem.locCode" />
|
</StyledDatagrid>
|
</List>
|
</Box> */}
|
<Box>
|
<Box component="form" onSubmit={handleSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
<Grid container spacing={2} md={6}>
|
<Grid item md={4}>
|
<TextField
|
label={translate('table.field.locItem.locCode')}
|
name="locCode"
|
value={formData.name}
|
onChange={handleChange}
|
size="small"
|
/>
|
</Grid>
|
<Grid item md={2} sx={{ margin: 'auto' }}>
|
<Button variant="contained" onClick={handleSearch}>搜索</Button>
|
</Grid>
|
</Grid>
|
</Box>
|
<Box sx={{ mt: 2, height: 600, width: '100%' }}>
|
<AsnWareModalTable
|
tableData={tableData}
|
setTableData={setTableData}
|
dyFields={dyFields}
|
page={page}
|
rowCount={rowCount}
|
setPage={setPage}
|
isLoading={isLoading}
|
setDyFields={setDyFields}
|
selectedRows={selectedRows}
|
setSelectedRows={setSelectedRows}
|
/>
|
</Box>
|
</Box>
|
</DialogContent>
|
<DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
|
<Box sx={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
|
<Button onClick={handleSubmit} variant="contained" startIcon={<SaveIcon />}>
|
{translate('toolbar.confirm')}
|
</Button>
|
</Box>
|
</DialogActions>
|
</Dialog>
|
);
|
};
|
|
export default SelectLocsRevise;
|
|
const AsnWareModalTable = ({ tableData, setTableData, page, isLoading, pageSize, setPage, rowCount, selectedRows, setSelectedRows, dyFields, setDyFields }) => {
|
const translate = useTranslate();
|
const notify = useNotify();
|
|
const [columns, setColumns] = useState([
|
// { field: 'id', headerName: 'ID', width: 100 },
|
{ field: 'locCode', headerName: translate('table.field.locItem.locCode'), width: 150 },
|
{ field: 'matnrCode', headerName: translate('table.field.locItem.matnrCode'), width: 200 },
|
{ field: 'maktx', headerName: translate('table.field.locItem.maktx'), width: 300 },
|
{ field: 'batch', headerName: translate('table.field.locItem.batch'), width: 100 },
|
{ field: 'anfme', headerName: translate('table.field.locItem.anfme'), width: 100 },
|
{ field: 'unit', headerName: translate('table.field.matnr.unit'), width: 100 },
|
])
|
|
const action = {
|
field: 'action',
|
headerName: '操作',
|
width: 140,
|
lockPosition: 'left',
|
renderCell: (params) => (
|
<Tooltip title="Delete">
|
<IconButton onClick={() => handleDelete(params.row)}>
|
<Delete />
|
</IconButton>
|
<IconButton onClick={() => handleDelete(params.row)}>
|
<Save />
|
</IconButton>
|
</Tooltip>
|
),
|
}
|
|
|
const handleSelectionChange = (ids) => {
|
setSelectedRows(ids)
|
};
|
|
useEffect(() => {
|
if (dyFields.length < 1) {
|
getDynamicFields();
|
}
|
}, []);
|
|
const getDynamicFields = async () => {
|
const {
|
data: { code, data, msg },
|
} = await request.get("/fields/enable/list");
|
if (code === 200) {
|
const cols = data.map(el => ({
|
field: el.fields,
|
headerName: el.fieldsAlise,
|
minWidth: 100,
|
flex: 1,
|
editable: el.unique,
|
valueGetter: (value, row) => {
|
return row.extendFields?.[el.fields] || '';
|
},
|
}))
|
setDyFields(data)
|
setColumns([...columns, ...cols, action])
|
} else {
|
notify(msg);
|
}
|
}
|
|
return (
|
<div style={{ width: '100%' }}>
|
<DataGrid
|
sx={{ height: 600 }}
|
size="small"
|
rows={tableData}
|
columns={columns}
|
checkboxSelection
|
onRowSelectionModelChange={handleSelectionChange}
|
selectionModel={selectedRows}
|
disableColumnMenu={true}
|
disableColumnSorting
|
disableMultipleColumnsSorting
|
rowCount={rowCount}
|
paginationMode="server"
|
paginationModel={page}
|
onPaginationModelChange={setPage}
|
loading={isLoading}
|
slotProps={{
|
loadingOverlay: {
|
variant: 'linear-progress',
|
noRowsVariant: 'linear-progress',
|
},
|
}}
|
/>
|
</div>
|
);
|
};
|