From 3eb25a0bb9b4bd0b914cf2cba60ecb8cc404fac9 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期二, 10 六月 2025 16:01:56 +0800
Subject: [PATCH] 任务取消功能优化
---
rsf-admin/src/page/orders/outStock/OutStockPublic.jsx | 272 +++++++++++++++++++++++++++--------------------------
1 files changed, 139 insertions(+), 133 deletions(-)
diff --git a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
index b3b7062..b3570fe 100644
--- a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
+++ b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
@@ -94,7 +94,6 @@
}));
};
- gridRef.current = useGridApiRef();
return (
<>
@@ -158,27 +157,11 @@
<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)
- }}
- />
+ <PreviewTable rows={rows} gridRef={gridRef} setRows={setRows} record={record}/>
</Box>
<Box sx={{ textAlign: 'center' }}>
<CloseButton setOpen={setOpen} />
- <SubmitButton selectedIds={selectedIds} setSelectedIds={setSelectedIds} gridRef={gridRef} />
+ <SubmitButton selectedIds={selectedIds} setSelectedIds={setSelectedIds} gridRef={gridRef} record={record}/>
</Box>
</Card>
</Grid>
@@ -188,15 +171,149 @@
);
}
+const PreviewTable = ({ rows, gridRef, setRows, record }) => {
+ gridRef.current = useGridApiRef();
+
+ 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, rows, setRows)}
+ />,
+ ]
+ },
+ ]
+
+ /**
+ * 鍒犻櫎浜嬩欢
+ * @param {*} params
+ */
+ const handleDelete = (params, rows, setRows) => {
+ const outRows = rows.filter(row => {
+ return row.id !== params.id
+ })
+ setRows(outRows)
+ }
+
+ 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 >
+ )
+ }
+
+ return (
+ <DataGrid
+ rows={rows}
+ columns={columns}
+ apiRef={gridRef}
+ initialState={{
+ pagination: {
+ paginationModel: {
+ pageSize: 15,
+ },
+ },
+ }}
+ checkboxSelection
+ pageSizeOptions={[15, 25, 35, 45]}
+ onRowSelectionModelChange={(ids) => {
+ setSelectedIds(ids)
+ }}
+ />
+ )
+}
//鎻愪氦鎸夐挳
-const SubmitButton = ({ selectedIds, setSelectedIds, gridRef }) => {
+const SubmitButton = ({ selectedIds, setSelectedIds, gridRef, record }) => {
const notify = useNotify();
const refresh = useRefresh();
- const redirect = useRedirect();
+ const redirect = useRedirect();
const submit = async () => {
+ console.log(record);
const items = gridRef.current?.getSortedRows();
- const { data: { code, data, msg } } = await request.post('/outStock/generate/tasks', { items });
+ const { data: { code, data, msg } } = await request.post('/outStock/generate/tasks', { items, outId: record?.id });
if (code == 200) {
refresh();
redirect("/task")
@@ -230,117 +347,6 @@
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;
--
Gitblit v1.9.1