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 | 96 ++++++++++++++++++++++++++++++-----------------
1 files changed, 61 insertions(+), 35 deletions(-)
diff --git a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
index 6836a37..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,17 +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 = [
+ 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: 60 },
- { field: 'outQty', headerName: '鍑哄簱鏁伴噺', width: 110 ,valueFormatter: (val) => val <= 0 ? '搴撳瓨涓嶈冻' : val,},
+ { field: 'outQty', headerName: '鍑哄簱鏁伴噺', width: 110, },
+ {
+ field: 'anfme', headerName: '搴撳瓨鏁伴噺', width: 110,
+ renderCell: (params) => (
+ <OutStockAnfme value={params.value} />
+ )
+ },
{
field: 'siteNo',
headerName: '鍑哄簱鍙�',
@@ -232,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];
/**
* 鍒犻櫎浜嬩欢
@@ -258,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>
);
@@ -276,9 +310,8 @@
const selectSiteNo = () => {
setDialog(true)
}
-
return (
- selectedIds.length > 0 ? <Box sx={{
+ <Box sx={{
p: 1,
display: 'flex',
justifyContent: 'flex-end',
@@ -290,7 +323,7 @@
label="toolbar.modiftySite"
size="medium"
sx={{ mr: 1 }} />
- </Box> : <></>
+ </Box>
);
}
@@ -350,16 +383,10 @@
columns={columns}
slots={{ toolbar: CustomToolBar }}
apiRef={gridRef}
- initialState={{
- pagination: {
- paginationModel: {
- pageSize: 15,
- },
- },
- }}
checkboxSelection
disableRowSelectionOnClick
- pageSizeOptions={[15, 25, 35, 45]}
+ hideFooterPagination={true} // 闅愯棌鍒嗛〉鎺т欢
+ hideFooter={false}
onRowSelectionModelChange={(ids) => {
setSelectedIds(ids)
}}
@@ -375,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