import { Box, Card, Grid, LinearProgress, Select, MenuItem, ListItemText, Tooltip, IconButton } from "@mui/material";
|
import React, { useState, useRef, useEffect, useMemo } from "react";
|
import {
|
List,
|
DatagridConfigurable,
|
SearchInput,
|
TopToolbar,
|
Button,
|
SelectColumnsButton,
|
EditButton,
|
FilterButton,
|
CreateButton,
|
ExportButton,
|
BulkDeleteButton,
|
WrapperField,
|
useRecordContext,
|
useTranslate,
|
useNotify,
|
useListContext,
|
FunctionField,
|
TextField,
|
NumberField,
|
DateField,
|
BooleanField,
|
ReferenceField,
|
TextInput,
|
DateTimeInput,
|
DateInput,
|
SelectInput,
|
NumberInput,
|
ReferenceInput,
|
ReferenceArrayInput,
|
AutocompleteInput,
|
DeleteButton,
|
SimpleForm,
|
required,
|
Form,
|
useRefresh,
|
useRedirect,
|
} from 'react-admin';
|
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting';
|
import { styled } from '@mui/material/styles';
|
import { DataGrid, useGridApiContext, GridActionsCellItem, useGridApiRef } from '@mui/x-data-grid';
|
import request from '@/utils/request';
|
import ConfirmationNumberOutlinedIcon from '@mui/icons-material/ConfirmationNumberOutlined';
|
import CloseSharpIcon from '@mui/icons-material/CloseSharp';
|
import ConfirmButton from '../../components/ConfirmButton';
|
import { Delete, Edit, Add } from '@mui/icons-material';
|
|
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
|
'& .css-1vooibu-MuiSvgIcon-root': {
|
height: '.9em'
|
},
|
'& .RaDatagrid-row': {
|
cursor: 'auto'
|
},
|
'& .column-maktx': {
|
width: 200
|
}
|
}));
|
|
|
const OutStockPublic = (props) => {
|
const { record, open, setOpen } = props;
|
const notify = useNotify();
|
const gridRef = useGridApiRef();
|
const [rows, setRows] = useState({});
|
const translate = useTranslate();
|
const [selectedIds, setSelectedIds] = React.useState([]);
|
const [formData, setFormData] = useState({
|
orderId: record?.id
|
});
|
useEffect(() => {
|
getWaveRule()
|
}, [formData, open])
|
|
const getWaveRule = async () => {
|
if (formData.waveId == null && formData.waveId == undefined) {
|
return
|
}
|
const { data: { code, data, msg } } = await request.post('/outStock/order/getOutTaskItems', { ...formData });
|
|
if (code === 200) {
|
setRows(data)
|
} else {
|
notify(msg);
|
}
|
}
|
|
const handleChange = (value, name) => {
|
setFormData((prevData) => ({
|
...prevData,
|
[name]: value
|
}));
|
};
|
|
gridRef.current = useGridApiRef();
|
|
return (
|
<>
|
<Box>
|
<Grid sx={{ display: "flex" }} container rowSpacing={2} columnSpacing={2}>
|
<Grid item xl={5.7} gap={2} >
|
<Card>
|
<Form>
|
<ReferenceInput
|
source="type"
|
reference="waveRule"
|
>
|
<AutocompleteInput
|
label="table.field.waveRule.type"
|
onChange={(e) => handleChange(e, 'waveId')}
|
value={formData.type}
|
validate={required()}
|
/>
|
</ReferenceInput>
|
</Form>
|
<List
|
resource="outStockItem"
|
storeKey='outStockItem'
|
sx={{
|
flexGrow: 1,
|
transition: (theme) =>
|
theme.transitions.create(['all'], {
|
duration: theme.transitions.duration.enteringScreen,
|
}),
|
}}
|
title={"menu.outStockItem"}
|
empty={false}
|
filter={{ asnId: record?.id, deleted: 0 }}
|
sort={{ field: "create_time", order: "desc" }}
|
actions={false}
|
perPage={DEFAULT_ITEM_PAGE_SIZE}
|
>
|
<LinearProgress
|
sx={{ height: "2px", position: 'absolute', top: 0, left: 0, right: 0, }}
|
/>
|
<StyledDatagrid
|
preferenceKey='outStockItem'
|
bulkActionButtons={false}
|
rowClick={false}
|
omit={['id', 'splrName', 'qty', 'poCode', 'workQty']}
|
>
|
<NumberField source="id" />
|
<TextField source="asnCode" label="table.field.outStockItem.asnCode" />
|
<TextField source="poCode" label="table.field.outStockItem.poCode" />
|
<TextField source="matnrCode" label="table.field.outStockItem.matnrCode" />
|
<TextField source="maktx" label="table.field.outStockItem.maktx" />
|
<NumberField source="anfme" label="table.field.outStockItem.anfme" />
|
<NumberField source="workQty" label="table.field.outStockItem.workQty" />
|
<NumberField source="qty" label="table.field.outStockItem.qty" />
|
<TextField source="stockUnit" label="table.field.outStockItem.stockUnit" />
|
<TextField source="splrName" label="table.field.outStockItem.splrName" />
|
</StyledDatagrid>
|
</List>
|
</Card>
|
</Grid>
|
<Grid item xl={6.3} gap={2}>
|
<Card>
|
<Box sx={{ height: 500, width: '100%' }}>
|
<DataGrid
|
rows={rows}
|
columns={columns}
|
apiRef={gridRef}
|
initialState={{
|
pagination: {
|
paginationModel: {
|
pageSize: 15,
|
},
|
},
|
}}
|
checkboxSelection
|
pageSizeOptions={[15, 25, 35, 45]}
|
onRowSelectionModelChange={(ids) => {
|
setSelectedIds(ids)
|
}}
|
/>
|
</Box>
|
<Box sx={{ textAlign: 'center' }}>
|
<CloseButton setOpen={setOpen} />
|
<SubmitButton selectedIds={selectedIds} setSelectedIds={setSelectedIds} gridRef={gridRef} />
|
</Box>
|
</Card>
|
</Grid>
|
</Grid>
|
</Box>
|
</>
|
);
|
}
|
|
|
//提交按钮
|
const SubmitButton = ({ selectedIds, setSelectedIds, gridRef }) => {
|
const notify = useNotify();
|
const refresh = useRefresh();
|
const redirect = useRedirect();
|
const submit = async () => {
|
const items = gridRef.current?.getSortedRows();
|
const { data: { code, data, msg } } = await request.post('/outStock/generate/tasks', { items });
|
if (code == 200) {
|
refresh();
|
redirect("/task")
|
} else {
|
notify(msg);
|
}
|
}
|
return (
|
<ConfirmButton
|
label="toolbar.confirm"
|
variant="contained"
|
size="medium"
|
onConfirm={submit}
|
startIcon={<ConfirmationNumberOutlinedIcon />}
|
/>
|
)
|
}
|
|
//关闭按钮
|
const CloseButton = ({ setOpen }) => {
|
const close = () => {
|
setOpen(false)
|
}
|
return (
|
<Button
|
label="toolbar.close"
|
variant="outlined"
|
size="medium"
|
onClick={close}
|
startIcon={<CloseSharpIcon />}
|
sx={{ margin: '3.5em' }} />
|
)
|
}
|
|
const columns = [
|
{ field: 'id', headerName: 'ID', width: 40 },
|
{ field: 'locCode', headerName: '库位', width: 110 },
|
{ field: 'barcode', headerName: '容器', width: 120 },
|
{ field: 'batch', headerName: '批次', width: 90 },
|
{ field: 'unit', headerName: '单位', width: 90 },
|
{ field: 'outQty', headerName: '本次出库数量', width: 110 },
|
{
|
field: 'siteNo',
|
headerName: '出库口',
|
width: 90,
|
type: 'singleSelect',
|
editable: true,
|
renderCell: (params) => (
|
<OutStockSiteNo value={params.value} />
|
),
|
renderEditCell: (params) => (
|
<OutStockSite {...params} />
|
),
|
},
|
{
|
field: 'actions',
|
type: 'actions',
|
headerName: '操作',
|
with: 120,
|
getActions: (params) => [
|
<GridActionsCellItem
|
icon={<Delete />}
|
label="Delete"
|
onClick={() => handleDelete(params.row.id)}
|
/>,
|
]
|
},
|
]
|
|
/**
|
* 删除事件
|
* @param {*} params
|
*/
|
const handleDelete = (params) => {
|
console.log(params);
|
|
}
|
|
|
const OutStockSiteNo = React.memo(function OutStockSiteNo(props) {
|
const { value } = props;
|
if (!value) {
|
return null;
|
}
|
return (
|
<Box
|
sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
|
>
|
<span>{value}</span>
|
</Box>
|
);
|
});
|
|
|
const OutStockSite = (params) => {
|
const { id, field, siteNo, row: { staNos } } = params;
|
const apiRef = useGridApiContext();
|
const handleChange = async (event) => {
|
await apiRef.current.setEditCellValue(
|
{ id, field, value: event.target.value },
|
event,
|
);
|
apiRef.current.stopCellEditMode({ id, field });
|
};
|
|
const handleClose = (event, reason) => {
|
if (reason === 'backdropClick') {
|
apiRef.current.stopCellEditMode({ id, field });
|
}
|
};
|
|
return (
|
<Select
|
value={siteNo}
|
onChange={handleChange}
|
MenuProps={{
|
onClose: handleClose,
|
}}
|
sx={{
|
height: '100%',
|
'& .MuiSelect-select': {
|
display: 'flex',
|
alignItems: 'center',
|
pl: 1,
|
},
|
}}
|
autoFocus
|
fullWidth
|
open
|
>
|
{staNos.map((option) => {
|
return (
|
<MenuItem
|
key={option}
|
value={option.staNo}
|
>
|
<ListItemText sx={{ overflow: 'hidden' }} primary={option.staNo} />
|
</MenuItem>
|
);
|
})}
|
</Select >
|
)
|
}
|
|
|
export default OutStockPublic;
|