From 48ad97c8a8afa2c9333bd00545dbc54bb4f0870a Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期五, 23 五月 2025 09:28:03 +0800 Subject: [PATCH] #盘点出库 --- rsf-admin/src/page/basicInfo/matnr/MatnrListAside.jsx | 110 +++++++++++++++++++++++++------------------------------ 1 files changed, 50 insertions(+), 60 deletions(-) diff --git a/rsf-admin/src/page/basicInfo/matnr/MatnrListAside.jsx b/rsf-admin/src/page/basicInfo/matnr/MatnrListAside.jsx index d61f6a8..dd93b57 100644 --- a/rsf-admin/src/page/basicInfo/matnr/MatnrListAside.jsx +++ b/rsf-admin/src/page/basicInfo/matnr/MatnrListAside.jsx @@ -4,10 +4,11 @@ SavedQueriesList, FilterLiveSearch, useNotify, - useListContext + useListContext, + SearchInput } from 'react-admin'; import BookmarkIcon from '@mui/icons-material/BookmarkBorder'; -import { Box, Typography, Card, CardContent, useTheme, TextField } from '@mui/material'; +import { Box, Typography, Card, CardContent, useTheme, Input } from '@mui/material'; import { RichTreeView } from "@mui/x-tree-view/RichTreeView"; import { TreeItem2 } from "@mui/x-tree-view/TreeItem2"; @@ -18,13 +19,39 @@ const { setFilters } = useListContext(); // 鑾峰彇鍒楄〃涓婁笅鏂� const [selectedOption, setSelectedOption] = useState(null); const [treeData, setTreeData] = useState([]); + const [defaultIds, setDefaultIds] = useState(['65']); + const [condition, setCondition] = useState(''); + const haveChildren = (item) => { + if (Array.isArray(item)) { + return item.map((k) => haveChildren(k)); + } + + if (item && typeof item === 'object') { + if (item.id !== undefined) { + item.id = item.id.toString(); + } + + if (item.children && Array.isArray(item.children)) { + item.children = haveChildren(item.children); + } + } + + return item; + }; useEffect(() => { - request.post('/matnrGroup/tree') + http() + }, [condition]); + + const http = () => { + request.post('/matnrGroup/tree', { condition }) .then(res => { - console.log('Tree Data:', res); if (res?.data?.code === 200) { - setTreeData(res.data.data); + let data = res.data.data; + let items = haveChildren(data) + setTreeData(items) + setDefaultIds([items.at(0).id]) + } else { notify(res.data.msg); } @@ -32,54 +59,13 @@ .catch(error => { notify('Error fetching tree data'); }); - - - - },[]); - - - const treeData1 = [ - { - id: '19', - label: '鍗婃垚鍝� ', - editable: true, - children: [ - { - id: 'grid-community', label: '@mui/x-data-grid', editable: true, children: [ - { id: 'grid-community22', label: '@mui/x-data-grid', editable: true },] - }, - { id: 'grid-pro', label: '@mui/x-data-grid-pro', editable: true }, - { id: 'grid-premium', label: '@mui/x-data-grid-premium', editable: true }, - ], - }, - { - id: '18', - label: '鍘熸潗鏂�', - }, - { - id: 'charts', - label: 'Charts', - children: [{ id: 'charts-community', label: '@mui/x-charts' }], - }, - { - id: 'tree-view', - label: 'Tree View', - children: [{ id: 'tree-view-community', label: '@mui/x-tree-view' }], - }, - { - id: 'tree-view2', - label: 'Tree View3', - children: [{ id: 'tree-view-community1', label: '@mui/x-tree-view' }], - }, - ]; + } const handleNodeSelect = (event, nodeId) => { - console.log('Selected Node ID:', nodeId); setFilters({ groupId: nodeId }); - // 鍦ㄨ繖閲屽彲浠ユ牴鎹� nodeId 鏇存柊涓诲唴瀹瑰尯鍩� }; - const handleSearch = () => { - console.log('Search Input:', selectedOption); + const handleSearch = (e) => { + setCondition(e.target.value) }; @@ -103,26 +89,30 @@ return ( <Card sx={{ - display: { xs: 'none', md: 'block', }, order: -1, mr: 2, mt: 8, alignSelf: 'flex-start', border: theme.palette.mode === 'light' && '1px solid #e0e0e3', - width: 250 + width: 250, + minWidth: 150, + height: `100%`, }} > <CardContent> - <SavedQueriesList icon={<BookmarkIcon />} /> - <FilterLiveSearch source="condition" /> - <RichTreeView - defaultExpandedItems={['grid', 'pickers']} - expansionTrigger="iconContainer" - items={ treeData } - slots={ CustomTreeItem } - onItemClick={handleNodeSelect} // 鐩戝惉鑺傜偣鐐瑰嚮浜嬩欢 - + <Input + placeholder="鎼滅储鐗╂枡鍒嗙粍" + sx={{ '--Input-focused': 1, marginBottom: '10px' }} + onChange={handleSearch} /> + <RichTreeView + defaultExpandedItems={defaultIds} + expansionTrigger="iconContainer" + items={treeData} + slots={CustomTreeItem} + onItemClick={handleNodeSelect} // 鐩戝惉鑺傜偣鐐瑰嚮浜嬩欢 + /> + </CardContent> </Card> ) -- Gitblit v1.9.1