| | |
| | | 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"; |
| | | |
| | |
| | | const { setFilters } = useListContext(); // 获取列表上下文 |
| | | const [selectedOption, setSelectedOption] = useState(null); |
| | | const [treeData, setTreeData] = useState([]); |
| | | const [defaultIds, setDefaultIds] = useState(['29']); |
| | | const [defaultIds, setDefaultIds] = useState(['65']); |
| | | const [condition, setCondition] = useState(''); |
| | | |
| | | const haveChildren = (item) => { |
| | | if (Array.isArray(item)) { |
| | |
| | | return item; |
| | | }; |
| | | useEffect(() => { |
| | | request.post('/matnrGroup/tree') |
| | | http() |
| | | }, [condition]); |
| | | |
| | | const http = () => { |
| | | request.post('/matnrGroup/tree', { condition }) |
| | | .then(res => { |
| | | if (res?.data?.code === 200) { |
| | | let data = res.data.data; |
| | | let items = haveChildren(data) |
| | | |
| | | setTreeData(items) |
| | | setDefaultIds([items.at(0).id]) |
| | | |
| | | |
| | | } else { |
| | | notify(res.data.msg); |
| | |
| | | notify('Error fetching tree data'); |
| | | }); |
| | | |
| | | }, []); |
| | | } |
| | | const handleNodeSelect = (event, nodeId) => { |
| | | setFilters({ groupId: nodeId }); |
| | | }; |
| | | const handleSearch = () => { |
| | | console.log('Search Input:', selectedOption); |
| | | const handleSearch = (e) => { |
| | | setCondition(e.target.value) |
| | | }; |
| | | |
| | | |
| | |
| | | border: theme.palette.mode === 'light' && '1px solid #e0e0e3', |
| | | width: 250, |
| | | minWidth: 150, |
| | | height: `calc(100% - 120px)`, |
| | | height: `100%`, |
| | | }} |
| | | > |
| | | <CardContent> |
| | | <SavedQueriesList icon={<BookmarkIcon />} /> |
| | | <FilterLiveSearch source="condition" /> |
| | | <Input |
| | | placeholder="搜索物料分组" |
| | | sx={{ '--Input-focused': 1, marginBottom: '10px' }} |
| | | onChange={handleSearch} |
| | | /> |
| | | <RichTreeView |
| | | defaultExpandedItems={defaultIds} |
| | | expansionTrigger="iconContainer" |