|  |  |  | 
|---|
|  |  |  | import { display, height, width } from "@mui/system"; | 
|---|
|  |  |  | import DashboardIcon from '@mui/icons-material/Dashboard'; | 
|---|
|  |  |  | import EditIcon from '@mui/icons-material/Edit'; | 
|---|
|  |  |  | import PrintIcon from '@mui/icons-material/Print'; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  | import BatchModal from './BatchModal'; | 
|---|
|  |  |  | import PrintModal from './PrintModal'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|---|
|  |  |  | '& .css-1vooibu-MuiSvgIcon-root': { | 
|---|
|  |  |  | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const { isLoading } = useListContext(); | 
|---|
|  |  |  | const [dynamicFields, setDynamicFields] = useState([]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const [columns, setColumns] = useState([]); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const { refetch } = useListContext(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | data: { code, data, msg }, | 
|---|
|  |  |  | } = await request.get("/fields/enable/list"); | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | setDynamicFields(data); | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | const arr = [ | 
|---|
|  |  |  | <NumberField key="id" source="id" />, | 
|---|
|  |  |  | <TooltipField key="name" source="name" label="table.field.matnr.name" cellClassName="name" />, | 
|---|
|  |  |  | <TextField key="code" source="code" label="table.field.matnr.code" />, | 
|---|
|  |  |  | <TextField key="shipperId$" source="shipperId$" label="table.field.matnr.shipperId" />, | 
|---|
|  |  |  | <ReferenceField key="groupId" source="groupId" label="table.field.matnr.groupId" reference="matnrGroup" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="name" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <TextField key="platCode" source="platCode" label="table.field.matnr.platCode" />, | 
|---|
|  |  |  | <TextField key="spec" source="spec" label="table.field.matnr.spec" />, | 
|---|
|  |  |  | <TextField key="model" source="model" label="table.field.matnr.model" />, | 
|---|
|  |  |  | <NumberField key="weight" source="weight" label="table.field.matnr.weight" />, | 
|---|
|  |  |  | <TextField key="describle" source="describle" label="table.field.matnr.describle" />, | 
|---|
|  |  |  | <NumberField key="nromNum" source="nromNum" label="table.field.matnr.nromNum" />, | 
|---|
|  |  |  | <TextField key="unit" source="unit" label="table.field.matnr.unit" />, | 
|---|
|  |  |  | <TextField key="purchaseUnit" source="purchaseUnit" label="table.field.matnr.purUnit" />, | 
|---|
|  |  |  | <TextField key="stockUnit" source="stockUnit" label="table.field.matnr.stockUnit" />, | 
|---|
|  |  |  | <TextField key="stockLeval$" source="stockLeval$" label="table.field.matnr.stockLevel" sortable={false} />, | 
|---|
|  |  |  | <TextField key="flagLabelMange$" source="flagLabelMange$" label="table.field.matnr.isLabelMange" sortable={false} />, | 
|---|
|  |  |  | <NumberField key="safeQty" source="safeQty" label="table.field.matnr.safeQty" />, | 
|---|
|  |  |  | <NumberField key="minQty" source="minQty" label="table.field.matnr.minQty" />, | 
|---|
|  |  |  | <NumberField key="maxQty" source="maxQty" label="table.field.matnr.maxQty" />, | 
|---|
|  |  |  | <NumberField key="stagn" source="stagn" label="table.field.matnr.stagn" />, | 
|---|
|  |  |  | <NumberField key="valid" source="valid" label="table.field.matnr.valid" />, | 
|---|
|  |  |  | <NumberField key="validWarn" source="validWarn" label="table.field.matnr.validWarn" />, | 
|---|
|  |  |  | <NumberField key="flagCheck" source="flagCheck" label="table.field.matnr.flagCheck" />, | 
|---|
|  |  |  | <ReferenceField key="updateBy" source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="nickname" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <DateField key="updateTime" source="updateTime" label="common.field.updateTime" showTime />, | 
|---|
|  |  |  | <ReferenceField key="createBy" source="createBy" label="common.field.createBy" reference="user" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="nickname" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <DateField key="createTime" source="createTime" label="common.field.createTime" showTime />, | 
|---|
|  |  |  | <BooleanField key="statusBool" source="statusBool" label="common.field.status" sortable={false} />, | 
|---|
|  |  |  | <TextField key="memo" source="memo" label="common.field.memo" sortable={false} />, | 
|---|
|  |  |  | ] | 
|---|
|  |  |  | const fields = data.map(el => <TextField key={el.fields} source={`extendFields.[${el.fields}]`} label={el.fieldsAlise} />) | 
|---|
|  |  |  | const opt = <WrapperField key="opt" cellClassName="opt" label="common.field.opt"> | 
|---|
|  |  |  | <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} /> | 
|---|
|  |  |  | <EnableButton /> | 
|---|
|  |  |  | </WrapperField> | 
|---|
|  |  |  | setColumns([...arr, ...fields, opt]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | notify('请求出错'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const columns = [ | 
|---|
|  |  |  | <NumberField key="id" source="id" />, | 
|---|
|  |  |  | <TooltipField key="name" source="name" label="table.field.matnr.name" cellClassName="name" />, | 
|---|
|  |  |  | <TextField key="code" source="code" label="table.field.matnr.code" />, | 
|---|
|  |  |  | <TextField key="shipperId$" source="shipperId$" label="table.field.matnr.shipperId" />, | 
|---|
|  |  |  | <ReferenceField key="groupId" source="groupId" label="table.field.matnr.groupId" reference="matnrGroup" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="name" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <TextField key="platCode" source="platCode" label="table.field.matnr.platCode" />, | 
|---|
|  |  |  | <TextField key="spec" source="spec" label="table.field.matnr.spec" />, | 
|---|
|  |  |  | <TextField key="model" source="model" label="table.field.matnr.model" />, | 
|---|
|  |  |  | <NumberField key="weight" source="weight" label="table.field.matnr.weight" />, | 
|---|
|  |  |  | <TextField key="describle" source="describle" label="table.field.matnr.describle" />, | 
|---|
|  |  |  | <NumberField key="nromNum" source="nromNum" label="table.field.matnr.nromNum" />, | 
|---|
|  |  |  | <TextField key="unit" source="unit" label="table.field.matnr.unit" />, | 
|---|
|  |  |  | <TextField key="purchaseUnit" source="purchaseUnit" label="table.field.matnr.purUnit" />, | 
|---|
|  |  |  | <TextField key="stockUnit" source="stockUnit" label="table.field.matnr.stockUnit" />, | 
|---|
|  |  |  | <TextField key="stockLeval$" source="stockLeval$" label="table.field.matnr.stockLevel" sortable={false} />, | 
|---|
|  |  |  | <TextField key="isLabelMange$" source="isLabelMange$" label="table.field.matnr.isLabelMange" sortable={false} />, | 
|---|
|  |  |  | <NumberField key="safeQty" source="safeQty" label="table.field.matnr.safeQty" />, | 
|---|
|  |  |  | <NumberField key="minQty" source="minQty" label="table.field.matnr.minQty" />, | 
|---|
|  |  |  | <NumberField key="maxQty" source="maxQty" label="table.field.matnr.maxQty" />, | 
|---|
|  |  |  | <NumberField key="stagn" source="stagn" label="table.field.matnr.stagn" />, | 
|---|
|  |  |  | <NumberField key="valid" source="valid" label="table.field.matnr.valid" />, | 
|---|
|  |  |  | <NumberField key="validWarn" source="validWarn" label="table.field.matnr.validWarn" />, | 
|---|
|  |  |  | <NumberField key="flagCheck" source="flagCheck" label="table.field.matnr.flagCheck" />, | 
|---|
|  |  |  | <ReferenceField key="updateBy" source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="nickname" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <DateField key="updateTime" source="updateTime" label="common.field.updateTime" showTime />, | 
|---|
|  |  |  | <ReferenceField key="createBy" source="createBy" label="common.field.createBy" reference="user" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="nickname" /> | 
|---|
|  |  |  | </ReferenceField>, | 
|---|
|  |  |  | <DateField key="createTime" source="createTime" label="common.field.createTime" showTime />, | 
|---|
|  |  |  | <BooleanField key="statusBool" source="statusBool" label="common.field.status" sortable={false} />, | 
|---|
|  |  |  | <TextField key="memo" source="memo" label="common.field.memo" sortable={false} />, | 
|---|
|  |  |  | <WrapperField key="opt" cellClassName="opt" label="common.field.opt"> | 
|---|
|  |  |  | <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} /> | 
|---|
|  |  |  | <EnableButton /> | 
|---|
|  |  |  | </WrapperField> | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box sx={{ position: 'relative', minHeight: "60vh", }}> | 
|---|
|  |  |  | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='matnr' | 
|---|
|  |  |  | bulkActionButtons={<> <BatchButton /><BulkDeleteButton mutationMode={OPERATE_MODE} /></>} | 
|---|
|  |  |  | rowClick={(id, resource, record) => false} | 
|---|
|  |  |  | omit={['id', 'shipperId', 'platCode', 'spec', 'model', 'weight', 'color', 'describle' | 
|---|
|  |  |  | , 'nromNum', 'unit', 'purchaseUnit', 'stockUnit', 'stockLeval', 'isLabelMange', 'safeQty' | 
|---|
|  |  |  | , 'minQty', 'maxQty', 'stagn', 'valid', 'validWarn', 'flagCheck', 'updateTime', 'updateBy' | 
|---|
|  |  |  | , 'createTime', 'createBy', 'memo', 'rglarId', 'groupId', 'stockLevel', 'isLabelMange']} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {columns.map((column) => column)} | 
|---|
|  |  |  | </StyledDatagrid> | 
|---|
|  |  |  | {columns.length > 0 && | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='matnr' | 
|---|
|  |  |  | bulkActionButtons={<> | 
|---|
|  |  |  | <BatchButton /> | 
|---|
|  |  |  | <PrintButton /> | 
|---|
|  |  |  | <BulkDeleteButton mutationMode={OPERATE_MODE} /> | 
|---|
|  |  |  | </>} | 
|---|
|  |  |  | rowClick={(id, resource, record) => false} | 
|---|
|  |  |  | omit={['id', 'shipperId', 'platCode', 'spec', 'model', 'weight', 'color', 'describle' | 
|---|
|  |  |  | , 'nromNum', 'unit', 'purchaseUnit', 'stockUnit', 'stockLeval', 'isLabelMange', 'safeQty' | 
|---|
|  |  |  | , 'minQty', 'maxQty', 'stagn', 'valid', 'validWarn', 'flagCheck', 'updateTime', 'updateBy' | 
|---|
|  |  |  | , 'createTime', 'createBy', 'memo', 'rglarId', 'groupId', 'stockLevel']} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {columns.map((column) => column)} | 
|---|
|  |  |  | </StyledDatagrid>} | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | </> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const PrintButton = () => { | 
|---|
|  |  |  | const record = useRecordContext(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const [createDialog, setCreateDialog] = useState(false); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <Button color="secondary" onClick={() => setCreateDialog(true)} label={"toolbar.print"}> | 
|---|
|  |  |  | <PrintIcon /> | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <PrintModal | 
|---|
|  |  |  | open={createDialog} | 
|---|
|  |  |  | setOpen={setCreateDialog} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|