From 275bcf975a288730b7e3c26f67fe484bc33f0510 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 12 六月 2025 08:51:33 +0800
Subject: [PATCH] 代码优化
---
 rsf-admin/src/page/orders/outStock/OutStockPublic.jsx |  102 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 65 insertions(+), 37 deletions(-)
diff --git a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
index 40e4607..e63b5a2 100644
--- a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
+++ b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
@@ -57,14 +57,18 @@
     },
     '& .column-maktx': {
         width: 200
+    },
+    '& .RaBulkActionsToolbar-toolbar': {
+        display: 'none'
     }
+
 }));
 
 const OutStockPublic = (props) => {
     const { record, open, setOpen } = props;
     const notify = useNotify();
     const gridRef = useGridApiRef();
-    const [rows, setRows] = useState({});
+    const [rows, setRows] = useState([]);
     const translate = useTranslate();
     const [selectedIds, setSelectedIds] = useState([]);
     const [formData, setFormData] = useState({
@@ -82,10 +86,10 @@
         setDialog(false);
         setSelectedValue(value);
         const newRows = rows.map(item => {
-            return {
+            return selectedIds.includes(item?.id) ? {
                 ...item,
                 siteNo: value?.site
-            }
+            } : item
         })
         setRows(newRows);
     };
@@ -158,7 +162,7 @@
                                 />
                                 <StyledDatagrid
                                     preferenceKey='outStockItem'
-                                    bulkActionButtons={false}
+                                    bulkActionButtons={<></>}
                                     rowClick={false}
                                     omit={['id', 'splrName', 'qty', 'poCode', 'workQty']}
                                 >
@@ -184,6 +188,7 @@
                                     gridRef={gridRef}
                                     setRows={setRows}
                                     record={record}
+                                    formData={formData}
                                     selectedIds={selectedIds}
                                     setDialog={setDialog}
                                     setSelectedIds={setSelectedIds}
@@ -208,16 +213,31 @@
     );
 }
 
-const PreviewTable = ({ rows, gridRef, setRows, record, selectedIds, setSelectedIds, setDialog }) => {
+const PreviewTable = ({ rows, gridRef, setRows, record, selectedIds, setSelectedIds, setDialog, formData }) => {
     gridRef.current = useGridApiRef();
+    const translate = useTranslate();
 
-    const columns = [
-        { field: 'id', headerName: 'ID', width: 40 },
+    useEffect(() => {
+        if (selectedIds.length > 0) {
+            console.log(selectedIds);
+        }
+    }, [selectedIds])
+
+
+    const baseColumns = [
+        // { field: 'id', headerName: 'ID', width: 40 },
         { field: 'locCode', headerName: '搴撲綅', width: 110 },
         { field: 'barcode', headerName: '瀹瑰櫒', width: 120 },
+        { field: 'matnrCode', headerName: '鐗╂枡缂栫爜', width: 120 },
         { field: 'batch', headerName: '鎵规', width: 90 },
-        { field: 'unit', headerName: '鍗曚綅', width: 90 },
-        { field: 'outQty', headerName: '鏈鍑哄簱鏁伴噺', width: 110 },
+        { field: 'unit', headerName: '鍗曚綅', width: 60 },
+        { field: 'outQty', headerName: '鍑哄簱鏁伴噺', width: 110, },
+        {
+            field: 'anfme', headerName: '搴撳瓨鏁伴噺', width: 110,
+            renderCell: (params) => (
+                <OutStockAnfme value={params.value} />
+            )
+        },
         {
             field: 'siteNo',
             headerName: '鍑哄簱鍙�',
@@ -231,20 +251,23 @@
                 <OutStockSite {...params} />
             ),
         },
-        {
-            field: 'actions',
-            type: 'actions',
-            headerName: '鎿嶄綔',
-            with: 120,
-            getActions: (params) => [
-                <GridActionsCellItem
-                    icon={<Delete />}
-                    label="Delete"
-                    onClick={() => handleDelete(params.row, rows, setRows)}
-                />,
-            ]
-        },
     ]
+
+    const optAction = {
+        field: 'actions',
+        type: 'actions',
+        headerName: translate('common.field.opt'),
+        with: 120,
+        getActions: (params) => [
+            <GridActionsCellItem
+                icon={<Delete />}
+                label="Delete"
+                onClick={() => handleDelete(params.row, rows, setRows)}
+            />,
+        ]
+    }
+
+    const columns = (formData.waveId == 15 || formData.waveId == 16) ? [...baseColumns] : [...baseColumns, optAction];
 
     /**
      * 鍒犻櫎浜嬩欢
@@ -257,15 +280,27 @@
         setRows(outRows)
     }
 
+    const OutStockAnfme = React.memo(function OutStockAnfme(props) {
+        const { value } = props;
+        return (
+            value > 0 ?
+                <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
+                    <span>{value}</span>
+                </Box>
+                :
+                <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
+                    <span style={{ color: 'red' }}>{translate('common.edit.title.insuffInventory')}</span>
+                </Box>
+        );
+    });
+
     const OutStockSiteNo = React.memo(function OutStockSiteNo(props) {
         const { value } = props;
         if (!value) {
             return null;
         }
         return (
-            <Box
-                sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
-            >
+            <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                 <span>{value}</span>
             </Box>
         );
@@ -275,9 +310,8 @@
         const selectSiteNo = () => {
             setDialog(true)
         }
-
         return (
-            selectedIds.length > 0 ? <Box sx={{
+            <Box sx={{
                 p: 1,
                 display: 'flex',
                 justifyContent: 'flex-end',
@@ -289,7 +323,7 @@
                     label="toolbar.modiftySite"
                     size="medium"
                     sx={{ mr: 1 }} />
-            </Box> : <></>
+            </Box>
         );
     }
 
@@ -349,15 +383,10 @@
             columns={columns}
             slots={{ toolbar: CustomToolBar }}
             apiRef={gridRef}
-            initialState={{
-                pagination: {
-                    paginationModel: {
-                        pageSize: 15,
-                    },
-                },
-            }}
             checkboxSelection
-            pageSizeOptions={[15, 25, 35, 45]}
+            disableRowSelectionOnClick
+            hideFooterPagination={true}  // 闅愯棌鍒嗛〉鎺т欢
+            hideFooter={false}
             onRowSelectionModelChange={(ids) => {
                 setSelectedIds(ids)
             }}
@@ -373,7 +402,6 @@
     const refresh = useRefresh();
     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, outId: record?.id });
         if (code == 200) {
--
Gitblit v1.9.1