| | |
| | | const AsnOrderModal = (props) => { |
| | | const { open, setOpen, asnId } = props; |
| | | |
| | | |
| | | |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | |
| | | }; |
| | | |
| | | 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() |
| | | } |
| | | } |
| | | |
| | |
| | | name="type" |
| | | value={formData.type} |
| | | onChange={handleChange} |
| | | onBlur={requestSetHead} |
| | | variant="outlined" |
| | | size="small" |
| | | validate={required()} |
| | | required |
| | | /> |
| | | </Grid> |
| | | |
| | |
| | | </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; |
| | | }; |
| | | |