| 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, | 
|     AutocompleteInput, | 
|     DeleteButton, | 
|     useRefresh, | 
|     Button, | 
|     useList, | 
| } from 'react-admin'; | 
| import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; | 
| import { Box, Typography, Card, Stack } from '@mui/material'; | 
| import MyCreateButton from "../../components/MyCreateButton"; | 
| import MyExportButton from '../../components/MyExportButton'; | 
| import DashboardIcon from '@mui/icons-material/Dashboard'; | 
| import DynamicField from "../../components/DynamicField"; | 
| import DiscountIcon from '@mui/icons-material/Discount'; | 
| import PageDrawer from "../../components/PageDrawer"; | 
| import EmptyData from "../../components/EmptyData"; | 
| import EditIcon from '@mui/icons-material/Edit'; | 
| import LinkIcon from '@mui/icons-material/Link'; | 
| import { styled } from '@mui/material/styles'; | 
| import SubzoneModal from './SubzoneModal'; | 
| import LocListAside from "./LocListAside"; | 
| import InitButton from './InitButton'; | 
| import BatchModal from './BatchModal'; | 
| import request from '@/utils/request'; | 
| import LocCreate from "./LocCreate"; | 
| import BindModal from "./BindModal"; | 
| import InitModal from "./InitModal"; | 
|   | 
| const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|     '& .css-1vooibu-MuiSvgIcon-root': { | 
|         height: '.9em' | 
|     }, | 
|     '& .RaDatagrid-row': { | 
|         cursor: 'auto' | 
|     }, | 
|     '& .column-name': { | 
|     }, | 
|     '& .opt': { | 
|         width: 180 | 
|     }, | 
|     // '& .RaDatagrid-headerCell': { | 
|     //     textAlign: 'left' | 
|     // }, | 
|     // '& .RaDatagrid-rowCell': { | 
|     //     textAlign: 'left' | 
|     // }, | 
|     '& .type .MuiTypography-root': { | 
|         whiteSpace: 'nowrap', | 
|         overflow: 'hidden', | 
|         textOverflow: 'ellipsis', | 
|         display: 'block', | 
|         width: 'auto', | 
|     }, | 
| })); | 
|   | 
| const LocList = () => { | 
|     const dicts = JSON.parse(localStorage.getItem('sys_dicts'))?.filter(dict => (dict.dictTypeCode == 'sys_loc_use_stas')) || []; | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|     const [initDialog, setInitDialog] = useState(false); | 
|     const [drawerVal, setDrawerVal] = useState(false); | 
|     const translate = useTranslate(); | 
|     const refresh = useRefresh(); | 
|     const notify = useNotify(); | 
|   | 
|     const filters = [ | 
|         <SearchInput source="condition" alwaysOn />, | 
|         <ReferenceInput | 
|             source="warehouseId" | 
|             label="table.field.loc.warehouseId" | 
|             reference="warehouse" | 
|         > | 
|             <AutocompleteInput | 
|                 label="table.field.loc.warehouseId" | 
|                 optionText="name" | 
|                 filterToQuery={(val) => ({ name: val })} | 
|             /> | 
|         </ReferenceInput>, | 
|         <ReferenceInput | 
|             source="areaId" | 
|             label="table.field.loc.areaId" | 
|             reference="warehouseAreas" | 
|         > | 
|             <AutocompleteInput | 
|                 label="table.field.loc.areaId" | 
|                 optionText="name" | 
|                 filterToQuery={(val) => ({ name: val })} | 
|             /> | 
|         </ReferenceInput>, | 
|         <AutocompleteInput | 
|             choices={dicts} | 
|             optionText="label" | 
|             label="table.field.loc.useStatus" | 
|             source="useStatus" | 
|             optionValue="value" | 
|             parse={v => v} | 
|             alwaysOn | 
|         />, | 
|         <TextInput source="code" label="table.field.loc.code" />, | 
|         <TextInput source="type" label="table.field.loc.type" />, | 
|         <TextInput source="name" label="table.field.loc.name" />, | 
|         <NumberInput source="flagLogic" label="table.field.loc.flagLogic" />, | 
|         <TextInput source="fucAtrrs" label="table.field.loc.fucAtrrs" />, | 
|         <TextInput source="barcode" label="table.field.loc.barcode" />, | 
|         <TextInput source="unit" label="table.field.loc.unit" />, | 
|         <TextInput source="size" label="table.field.loc.size" />, | 
|         <NumberInput source="row" label="table.field.loc.row" />, | 
|         <NumberInput source="col" label="table.field.loc.col" />, | 
|         <NumberInput source="lev" label="table.field.loc.lev" />, | 
|         <NumberInput source="channel" label="table.field.loc.channel" />, | 
|         <NumberInput source="maxParts" label="table.field.loc.maxParts" />, | 
|         <NumberInput source="maxPack" label="table.field.loc.maxPack" />, | 
|         <NumberInput source="flagLabelMange" label="table.field.loc.flagLabelMange" />, | 
|         <TextInput source="locAttrs" label="table.field.loc.locAttrs" />, | 
|   | 
|         <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 | 
|         />, | 
|     ] | 
|   | 
|     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.loc"} | 
|                 empty={<EmptyData | 
|                     children={ | 
|                         <Box sx={{ gap: 2, display: 'flex' }}> | 
|                             <Button | 
|                                 variant="contained" | 
|                                 color="primary" | 
|                                 sx={{ | 
|                                     fontSize: '1em', | 
|                                     mt: 2 | 
|                                 }} | 
|                                 onClick={() => { setCreateDialog(true) }}> | 
|                                 {translate('create.empty.button')} | 
|                             </Button> | 
|                             <Button | 
|                                 variant="contained" | 
|                                 color="primary" | 
|                                 sx={{ | 
|                                     fontSize: '1em', | 
|                                     mt: 2 | 
|                                 }} | 
|                                 onClick={() => { setInitDialog(true) }}> | 
|                                 {translate('toolbar.locInit')} | 
|                             </Button> | 
|                         </Box> | 
|                     } | 
|                     onClick={() => { }} />} | 
|                 filters={filters} | 
|                 sort={{ field: "'row'" }} | 
|                 actions={( | 
|                     <TopToolbar> | 
|                         <FilterButton /> | 
|                         <InitButton /> | 
|                         <MyCreateButton onClick={() => { setCreateDialog(true) }} /> | 
|                         <SelectColumnsButton preferenceKey='loc' /> | 
|                         <MyExportButton /> | 
|                     </TopToolbar> | 
|                 )} | 
|                 perPage={DEFAULT_PAGE_SIZE} | 
|                 aside={<LocListAside />} | 
|             > | 
|                 <StyledDatagrid | 
|                     preferenceKey='loc' | 
|                     align="left" | 
|                     bulkActionButtons={ | 
|                         <> | 
|                             <BatchWateButton /> | 
|                             <BatchAreasButton /> | 
|                             <BatchLocTypeButton /> | 
|                             <BatchStatusButton /> | 
|                             <BindButton /> | 
|                             <SubzoneButton /> | 
|                             <BulkDeleteButton /> | 
|                         </> | 
|                     } | 
|                     rowClick={() => false} | 
|                     omit={['id', 'createTime', 'createBy', 'memo', 'updateTime', 'updateBy', 'length', 'width', 'height', 'statusBool', 'updateBy$', 'createBy$']} | 
|                 > | 
|                     <NumberField source="id" /> | 
|                     <TextField source="code" label="table.field.loc.code" /> | 
|                     <NumberField source="warehouseId$" label="table.field.loc.warehouseId" /> | 
|                     <NumberField source="areaId$" label="table.field.loc.areaId" /> | 
|                     <TextField source="typeIds$" label="table.field.loc.type" cellClassName="type" /> | 
|                     {/* <TextField source="name" label="table.field.loc.name" /> */} | 
|                     {/* <NumberField source="flagLogic" label="table.field.loc.flagLogic" /> | 
|                     <TextField source="fucAtrrs" label="table.field.loc.fucAtrrs" /> | 
|                     */} | 
|                     {/* <TextField source="unit" label="table.field.loc.unit" /> */} | 
|                     <TextField source="barcode" label="table.field.loc.barcode" /> | 
|                     <TextField source="length" label="table.field.loc.length" /> | 
|                     <TextField source="width" label="table.field.loc.width" /> | 
|                     <TextField source="height" label="table.field.loc.height" /> | 
|                     <NumberField source="row" label="table.field.loc.row" /> | 
|                     <NumberField source="col" label="table.field.loc.col" /> | 
|                     <NumberField source="lev" label="table.field.loc.lev" /> | 
|                     <NumberField source="channel" label="table.field.loc.channel" /> | 
|                     {/* <NumberField source="channel" label="table.field.loc.channel" /> | 
|                     <NumberField source="maxParts" label="table.field.loc.maxParts" /> | 
|                     <NumberField source="maxPack" label="table.field.loc.maxPack" /> | 
|                     <NumberField source="flagLabelMange" label="table.field.loc.flagLabelMange" /> | 
|                     <TextField source="locAttrs" label="table.field.loc.locAttrs" /> */} | 
|                     <TextField source="useStatus$" label="table.field.loc.useStatus" /> | 
|                     <TextField source="updateBy$" label="common.field.updateBy" /> | 
|                     <DateField source="updateTime" label="common.field.updateTime" showTime align="left" /> | 
|                     <TextField source="createBy$" label="common.field.createBy" /> | 
|                     <DateField source="createTime" label="common.field.createTime" showTime align="left" /> | 
|                     <BooleanField source="statusBool" label="common.field.status" sortable={false} align="left" /> | 
|                     <TextField source="memo" label="common.field.memo" sortable={false} /> | 
|                     <WrapperField cellClassName="opt" label="common.field.opt"> | 
|                         <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} /> | 
|                         {/* <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} /> */} | 
|                         <EnableButton /> | 
|                     </WrapperField> | 
|   | 
|                 </StyledDatagrid> | 
|                 <InitModal | 
|                     open={initDialog} | 
|                     setOpen={setInitDialog} | 
|                 /> | 
|             </List> | 
|             <LocCreate | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|             /> | 
|             <PageDrawer | 
|                 title='Loc Detail' | 
|                 drawerVal={drawerVal} | 
|                 setDrawerVal={setDrawerVal} | 
|             > | 
|             </PageDrawer> | 
|   | 
|   | 
|         </Box> | 
|     ) | 
| } | 
|   | 
| export default LocList; | 
|   | 
| const EnableButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|     const enable = async () => { | 
|         const res = await request.post('/loc/update', { | 
|             ...record, | 
|             status: +!record.status | 
|         }); | 
|         if (res?.data?.code === 200) { | 
|             refresh() | 
|         } else { | 
|             notify(res.data.msg); | 
|         } | 
|     } | 
|     return ( | 
|         record.status === 1 ? | 
|             (<Button onClick={enable} label={"toolbar.unenable"}> | 
|                 <DashboardIcon /> | 
|             </Button>) : (<Button onClick={enable} label={"toolbar.enable"}> | 
|                 <DashboardIcon /> | 
|             </Button>) | 
|   | 
|     ) | 
| } | 
|   | 
| const BatchWateButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.batchWarehouse"}> | 
|                 <EditIcon /> | 
|             </Button> | 
|   | 
|             <BatchModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|                 fieldType={'warehouseId'} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } | 
|   | 
| const BatchAreasButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.batchWarehouseAreas"}> | 
|                 <EditIcon /> | 
|             </Button> | 
|   | 
|             <BatchModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|                 fieldType={'areaId'} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } | 
|   | 
| const BatchLocTypeButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.batchLocType"}> | 
|                 <EditIcon /> | 
|             </Button> | 
|   | 
|             <BatchModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|                 fieldType={'typeIds'} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } | 
|   | 
| const BatchStatusButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.batchStatus"}> | 
|                 <EditIcon /> | 
|             </Button> | 
|   | 
|             <BatchModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|                 fieldType={'status'} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } | 
|   | 
| const SubzoneButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.subzone"}> | 
|                 <DiscountIcon /> | 
|             </Button> | 
|   | 
|             <SubzoneModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } | 
|   | 
| const BindButton = () => { | 
|     const record = useRecordContext(); | 
|     const notify = useNotify(); | 
|     const refresh = useRefresh(); | 
|   | 
|   | 
|     const [createDialog, setCreateDialog] = useState(false); | 
|   | 
|     return ( | 
|         <> | 
|             <Button onClick={() => setCreateDialog(true)} label={"toolbar.bindmatnr"}> | 
|                 <LinkIcon /> | 
|             </Button> | 
|   | 
|             <BindModal | 
|                 open={createDialog} | 
|                 setOpen={setCreateDialog} | 
|             /> | 
|         </> | 
|   | 
|     ) | 
| } |