|  |  |  | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | Form, | 
|---|
|  |  |  | useCreateController, | 
|---|
|  |  |  | SimpleForm, | 
|---|
|  |  |  | useRefresh, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | Dialog, | 
|---|
|  |  |  | 
|---|
|  |  |  | Grid, | 
|---|
|  |  |  | Box, | 
|---|
|  |  |  | } from '@mui/material'; | 
|---|
|  |  |  | import DialogCloseButton from "../../components/DialogCloseButton.jsx"; | 
|---|
|  |  |  | import ConfirmationNumberIcon from '@mui/icons-material/ConfirmationNumber'; | 
|---|
|  |  |  | import CreateBySelectMats from "./CreateBySelectMats.jsx"; | 
|---|
|  |  |  | import DialogCloseButton from "../../components/DialogCloseButton.jsx"; | 
|---|
|  |  |  | import WarehouseSelect from "../../components/WarehouseSelect.jsx"; | 
|---|
|  |  |  | import { DataGrid, useGridApiRef } from '@mui/x-data-grid'; | 
|---|
|  |  |  | import { Add, Edit, Delete } from '@mui/icons-material'; | 
|---|
|  |  |  | import ConfirmButton from "../../components/ConfirmButton"; | 
|---|
|  |  |  | import { useFormContext, useWatch } from "react-hook-form"; | 
|---|
|  |  |  | import CreateBySelectMats from "./CreateBySelectMats.jsx"; | 
|---|
|  |  |  | import { Add, Edit, Delete } from '@mui/icons-material'; | 
|---|
|  |  |  | import DictSelect from "../../components/DictSelect"; | 
|---|
|  |  |  | import { minHeight, padding } from "@mui/system"; | 
|---|
|  |  |  | import SaveIcon from '@mui/icons-material/Save'; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  | import _, { set } from 'lodash'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const ManualCreate = (props) => { | 
|---|
|  |  |  | const { open, setOpen, orderId } = props; | 
|---|
|  |  |  | const tableRef = useRef(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const [tabelData, setTableData] = useState([]); | 
|---|
|  |  |  | const [disabled, setDisabled] = useState(false); | 
|---|
|  |  |  | const [selectedRows, setSelectedRows] = useState([]); | 
|---|
|  |  |  | const [createDialog, setCreateDialog] = useState(false); | 
|---|
|  |  |  | const [formData, setFormData] = useState({}); | 
|---|
|  |  |  | const [formData, setFormData] = useState({ type: '1', orgAreaId: null, tarAreaId: null }); | 
|---|
|  |  |  | const [list, setList] = useState([]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleClose = (event, reason) => { | 
|---|
|  |  |  | if (reason !== "backdropClick") { | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const setFinally = () => { | 
|---|
|  |  |  | const rows = tableRef.current.state.editRows; | 
|---|
|  |  |  | for (const key in rows) { | 
|---|
|  |  |  | const find = tabelData.find(item => item.matnrId === +key); | 
|---|
|  |  |  | find.anfme = rows[key].anfme.value; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | setTableData([...tabelData]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleSubmit = async () => { | 
|---|
|  |  |  | setFinally() | 
|---|
|  |  |  | setDisabled(true) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (asnId === 0) { | 
|---|
|  |  |  | if (orderId == null || orderId == undefined) { | 
|---|
|  |  |  | const parmas = { | 
|---|
|  |  |  | "orders": formData, | 
|---|
|  |  |  | "transfer": formData, | 
|---|
|  |  |  | "items": tabelData, | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const res = await request.post(`/outStock/items/save`, parmas); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const res = await request.post(`/transfer/items/save`, parmas); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | resetData() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | const parmas = { | 
|---|
|  |  |  | "orders": formData, | 
|---|
|  |  |  | "transfer": formData, | 
|---|
|  |  |  | "items": tabelData, | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const res = await request.post(`/outStock/items/update`, parmas); | 
|---|
|  |  |  | const res = await request.post(`/transfer/items/update`, parmas); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | resetData() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | setDisabled(false) | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const getWarehouse = async () => { | 
|---|
|  |  |  | const res = await request.post('/warehouseAreas/page'); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | setList(res.data.data.records.map((item) => { | 
|---|
|  |  |  | return { | 
|---|
|  |  |  | id: item.id, | 
|---|
|  |  |  | name: item.name | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | })); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const newAddClick = () => { | 
|---|
|  |  |  | if (formData.orgAreaId == null || formData.orgAreaId == undefined) { | 
|---|
|  |  |  | notify("原库区不能为空!!", { type: 'error' }) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (formData.tarAreaId == null || formData.tarAreaId == undefined) { | 
|---|
|  |  |  | notify("目标库区不能为空!!", { type: 'error' }) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | console.log(formData); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | setCreateDialog(true) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleChange = (value, name) => { | 
|---|
|  |  |  | setFormData((prevData) => ({ | 
|---|
|  |  |  | ...prevData, | 
|---|
|  |  |  | [name]: value | 
|---|
|  |  |  | })); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <Box sx={{ padding: 1 }}> | 
|---|
|  |  |  | <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> | 
|---|
|  |  |  | <Form defaultValues={formData}> | 
|---|
|  |  |  | <Grid container spacing={2}> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <DictSelect | 
|---|
|  |  |  | label={translate("table.field.transfer.type")} | 
|---|
|  |  |  | value={formData.wkType} | 
|---|
|  |  |  | variant="filled" | 
|---|
|  |  |  | group='2' | 
|---|
|  |  |  | onChange={(e) => handleChange(e.target.value, 'wkType')} | 
|---|
|  |  |  | dictTypeCode="sys_business_type" | 
|---|
|  |  |  | required | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <ReferenceInput reference="warehouseAreas" source="name"> | 
|---|
|  |  |  | <AutocompleteInput optionText="name" label="table.field.transfer.orgAreaName" /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <ReferenceInput reference="warehouseAreas" source="name"> | 
|---|
|  |  |  | <AutocompleteInput optionText="name" label="table.field.transfer.orgAreaName" /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <SimpleForm toolbar={false}> | 
|---|
|  |  |  | <Grid container spacing={2}> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <DictSelect | 
|---|
|  |  |  | label={translate("table.field.transfer.type")} | 
|---|
|  |  |  | value={formData.type} | 
|---|
|  |  |  | variant="filled" | 
|---|
|  |  |  | onChange={(e) => handleChange(e.target.value, 'type')} | 
|---|
|  |  |  | dictTypeCode="sys_transfer_type" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </Form> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <WarehouseSelect | 
|---|
|  |  |  | value={formData.orgAreaId} | 
|---|
|  |  |  | variant="filled" | 
|---|
|  |  |  | dictTypeCode="warehouse" | 
|---|
|  |  |  | onChange={(e) => handleChange(e.target.value, 'orgAreaId')} | 
|---|
|  |  |  | label={translate("table.field.transfer.orgAreaName")} /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item md={2}> | 
|---|
|  |  |  | <WarehouseSelect | 
|---|
|  |  |  | label={translate("table.field.transfer.tarAreaName")} | 
|---|
|  |  |  | value={formData.tarAreaId} | 
|---|
|  |  |  | dictTypeCode="warehouse" | 
|---|
|  |  |  | variant="filled" | 
|---|
|  |  |  | onChange={(e) => handleChange(e.target.value, 'tarAreaId')} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </SimpleForm> | 
|---|
|  |  |  | <Box sx={{ mt: 2 }}> | 
|---|
|  |  |  | <Stack direction="row" spacing={2} sx={{ justifyContent: "flex-end" }}> | 
|---|
|  |  |  | <Button variant="contained" onClick={() => setCreateDialog(true)} > | 
|---|
|  |  |  | <Button variant="contained" onClick={newAddClick} > | 
|---|
|  |  |  | {translate('common.action.newAddMats')} | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | <ConfirmButton label={"toolbar.delete"} variant="outlined" color="error" onConfirm={handleDeleteItem} /> | 
|---|
|  |  |  | 
|---|
|  |  |  | <TransferTableView | 
|---|
|  |  |  | tabelData={tabelData} | 
|---|
|  |  |  | setTableData={setTableData} | 
|---|
|  |  |  | asnId={orderId} | 
|---|
|  |  |  | orderId={orderId} | 
|---|
|  |  |  | selectedRows={selectedRows} | 
|---|
|  |  |  | setSelectedRows={setSelectedRows} | 
|---|
|  |  |  | tableRef={tableRef}> | 
|---|
|  |  |  | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | </Toolbar> | 
|---|
|  |  |  | <CreateBySelectMats | 
|---|
|  |  |  | data={tabelData} | 
|---|
|  |  |  | queryForm={formData} | 
|---|
|  |  |  | open={createDialog} | 
|---|
|  |  |  | setOpen={setCreateDialog} | 
|---|
|  |  |  | data={tabelData} | 
|---|
|  |  |  | selectedRows={selectedRows} | 
|---|
|  |  |  | setSelectedRows={setSelectedRows} | 
|---|
|  |  |  | setData={setTableData} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | field: 'anfme', | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.anfme') + "*", | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.anfme'), | 
|---|
|  |  |  | type: 'number', | 
|---|
|  |  |  | minWidth: 100, | 
|---|
|  |  |  | flex: 1, | 
|---|
|  |  |  | editable: true, | 
|---|
|  |  |  | valueFormatter: (val) => val < 0 ? 0 : val, | 
|---|
|  |  |  | headerClassName: "custom", | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | field: 'splrCode', | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.splrCode') + "*", | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.splrCode'), | 
|---|
|  |  |  | minWidth: 100, | 
|---|
|  |  |  | flex: 1, | 
|---|
|  |  |  | editable: true, | 
|---|
|  |  |  | renderEditCell: (params) => ( | 
|---|
|  |  |  | <SelectInputSplrCodeEditCell {...params} /> | 
|---|
|  |  |  | ), | 
|---|
|  |  |  | headerClassName: "custom", | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | field: 'splrName', | 
|---|
|  |  |  | 
|---|
|  |  |  | renderEditCell: (params) => ( | 
|---|
|  |  |  | <SelectInputSplrNameEditCell {...params} /> | 
|---|
|  |  |  | ), | 
|---|
|  |  |  | headerClassName: "custom", | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | field: 'splrBatch', | 
|---|
|  |  |  | field: 'batch', | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.splrBatch'), | 
|---|
|  |  |  | minWidth: 100, | 
|---|
|  |  |  | flex: 1, | 
|---|
|  |  |  | editable: true, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | field: 'poCode', | 
|---|
|  |  |  | headerName: translate('table.field.outStockItem.poDetlCode'), | 
|---|
|  |  |  | minWidth: 100, | 
|---|
|  |  |  | flex: 1, | 
|---|
|  |  |  | editable: true, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tableRef.current = useGridApiRef(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const tableIds = tabelData.map(map => map.id); | 
|---|
|  |  |  | // setSelectedRows(tableIds); | 
|---|
|  |  |  | // // console.log(selectedRows); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box> | 
|---|
|  |  |  | <DataGrid | 
|---|
|  |  |  | 
|---|
|  |  |  | rows={tabelData} | 
|---|
|  |  |  | columns={columns} | 
|---|
|  |  |  | disableRowSelectionOnClick | 
|---|
|  |  |  | getRowId={(row) => row.matnrId ? row.matnrId : row.id} | 
|---|
|  |  |  | disableColumnFilter | 
|---|
|  |  |  | disableColumnSelector | 
|---|
|  |  |  | disableColumnSorting | 
|---|
|  |  |  | disableMultipleColumnsSorting | 
|---|
|  |  |  | processRowUpdate={processRowUpdate} | 
|---|
|  |  |  | initialState={{ | 
|---|
|  |  |  | pagination: { | 
|---|
|  |  |  | paginationModel: { | 
|---|
|  |  |  | 
|---|
|  |  |  | pageSizeOptions={[15, 25, 50, 100]} | 
|---|
|  |  |  | editMode="row" | 
|---|
|  |  |  | checkboxSelection | 
|---|
|  |  |  | rowSelectionModel={tableIds} | 
|---|
|  |  |  | onRowSelectionModelChange={handleSelectionChange} | 
|---|
|  |  |  | selectionModel={selectedRows} | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | height: 610, | 
|---|
|  |  |  | height: 580, | 
|---|
|  |  |  | '& .MuiDataGrid-cell input': { | 
|---|
|  |  |  | border: '1px solid #ccc' | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | {/* <Box sx={{ | 
|---|
|  |  |  | padding: 2, | 
|---|
|  |  |  | position: 'absolute', | 
|---|
|  |  |  | right: 1 | 
|---|
|  |  |  | }}> | 
|---|
|  |  |  | <Button variant="contained" onClick={() => handleSubmit()} startIcon={<SaveIcon/>} > | 
|---|
|  |  |  | {translate('toolbar.confirm')} | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | </Box> */} | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }; | 
|---|