| New file | 
|  |  |  | 
|---|
|  |  |  | import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | SavedQueriesList, | 
|---|
|  |  |  | FilterLiveSearch, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | useListContext, | 
|---|
|  |  |  | SearchInput | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import BookmarkIcon from '@mui/icons-material/BookmarkBorder'; | 
|---|
|  |  |  | 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"; | 
|---|
|  |  |  | import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const LocListAside = () => { | 
|---|
|  |  |  | const theme = useTheme(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const { setFilters } = useListContext(); // 获取列表上下文 | 
|---|
|  |  |  | const [selectedOption, setSelectedOption] = useState(null); | 
|---|
|  |  |  | const [treeData, setTreeData] = useState([]); | 
|---|
|  |  |  | const [defaultIds, setDefaultIds] = useState([]); | 
|---|
|  |  |  | const [condition, setCondition] = useState(''); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const haveChildren = (item) => { | 
|---|
|  |  |  | if (Array.isArray(item)) { | 
|---|
|  |  |  | return item.map((k) => haveChildren(k)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (item && typeof item === 'object') { | 
|---|
|  |  |  | if (item.index !== undefined) { | 
|---|
|  |  |  | item.index = item.index.toString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (item.children && Array.isArray(item.children)) { | 
|---|
|  |  |  | item.children = haveChildren(item.children); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return item; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | http() | 
|---|
|  |  |  | }, [condition]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const http = () => { | 
|---|
|  |  |  | request.post('/warehouse/areas', { 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(error => { | 
|---|
|  |  |  | notify('Error fetching tree data'); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const handleNodeSelect = (event, nodeId) => { | 
|---|
|  |  |  | const row = apiRef.current.getItem(nodeId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (row.flagWare === 1) { | 
|---|
|  |  |  | setFilters({ warehouseId: row.id, areaId: '' }); | 
|---|
|  |  |  | } else if (row.flagWare === 0) { | 
|---|
|  |  |  | setFilters({ areaId: row.id, warehouseId: row.warehouseId }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | const handleSearch = (e) => { | 
|---|
|  |  |  | setCondition(e.target.value) | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const apiRef = useTreeViewApiRef(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const CustomCheckbox = React.forwardRef(function CustomCheckbox(props, ref) { | 
|---|
|  |  |  | return <input type="checkbox" ref={ref} {...props} />; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const CustomTreeItem = React.forwardRef(function CustomTreeItem(props, ref) { | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <TreeItem2 | 
|---|
|  |  |  | {...props} | 
|---|
|  |  |  | ref={ref} | 
|---|
|  |  |  | slots={{ | 
|---|
|  |  |  | checkbox: CustomCheckbox, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Card | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | order: -1, | 
|---|
|  |  |  | mr: 2, | 
|---|
|  |  |  | mt: 8, | 
|---|
|  |  |  | alignSelf: 'flex-start', | 
|---|
|  |  |  | border: theme.palette.mode === 'light' && '1px solid #e0e0e3', | 
|---|
|  |  |  | width: 250, | 
|---|
|  |  |  | minWidth: 150, | 
|---|
|  |  |  | height: `100%`, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <CardContent> | 
|---|
|  |  |  | {/* <Input | 
|---|
|  |  |  | placeholder="搜索库位" | 
|---|
|  |  |  | sx={{ '--Input-focused': 1, marginBottom: '10px' }} | 
|---|
|  |  |  | onChange={handleSearch} | 
|---|
|  |  |  | /> */} | 
|---|
|  |  |  | <RichTreeView | 
|---|
|  |  |  | defaultExpandedItems={defaultIds} | 
|---|
|  |  |  | expansionTrigger="iconContainer" | 
|---|
|  |  |  | items={treeData} | 
|---|
|  |  |  | slots={CustomTreeItem} | 
|---|
|  |  |  | apiRef={apiRef} | 
|---|
|  |  |  | getItemId={(item) => item.index} | 
|---|
|  |  |  | getItemLabel={(item) => item.name} | 
|---|
|  |  |  | onItemClick={handleNodeSelect} // 监听节点点击事件 | 
|---|
|  |  |  | /> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </CardContent> | 
|---|
|  |  |  | </Card> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export default LocListAside; | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; | 
|---|
|  |  |  | import { useNavigate } from 'react-router-dom'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | List, | 
|---|
|  |  |  | DatagridConfigurable, | 
|---|
|  |  |  | SearchInput, | 
|---|
|  |  |  | TopToolbar, | 
|---|
|  |  |  | SelectColumnsButton, | 
|---|
|  |  |  | EditButton, | 
|---|
|  |  |  | FilterButton, | 
|---|
|  |  |  | CreateButton, | 
|---|
|  |  |  | ExportButton, | 
|---|
|  |  |  | BulkDeleteButton, | 
|---|
|  |  |  | WrapperField, | 
|---|
|  |  |  | useRecordContext, | 
|---|
|  |  |  | useTranslate, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | useListContext, | 
|---|
|  |  |  | FunctionField, | 
|---|
|  |  |  | TextField, | 
|---|
|  |  |  | NumberField, | 
|---|
|  |  |  | DateField, | 
|---|
|  |  |  | BooleanField, | 
|---|
|  |  |  | ReferenceField, | 
|---|
|  |  |  | TextInput, | 
|---|
|  |  |  | DateTimeInput, | 
|---|
|  |  |  | DateInput, | 
|---|
|  |  |  | SelectInput, | 
|---|
|  |  |  | NumberInput, | 
|---|
|  |  |  | ReferenceInput, | 
|---|
|  |  |  | ReferenceArrayInput, | 
|---|
|  |  |  | useRefresh, | 
|---|
|  |  |  | AutocompleteInput, | 
|---|
|  |  |  | DeleteButton, | 
|---|
|  |  |  | useGetRecordId, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { Box, Typography, Card, Stack, LinearProgress } from '@mui/material'; | 
|---|
|  |  |  | import { styled } from '@mui/material/styles'; | 
|---|
|  |  |  | import PageDrawer from "../components/PageDrawer"; | 
|---|
|  |  |  | import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|---|
|  |  |  | '& .css-1vooibu-MuiSvgIcon-root': { | 
|---|
|  |  |  | height: '.9em' | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | '& .RaDatagrid-row': { | 
|---|
|  |  |  | cursor: 'auto' | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | '& .column-name': { | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | '& .opt': { | 
|---|
|  |  |  | width: 100 | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | })); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const filters = [ | 
|---|
|  |  |  | <SearchInput source="condition" alwaysOn />, | 
|---|
|  |  |  | <DateInput label='common.time.after' source="timeStart" />, | 
|---|
|  |  |  | <DateInput label='common.time.before' source="timeEnd" />, | 
|---|
|  |  |  | <NumberInput source="locId" label="table.field.locItem.locId" />, | 
|---|
|  |  |  | <TextInput source="locCode" label="table.field.locItem.locCode" />, | 
|---|
|  |  |  | <NumberInput source="orderId" label="table.field.locItem.orderId" />, | 
|---|
|  |  |  | <TextInput source="type" label="table.field.locItem.type" />, | 
|---|
|  |  |  | <NumberInput source="orderItemId" label="table.field.locItem.orderItemId" />, | 
|---|
|  |  |  | <NumberInput source="wkType" label="table.field.locItem.wkType" />, | 
|---|
|  |  |  | <NumberInput source="matnrId" label="table.field.locItem.matnrId" />, | 
|---|
|  |  |  | <TextInput source="maktx" label="table.field.locItem.maktx" />, | 
|---|
|  |  |  | <TextInput source="matnrCode" label="table.field.locItem.matnrCode" />, | 
|---|
|  |  |  | <TextInput source="trackCode" label="table.field.locItem.trackCode" />, | 
|---|
|  |  |  | <TextInput source="unit" label="table.field.locItem.unit" />, | 
|---|
|  |  |  | <NumberInput source="anfme" label="table.field.locItem.anfme" />, | 
|---|
|  |  |  | <NumberInput source="qty" label="table.field.locItem.qty" />, | 
|---|
|  |  |  | <NumberInput source="workQty" label="table.field.locItem.workQty" />, | 
|---|
|  |  |  | <TextInput source="batch" label="table.field.locItem.batch" />, | 
|---|
|  |  |  | <TextInput source="splrBatch" label="table.field.locItem.splrBatch" />, | 
|---|
|  |  |  | <TextInput source="spec" label="table.field.locItem.spec" />, | 
|---|
|  |  |  | <TextInput source="model" label="table.field.locItem.model" />, | 
|---|
|  |  |  | <TextInput source="fieldsIndex" label="table.field.locItem.fieldsIndex" />, | 
|---|
|  |  |  | <TextInput label="common.field.memo" source="memo" />, | 
|---|
|  |  |  | <SelectInput | 
|---|
|  |  |  | label="common.field.status" | 
|---|
|  |  |  | source="status" | 
|---|
|  |  |  | choices={[ | 
|---|
|  |  |  | { id: '1', name: 'common.enums.statusTrue' }, | 
|---|
|  |  |  | { id: '0', name: 'common.enums.statusFalse' }, | 
|---|
|  |  |  | ]} | 
|---|
|  |  |  | resettable | 
|---|
|  |  |  | />, | 
|---|
|  |  |  | ] | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const LocItemList = () => { | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const [createDialog, setCreateDialog] = useState(false); | 
|---|
|  |  |  | const [drawerVal, setDrawerVal] = useState(false); | 
|---|
|  |  |  | const locId = useGetRecordId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box display="flex"> | 
|---|
|  |  |  | <List | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | flexGrow: 1, | 
|---|
|  |  |  | transition: (theme) => | 
|---|
|  |  |  | theme.transitions.create(['all'], { | 
|---|
|  |  |  | duration: theme.transitions.duration.enteringScreen, | 
|---|
|  |  |  | }), | 
|---|
|  |  |  | marginRight: !!drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | title={"menu.locItem"} | 
|---|
|  |  |  | empty={false} | 
|---|
|  |  |  | filter={{locId: locId}} | 
|---|
|  |  |  | filters={filters} | 
|---|
|  |  |  | sort={{ field: "create_time", order: "desc" }} | 
|---|
|  |  |  | actions={( | 
|---|
|  |  |  | <TopToolbar> | 
|---|
|  |  |  | <FilterButton /> | 
|---|
|  |  |  | <SelectColumnsButton preferenceKey='locItem' /> | 
|---|
|  |  |  | </TopToolbar> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | perPage={DEFAULT_PAGE_SIZE} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <DynamicFields /> | 
|---|
|  |  |  | </List> | 
|---|
|  |  |  | <PageDrawer | 
|---|
|  |  |  | title='LocItem Detail' | 
|---|
|  |  |  | drawerVal={drawerVal} | 
|---|
|  |  |  | setDrawerVal={setDrawerVal} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | </PageDrawer> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export default LocItemList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const DynamicFields = (props) => { | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const [columns, setColumns] = useState([]); | 
|---|
|  |  |  | const { isLoading } = useListContext(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | getDynamicFields(); | 
|---|
|  |  |  | }, []); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const getDynamicFields = async () => { | 
|---|
|  |  |  | const { data: { code, data, msg }, } = await request.get("/fields/enable/list"); | 
|---|
|  |  |  | if (code == 200) { | 
|---|
|  |  |  | const arr = [ | 
|---|
|  |  |  | <NumberField source="id" />, | 
|---|
|  |  |  | <NumberField source="locId" label="table.field.locItem.locId" />, | 
|---|
|  |  |  | <TextField source="wareArea" label="table.field.locItem.wareArea" />, | 
|---|
|  |  |  | <TextField source="locCode" label="table.field.locItem.locCode" />, | 
|---|
|  |  |  | <NumberField source="orderId" label="table.field.locItem.orderId" />, | 
|---|
|  |  |  | <TextField source="type$" label="table.field.locItem.type" />, | 
|---|
|  |  |  | <NumberField source="orderItemId" label="table.field.locItem.orderItemId" />, | 
|---|
|  |  |  | <NumberField source="wkType$" label="table.field.locItem.wkType" />, | 
|---|
|  |  |  | <NumberField source="matnrId" label="table.field.locItem.matnrId" />, | 
|---|
|  |  |  | <TextField source="matnrCode" label="table.field.locItem.matnrCode" />, | 
|---|
|  |  |  | <TextField source="maktx" label="table.field.locItem.maktx" />, | 
|---|
|  |  |  | <TextField source="spec" label="table.field.locItem.spec" />, | 
|---|
|  |  |  | <TextField source="model" label="table.field.locItem.model" />, | 
|---|
|  |  |  | <TextField source="batch" label="table.field.locItem.batch" />, | 
|---|
|  |  |  | <TextField source="trackCode" label="table.field.locItem.trackCode" />, | 
|---|
|  |  |  | <TextField source="unit" label="table.field.locItem.unit" />, | 
|---|
|  |  |  | <NumberField source="anfme" label="table.field.locItem.anfme" />, | 
|---|
|  |  |  | <NumberField source="workQty" label="table.field.locItem.workQty" />, | 
|---|
|  |  |  | <NumberField source="qty" label="table.field.locItem.qty" />, | 
|---|
|  |  |  | <TextField source="splrBatch" label="table.field.locItem.splrBatch" />, | 
|---|
|  |  |  | <TextField source="fieldsIndex" label="table.field.locItem.fieldsIndex" />, | 
|---|
|  |  |  | ] | 
|---|
|  |  |  | const fields = data.map(el => <TextField key={el.fields} source={`extendFields.[${el.fields}]`} label={el.fieldsAlise} />) | 
|---|
|  |  |  | const lastArr = [ | 
|---|
|  |  |  | <TextField source="updateBy$" label="common.field.updateBy" />, | 
|---|
|  |  |  | <DateField source="updateTime" label="common.field.updateTime" showTime />, | 
|---|
|  |  |  | <TextField source="createBy$" label="common.field.createBy" />, | 
|---|
|  |  |  | <DateField source="createTime" label="common.field.createTime" showTime />, | 
|---|
|  |  |  | <BooleanField source="statusBool" label="common.field.status" sortable={false} />, | 
|---|
|  |  |  | <TextField source="memo" label="common.field.memo" sortable={false} />, | 
|---|
|  |  |  | ] | 
|---|
|  |  |  | setColumns([...arr, ...fields, ...lastArr]); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box sx={{ position: 'relative', minHeight: "60vh", }}> | 
|---|
|  |  |  | {isLoading && ( | 
|---|
|  |  |  | <LinearProgress | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | height: "2px", | 
|---|
|  |  |  | position: 'absolute', | 
|---|
|  |  |  | top: 0, | 
|---|
|  |  |  | left: 0, | 
|---|
|  |  |  | right: 0, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | {columns.length > 0 && | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='locItem' | 
|---|
|  |  |  | bulkActionButtons={false} | 
|---|
|  |  |  | rowClick={false} | 
|---|
|  |  |  | expand={false} | 
|---|
|  |  |  | expandSingle={true} | 
|---|
|  |  |  | omit={['id', 'createTime','spec', 'model', 'locId', 'orderId', 'trackCode', 'orderItemId', 'matnrId', 'splrBatch','createBy', 'memo', 'fieldsIndex']} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {columns.map((column) => column)} | 
|---|
|  |  |  | </StyledDatagrid>} | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Update 字典数据集") | 
|---|
|  |  |  | @PostMapping("/companys/update") | 
|---|
|  |  |  | public R update(@RequestBody Companys companys) { | 
|---|
|  |  |  | companys.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | if (Objects.isNull(companys.getName())) { | 
|---|
|  |  |  | throw new CoolException("名称不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("类型不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | companys.setUpdateTime(null); | 
|---|
|  |  |  | companys.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | if (!companysService.updateById(companys)) { | 
|---|
|  |  |  | return R.error("Update Fail"); | 
|---|
|  |  |  | } | 
|---|