|  |  |  | 
|---|
|  |  |  | useRecordContext, | 
|---|
|  |  |  | useTranslate, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | useRefresh, | 
|---|
|  |  |  | useListContext, | 
|---|
|  |  |  | FunctionField, | 
|---|
|  |  |  | TextField, | 
|---|
|  |  |  | 
|---|
|  |  |  | import ConstructionIcon from "@mui/icons-material/Construction"; | 
|---|
|  |  |  | import FileDownloadIcon from '@mui/icons-material/FileDownload'; | 
|---|
|  |  |  | import EditIcon from '@mui/icons-material/Edit'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|---|
|  |  |  | 
|---|
|  |  |  | navigate(`/asnOrderItem?asnId=${record.id}`); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const inspection = () => { }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const print = () => { | 
|---|
|  |  |  | // const imageUrls = ['https://www.baidu.com/img/flexible/logo/pc/result@2.png',] | 
|---|
|  |  |  | // const iframe = document.createElement('iframe'); | 
|---|
|  |  |  | // iframe.style.display = 'none'; | 
|---|
|  |  |  | // document.body.appendChild(iframe); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; | 
|---|
|  |  |  | // iframeDoc.open(); | 
|---|
|  |  |  | // iframeDoc.write('<html><head><title>Print Images</title></head><body>'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // // 将图片插入到 iframe 中 | 
|---|
|  |  |  | // imageUrls.forEach((imageUrl) => { | 
|---|
|  |  |  | //   iframeDoc.write(`<img src="${imageUrl}" style="margin: 10px;">`); | 
|---|
|  |  |  | // }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // iframeDoc.write('</body></html>'); | 
|---|
|  |  |  | // iframeDoc.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // // 等待图片加载完成后触发打印 | 
|---|
|  |  |  | // iframe.contentWindow.onload = () => { | 
|---|
|  |  |  | //   iframe.contentWindow.print(); | 
|---|
|  |  |  | //   // 打印完成后移除 iframe | 
|---|
|  |  |  | //   document.body.removeChild(iframe); | 
|---|
|  |  |  | // }; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box display="flex"> | 
|---|
|  |  |  | <List | 
|---|
|  |  |  | 
|---|
|  |  |  | actions={( | 
|---|
|  |  |  | <TopToolbar> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <Button onClick={inspection} label={"toolbar.inspection"}> | 
|---|
|  |  |  | <ConstructionIcon /> | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | <FilterButton /> | 
|---|
|  |  |  | <MyCreateButton onClick={() => { setCreateDialog(true); setmodalType(0) }} /> | 
|---|
|  |  |  | <SelectColumnsButton preferenceKey='asnOrder' /> | 
|---|
|  |  |  | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='asnOrder' | 
|---|
|  |  |  | bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />} | 
|---|
|  |  |  | bulkActionButtons={<> <InspectionsButton /><BulkDeleteButton mutationMode={OPERATE_MODE} /></>} | 
|---|
|  |  |  | rowClick={(id, resource, record) => false} | 
|---|
|  |  |  | expand={(e) => <AsnOrderPanel key={Math.floor(Math.random() * 100)} />} | 
|---|
|  |  |  | expandSingle={true} | 
|---|
|  |  |  | 
|---|
|  |  |  | <BooleanField source="statusBool" label="common.field.status" sortable={false} /> | 
|---|
|  |  |  | <TextField source="memo" label="common.field.memo" sortable={false} /> | 
|---|
|  |  |  | <WrapperField cellClassName="opt" label="common.field.opt" > | 
|---|
|  |  |  | <Button label="toolbar.print" onClick={print}> | 
|---|
|  |  |  | {/* <Button label="toolbar.print" onClick={print}> | 
|---|
|  |  |  | <FileDownloadIcon /> | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | </Button> */} | 
|---|
|  |  |  | {/* <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} /> */} | 
|---|
|  |  |  | <MyButton setCreateDialog={setCreateDialog} setmodalType={setmodalType} /> | 
|---|
|  |  |  | {/* <Button | 
|---|
|  |  |  | 
|---|
|  |  |  | label={'ra.action.edit'} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | </Button> */} | 
|---|
|  |  |  | <InspectionButton /> | 
|---|
|  |  |  | <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} /> | 
|---|
|  |  |  | </WrapperField> | 
|---|
|  |  |  | </StyledDatagrid> | 
|---|
|  |  |  | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const InspectionButton = () => { | 
|---|
|  |  |  | const record = useRecordContext(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const inspection = () => { | 
|---|
|  |  |  | requestInspect([record]) | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const requestInspect = async (rows) => { | 
|---|
|  |  |  | const { data: { code, data, msg } } = await request.post(`/asnOrder/inspect`, rows); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | refresh() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Button onClick={inspection} label={"toolbar.inspection"}> | 
|---|
|  |  |  | <ConstructionIcon /> | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const InspectionsButton = () => { | 
|---|
|  |  |  | const { selectedIds, onUnselectItems, data } = useListContext(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const inspection = () => { | 
|---|
|  |  |  | if (selectedIds.length === 0) { | 
|---|
|  |  |  | notify('请选择通知单'); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | const rows = data.filter((item) => selectedIds.includes(item.id)) | 
|---|
|  |  |  | requestInspect(rows) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const requestInspect = async (rows) => { | 
|---|
|  |  |  | const { data: { code, data, msg } } = await request.post(`/asnOrder/inspect`, rows); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | refresh() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Button onClick={inspection} label={"toolbar.inspection"}> | 
|---|
|  |  |  | <ConstructionIcon /> | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|