|  |  | 
 |  |  | import { Add, Edit, Delete } from '@mui/icons-material'; | 
 |  |  | import _ from 'lodash'; | 
 |  |  | import { DataGrid } from '@mui/x-data-grid'; | 
 |  |  | import DictionarySelect from "../components/DictionarySelect"; | 
 |  |  |  | 
 |  |  | const AsnOrderModal = (props) => { | 
 |  |  |     const { open, setOpen, asnId } = props; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     const translate = useTranslate(); | 
 |  |  |     const notify = useNotify(); | 
 |  |  | 
 |  |  |  | 
 |  |  |     const [tabelData, setTableData] = useState([]); | 
 |  |  |  | 
 |  |  |     const handleChange = (e) => { | 
 |  |  |         const { name, value } = e.target; | 
 |  |  |  | 
 |  |  |     const handleChange = (value, name) => { | 
 |  |  |         setFormData((prevData) => ({ | 
 |  |  |             ...prevData, | 
 |  |  |             [name]: value | 
 |  |  | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     const handleSubmit = async () => { | 
 |  |  |         const parmas = { | 
 |  |  |             "orders": formData, | 
 |  |  |             "items": tabelData, | 
 |  |  |         } | 
 |  |  |         const res = await request.post(`/asnOrder/items/save`, parmas); | 
 |  |  |         if (res?.data?.code === 200) { | 
 |  |  |             setOpen(false); | 
 |  |  |         if (asnId === 0) { | 
 |  |  |             const parmas = { | 
 |  |  |                 "orders": formData, | 
 |  |  |                 "items": tabelData, | 
 |  |  |             } | 
 |  |  |             const res = await request.post(`/asnOrder/items/save`, parmas); | 
 |  |  |             if (res?.data?.code === 200) { | 
 |  |  |                 setOpen(false); | 
 |  |  |                 refresh(); | 
 |  |  |             } else { | 
 |  |  |                 notify(res.data.msg); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             notify(res.data.msg); | 
 |  |  |             setOpen(false); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |         } else { | 
 |  |  |             notify(res.data.msg); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     const requestGetBody = async () => { | 
 |  |  | 
 |  |  |             setTableData(res.data.data.records) | 
 |  |  |         } else { | 
 |  |  |             notify(res.data.msg); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     const requestSetHead = async () => { | 
 |  |  |         if (asnId !== 0) { | 
 |  |  |             const res = await request.post(`/asnOrder/update`, { ...formData }); | 
 |  |  |             refresh() | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                     </Box> | 
 |  |  |                 </DialogTitle> | 
 |  |  |                 <DialogContent sx={{ mt: 2 }}> | 
 |  |  |                     <Box component="form" sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> | 
 |  |  |                         <form> | 
 |  |  |                     <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> | 
 |  |  |                         <Form> | 
 |  |  |                             <Grid container spacing={2}> | 
 |  |  |                                 <Grid item xs={4}> | 
 |  |  |                                     <TextField | 
 |  |  |                                         label={translate('table.field.asnOrder.type')} | 
 |  |  |                                     <DictionarySelect | 
 |  |  |                                         label={translate("table.field.asnOrder.type")} | 
 |  |  |                                         name="type" | 
 |  |  |                                         value={formData.type} | 
 |  |  |                                         onChange={handleChange} | 
 |  |  |                                         variant="outlined" | 
 |  |  |                                         onChange={(e) => handleChange(+e.target.value, 'type')} | 
 |  |  |                                         size="small" | 
 |  |  |                                         validate={required()} | 
 |  |  |                                         dictTypeCode="sys_bill_type" | 
 |  |  |                                     /> | 
 |  |  |  | 
 |  |  |                                 </Grid> | 
 |  |  |  | 
 |  |  |                                 {/* <Grid item xs={4}> | 
 |  |  | 
 |  |  |                                 /> | 
 |  |  |                             </Grid> */} | 
 |  |  |                             </Grid> | 
 |  |  |                         </form> | 
 |  |  |                         </Form> | 
 |  |  |                     </Box> | 
 |  |  |  | 
 |  |  |                     <Box sx={{ mt: 2 }}> | 
 |  |  | 
 |  |  |                     </Box> | 
 |  |  |  | 
 |  |  |                     <Box sx={{ mt: 2 }}> | 
 |  |  |                         <AsnOrderModalTable tabelData={tabelData} setTableData={setTableData} ></AsnOrderModalTable> | 
 |  |  |                         <AsnOrderModalTable tabelData={tabelData} setTableData={setTableData} asnId={asnId} ></AsnOrderModalTable> | 
 |  |  |                     </Box> | 
 |  |  |                 </DialogContent> | 
 |  |  |                 <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> | 
 |  |  | 
 |  |  |  | 
 |  |  | export default AsnOrderModal; | 
 |  |  |  | 
 |  |  | const AsnOrderModalTable = ({ tabelData, setTableData }) => { | 
 |  |  | const AsnOrderModalTable = ({ tabelData, setTableData, asnId }) => { | 
 |  |  |     const translate = useTranslate(); | 
 |  |  |  | 
 |  |  |     const columns = [ | 
 |  |  | 
 |  |  |             headerName: translate('table.field.asnOrderItem.matnrId'), | 
 |  |  |             minWidth: 100, | 
 |  |  |             flex: 1, | 
 |  |  |             editable: false, // 假设 matnrId 不可编辑 | 
 |  |  |             editable: false, | 
 |  |  |         }, | 
 |  |  |         { | 
 |  |  |             field: 'matnk', | 
 |  |  |             headerName: translate('table.field.asnOrderItem.matnk'), | 
 |  |  |             field: 'maktx', | 
 |  |  |             headerName: translate('table.field.asnOrderItem.maktx'), | 
 |  |  |             minWidth: 100, | 
 |  |  |             flex: 1, | 
 |  |  |             editable: true, | 
 |  |  | 
 |  |  |             headerName: translate('table.field.asnOrderItem.poDetlId'), | 
 |  |  |             minWidth: 100, | 
 |  |  |             flex: 1, | 
 |  |  |             editable: true, | 
 |  |  |         }, | 
 |  |  |         { | 
 |  |  |             field: 'poDetlCode', | 
 |  |  |             headerName: translate('table.field.asnOrderItem.poDetlCode'), | 
 |  |  |             minWidth: 100, | 
 |  |  |             flex: 1, | 
 |  |  |             editable: true, | 
 |  |  |         }, | 
 |  |  |         { | 
 |  |  |             field: 'anfme', | 
 |  |  | 
 |  |  |  | 
 |  |  |     ]; | 
 |  |  |  | 
 |  |  |     const requestSetBody = async (row) => { | 
 |  |  |         if (asnId !== 0) { | 
 |  |  |             const res = await request.post(`/asnOrderItem/update`, row); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     const handleDelete = (row) => { | 
 |  |  |         const newData = _.filter(tabelData, (item) => item.matnrId !== row.matnrId); | 
 |  |  |         setTableData(newData); | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     const handleEdit = (field, row, value) => { | 
 |  |  |         setTableData((prevData) => | 
 |  |  |             prevData.map((r) => | 
 |  |  |                 r.matnrId === row.matnrId ? { ...r, [field]: value } : r | 
 |  |  |             ) | 
 |  |  |         ); | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     const processRowUpdate = (newRow, oldRow) => { | 
 |  |  |         const field = Object.keys(newRow).find((key) => newRow[key] !== oldRow[key]); | 
 |  |  |         handleEdit(field, oldRow, newRow[field]); | 
 |  |  |         setTableData((prevData) => | 
 |  |  |             prevData.map((r) => | 
 |  |  |                 r.matnrId === newRow.matnrId ? { ...newRow } : r | 
 |  |  |             ) | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         requestSetBody(newRow) | 
 |  |  |         return newRow; | 
 |  |  |     }; | 
 |  |  |  |