| import { | 
|   List, | 
|   DatagridConfigurable, | 
|   SearchInput, | 
|   TopToolbar, | 
|   SelectColumnsButton, | 
|   EditButton, | 
|   FilterButton, | 
|   useDataProvider, | 
|   WrapperField, | 
|   useRecordContext, | 
|   useTranslate, | 
|   useNotify, | 
|   useRefresh, | 
|   useListContext, | 
|   TextField, | 
|   NumberField, | 
|   DateField, | 
|   BooleanField, | 
|   ReferenceField, | 
|   TextInput, | 
|   DateTimeInput, | 
|   DateInput, | 
|   SelectInput, | 
|   NumberInput, | 
|   ReferenceInput, | 
|   ReferenceArrayInput, | 
|   AutocompleteInput, | 
|   DeleteButton, | 
|   Button, | 
|   useRedirect, | 
|   useUnselectAll, | 
| } from 'react-admin'; | 
|   | 
| import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; | 
| import CreateNewFolderOutlinedIcon from '@mui/icons-material/CreateNewFolderOutlined'; | 
| import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; | 
| import PrintOutlinedIcon from '@mui/icons-material/PrintOutlined'; | 
| import DictionarySelect from "../../components/DictionarySelect"; | 
| import ConstructionIcon from "@mui/icons-material/Construction"; | 
| import BillStatusField from '../../components/BillStatusField'; | 
| import MyExportButton from '../../components/MyExportButton'; | 
| import { Box, Typography, Card, Stack } from '@mui/material'; | 
| import MyCreateButton from "../../components/MyCreateButton"; | 
| import { useLocation, useNavigate } from 'react-router-dom'; | 
| import ConfirmButton from '../../components/ConfirmButton'; | 
| import ExitToAppIcon from '@mui/icons-material/ExitToApp'; | 
| import ImportButton from "../../components/ImportButton"; | 
| import AsnCreateByPoModal from "./AsnCreateByPoModal"; | 
| import PageDrawer from "../../components/PageDrawer"; | 
| import OrderPrintPreview from "./OrderPrintPreview"; | 
| import CloseIcon from '@mui/icons-material/Close'; | 
| import EditIcon from '@mui/icons-material/Edit'; | 
| import TaskIcon from '@mui/icons-material/Task'; | 
| import { styled } from '@mui/material/styles'; | 
| import AsnOrderModal from "./AsnOrderModal"; | 
| import request from '@/utils/request'; | 
|   | 
| const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|   '& .css-1vooibu-MuiSvgIcon-root': { | 
|     height: '.9em' | 
|   }, | 
|   '& .RaDatagrid-row': { | 
|     cursor: 'auto' | 
|   }, | 
|   '& .column-name': { | 
|   }, | 
|   | 
|   '& .wkType': { | 
|     width: 110 | 
|   }, | 
|   '& .status': { | 
|     width: 90 | 
|   }, | 
|   '& .MuiTableCell-root': { | 
|     whiteSpace: 'nowrap', | 
|     overflow: 'visible', | 
|     textOverflow: 'unset' | 
|   }, | 
|   '& .opt': { | 
|     width: 220, | 
|   }, | 
| })); | 
|   | 
| const filters = [ | 
|   <SearchInput source="condition" alwaysOn />, | 
|   <TextInput source="code" label="table.field.asnOrder.code" />, | 
|   <TextInput source="poCode" label="table.field.asnOrder.poCode" />, | 
|   <NumberInput source="poId" label="table.field.asnOrder.poId" />, | 
|   <TextInput source="type" label="table.field.asnOrder.type" />, | 
|   <ReferenceInput source="wkType" reference="dictData" filter={{ dictTypeCode: 'sys_business_type', group: "1" }} label="table.field.asnOrder.wkType" alwaysOn> | 
|     <AutocompleteInput label="table.field.asnOrder.wkType" optionValue="value" /> | 
|   </ReferenceInput>, | 
|   <NumberInput source="anfme" label="table.field.asnOrder.anfme" />, | 
|   <NumberInput source="qty" label="table.field.asnOrder.qty" />, | 
|   <TextInput source="logisNo" label="table.field.asnOrder.logisNo" />, | 
|   <DateInput source="arrTime" label="table.field.asnOrder.arrTime" />, | 
|   <TextInput label="common.field.memo" source="memo" />, | 
|   <DictionarySelect | 
|     label='table.field.asnOrder.exceStatus' | 
|     name="exceStatus" | 
|     group="1" | 
|     dictTypeCode="sys_asn_exce_status" | 
|     alwaysOn | 
|   />, | 
| ] | 
|   | 
| const AsnOrderList = (props) => { | 
|   const translate = useTranslate(); | 
|   const [createDialog, setCreateDialog] = useState(false); | 
|   const [drawerVal, setDrawerVal] = useState(false); | 
|   const [modalType, setmodalType] = useState(0); | 
|   const [poCreate, setPoCreate] = useState(false); | 
|   const [printOrder, setPrintOrder] = useState(false); | 
|   const [select, setSelect] = useState({}); | 
|   const invoiceRef = useRef(); | 
|   const billReload = useRef(); | 
|   const notify = useNotify(); | 
|   const refresh = useRefresh(); | 
|   const dicts = JSON.parse(localStorage.getItem('sys_dicts'))?.filter(dict => (dict.dictTypeCode == 'sys_business_type')) || []; | 
|   return ( | 
|     <Box display="flex"> | 
|       <List | 
|         resource="asnOrder" | 
|         sx={{ | 
|           flexGrow: 1, | 
|           transition: (theme) => | 
|             theme.transitions.create(['all'], { | 
|               duration: theme.transitions.duration.enteringScreen, | 
|             }), | 
|           marginRight: drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0, | 
|         }} | 
|         title={"menu.asnOrder"} | 
|         empty={false} | 
|         filters={filters} | 
|         filter={{ deleted: 0, type: 'in' }} | 
|         sort={{ field: "create_time", order: "desc" }} | 
|         actions={( | 
|           <TopToolbar> | 
|             <FilterButton /> | 
|             <MyCreateButton onClick={() => { setCreateDialog(true); setmodalType(0) }} /> | 
|             <CreateByPoButton setPoCreate={setPoCreate} /> | 
|             <SelectColumnsButton preferenceKey='asnOrder' /> | 
|             <ImportButton value={'asnOrderItem'} /> | 
|             <MyExportButton /> | 
|           </TopToolbar> | 
|         )} | 
|         perPage={DEFAULT_PAGE_SIZE} | 
|       > | 
|         <StyledDatagrid | 
|           sx={{ width: '100%' }} | 
|           preferenceKey='asnOrder' | 
|           bulkActionButtons={ | 
|             <> | 
|               <InspectionsButton /> | 
|               <MyExportButton /> | 
|               {/* <BtnBulkExport></BtnBulkExport> */} | 
|             </>} | 
|           rowClick={false} | 
|           expandSingle={true} | 
|           omit={['id', 'createTime', 'createBy', 'memo', 'logisNo', 'poId', 'rleStatus$', 'createBy$']} | 
|         > | 
|           <NumberField source="id" /> | 
|           <TextField source="code" label="table.field.asnOrder.code" /> | 
|           <TextField source="poCode" label="table.field.asnOrder.poCode" /> | 
|           <NumberField source="poId" label="table.field.asnOrder.poId" /> | 
|           <TextField source="type$" label="table.field.asnOrder.type" /> | 
|           <TextField cellClassName="wkType" source="wkType$" label="table.field.asnOrder.wkType" /> | 
|           <NumberField source="anfme" label="table.field.asnOrder.anfme" /> | 
|           <NumberField source="qty" label="table.field.asnOrder.qty" /> | 
|           <DateField source="arrTime" label="table.field.asnOrder.arrTime" showTime /> | 
|           <TextField source="rleStatus$" label="table.field.asnOrder.rleStatus" sortable={false} /> | 
|           <TextField source="logisNo" label="table.field.asnOrder.logisNo" /> | 
|           <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 /> | 
|           <BillStatusField cellClassName="status" source="exceStatus" label="table.field.asnOrder.exceStatus" /> | 
|           <TextField source="memo" label="common.field.memo" sortable={false} /> | 
|           <WrapperField cellClassName="opt" label="common.field.opt" > | 
|             <EditButton label="toolbar.detail"></EditButton> | 
|             <MyButton setCreateDialog={setCreateDialog} setmodalType={setmodalType} /> | 
|             <InspectionButton /> | 
|             <CompleteButton /> | 
|             <ODeleteButton /> | 
|             <PrintButton setPrintOrder={setPrintOrder} setSelect={setSelect} /> | 
|             {/* <CloseButton /> */} | 
|           </WrapperField> | 
|         </StyledDatagrid> | 
|       </List> | 
|       <AsnOrderModal | 
|         open={createDialog} | 
|         setOpen={setCreateDialog} | 
|         asnId={modalType} | 
|         billReload={billReload} | 
|       /> | 
|       <OrderPrintPreview | 
|         open={printOrder} | 
|         setOpen={setPrintOrder} | 
|         record={select} | 
|       /> | 
|       <AsnCreateByPoModal | 
|         open={poCreate} | 
|         setOpen={setPoCreate} | 
|       /> | 
|       <PageDrawer | 
|         title='AsnOrder Detail' | 
|         drawerVal={drawerVal} | 
|         setDrawerVal={setDrawerVal} | 
|       > | 
|       </PageDrawer> | 
|     </Box > | 
|   ) | 
| } | 
| export default AsnOrderList; | 
|   | 
| //按PO单新建 | 
| const CreateByPoButton = ({ setPoCreate }) => { | 
|   const record = useRecordContext(); | 
|   | 
|   const createEvent = (event) => { | 
|     event.stopPropagation(); | 
|     setPoCreate(true) | 
|   } | 
|   return ( | 
|     <Button label={"toolbar.poCreate"} onClick={createEvent}> | 
|       <CreateNewFolderOutlinedIcon /> | 
|     </Button> | 
|   ) | 
| } | 
|   | 
|   | 
| //打印按钮 | 
| const PrintButton = ({ setPrintOrder, setSelect }) => { | 
|   const record = useRecordContext(); | 
|   const printOrder = (event) => { | 
|     event.stopPropagation(); | 
|     setPrintOrder(true) | 
|     setSelect(record) | 
|   } | 
|   | 
|   return ( | 
|     <Button label={"toolbar.print"} onClick={printOrder}> | 
|       <PrintOutlinedIcon /> | 
|     </Button> | 
|   ) | 
| } | 
|   | 
|   | 
| const ODeleteButton = () => { | 
|   const record = useRecordContext(); | 
|   return ( | 
|     record.exceStatus === 0 ? <DeleteButton mutationMode="pessimistic" /> : <></> | 
|   ) | 
|   | 
| } | 
|   | 
| const MyButton = ({ setCreateDialog, setmodalType }) => { | 
|   const record = useRecordContext(); | 
|   const handleEditClick = (btn) => { | 
|     btn.stopPropagation(); | 
|     const id = record.id; | 
|     setmodalType(id); | 
|     setCreateDialog(true); | 
|   | 
|   }; | 
|   return ( | 
|     record.exceStatus === 1 || record.exceStatus === 0 ? | 
|       <Button | 
|         color="primary" | 
|         startIcon={<EditIcon />} | 
|         onClick={(btn) => handleEditClick(btn)} | 
|         sx={{ ml: 1 }} | 
|         label={'ra.action.edit'} | 
|       > | 
|       </Button> | 
|       : <></> | 
|   ) | 
| } | 
|   | 
| //报检 | 
| const InspectionButton = () => { | 
|   const record = useRecordContext(); | 
|   const notify = useNotify(); | 
|   const refresh = useRefresh(); | 
|   const inspection = (btn) => { | 
|     btn.stopPropagation(); | 
|     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 ( | 
|     <ConfirmButton label={"toolbar.inspection"} color="secondary" startIcon={<ConstructionIcon />} onConfirm={inspection} /> | 
|   ) | 
| } | 
|   | 
| const InspectionsButton = () => { | 
|   const { selectedIds, onUnselectItems, data } = useListContext(); | 
|   const notify = useNotify(); | 
|   const refresh = useRefresh(); | 
|   const translate = useTranslate(); | 
|   const inspection = (btn) => { | 
|     btn.stopPropagation(); | 
|     if (selectedIds.length === 0) { | 
|       notify(translate("request.error.select_error_order")); | 
|       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> | 
|   ) | 
| } | 
|   | 
| const BtnBulkExport = () => { | 
|   const { filter, selectedIds, filterValues, resource, sort, total } = useListContext(); | 
|   const unSelect = useUnselectAll(resource); | 
|   const dataProvider = useDataProvider(); | 
|   const refresh = useRefresh(); | 
|   const notify = useNotify(); | 
|   | 
|   const bulkExport = () => { | 
|     getExport() | 
|     unSelect(); | 
|   } | 
|   | 
|   const getExport = () => { | 
|     dataProvider | 
|       .export(resource, { | 
|         ids: selectedIds, | 
|         pagination: { page: 1, perPage: 1000 }, | 
|       }) | 
|       .then((res) => { | 
|         const url = window.URL.createObjectURL( | 
|           new Blob([res.data], { type: res.headers["content-type"] }), | 
|         ); | 
|         const link = document.createElement("a"); | 
|         link.href = url; | 
|         link.setAttribute("download", `${resource}.xlsx`); | 
|         document.body.appendChild(link); | 
|         link.click(); | 
|         link.remove(); | 
|       }) | 
|       .catch((error) => { | 
|         console.error(error); | 
|         notify("ra.notification.http_error", { type: "error" }); | 
|       }); | 
|     if (typeof onClick === "function") { | 
|       onClick(event); | 
|     } | 
|   }; | 
|   | 
|   return ( | 
|     <> | 
|       <Button label="toolbar.bulkExport" onClick={bulkExport}> | 
|         <ExitToAppIcon /> | 
|       </Button> | 
|     </> | 
|   ) | 
| } | 
|   | 
| //完成单据 | 
| const CompleteButton = () => { | 
|   const record = useRecordContext(); | 
|   const notify = useNotify(); | 
|   const refresh = useRefresh(); | 
|   const requestComplete = async () => { | 
|     const { data: { code, data, msg } } = await request.post(`/asnOrder/complete/${record.id}`); | 
|   | 
|     if (code === 200) { | 
|       notify(msg); | 
|       refresh() | 
|     } else { | 
|       notify(msg); | 
|     } | 
|   } | 
|   | 
|   return ( | 
|     // record.exceStatus === 1 && (record.anfme === record.qty ? <Button onClick={requestComplete} label={"toolbar.complete"} color="secondary"> | 
|     //   <TaskIcon /> | 
|     // </Button> : ) | 
|     record.exceStatus === 1 ? <ConfirmButton label={"toolbar.complete"} color="secondary" startIcon={<TaskIcon />} onConfirm={requestComplete} /> : <></> | 
|   ) | 
|   | 
|   | 
| } | 
|   | 
| const CloseButton = () => { | 
|   const record = useRecordContext(); | 
|   const notify = useNotify(); | 
|   const refresh = useRefresh(); | 
|   const requestClose = async () => { | 
|     const { data: { code, data, msg } } = await request.post(`/asnOrder/close/${record.id}`); | 
|   | 
|     if (code === 200) { | 
|       notify(msg); | 
|       refresh() | 
|     } else { | 
|       notify(msg); | 
|     } | 
|   } | 
|   | 
|   return ( | 
|     <ConfirmButton label={"toolbar.close"} color="error" startIcon={<CloseIcon />} onConfirm={requestClose} /> | 
|   ) | 
| } |