From d871326f5ad1c55367333e1cb1aaf93e87989bea Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期五, 23 五月 2025 09:39:42 +0800 Subject: [PATCH] 库存出库功能优化 --- rsf-admin/src/page/outWork/outBound/OutBoundList.jsx | 205 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 143 insertions(+), 62 deletions(-) diff --git a/rsf-admin/src/page/outWork/outBound/OutBoundList.jsx b/rsf-admin/src/page/outWork/outBound/OutBoundList.jsx index 6afcfcd..e7bf5b2 100644 --- a/rsf-admin/src/page/outWork/outBound/OutBoundList.jsx +++ b/rsf-admin/src/page/outWork/outBound/OutBoundList.jsx @@ -20,7 +20,8 @@ useCreateController, useListContext, useRefresh, - Edit, + Edit, + useRedirect, } from 'react-admin'; import { Dialog, @@ -57,12 +58,18 @@ import request from '@/utils/request'; import LocItemInfoModal from "./locItemInfoModal"; import { Delete } from '@mui/icons-material'; +import _, { set } from 'lodash'; +import StaSelect from "./StaSelect"; +import { redirect } from "react-router"; +import { number } from "prop-types"; -const OutBoundList = () => { +const OutBoundList = () => { const [createDialog, setCreateDialog] = useState(false); const [tabelData, setTableData] = useState([]); const [selectedRows, setSelectedRows] = useState([]); + const [sta, setSta] = useState(""); + const notify = useNotify(); const tableRef = useRef(); tableRef.current = useGridApiRef(); const translate = useTranslate(); @@ -71,73 +78,138 @@ const newTableData = _.filter(tabelData, (item) => !selectedRows.includes(item.matnrId)); setTableData(newTableData); } + + // 娣诲姞涓�涓鐞嗘柊鏁版嵁鐨勫嚱鏁帮紝璁剧疆outQty榛樿鍊� + const handleSetData = (newData) => { + // 涓烘柊娣诲姞鐨勬暟鎹缃畂utQty榛樿鍊间负anfme鐨勫�� + const dataWithDefaultQty = newData.map(item => ({ + ...item, + outQty: item.outQty || item.anfme // 濡傛灉outQty宸插瓨鍦ㄥ垯淇濈暀锛屽惁鍒欎娇鐢╝nfme鐨勫�� + })); + setTableData([...tabelData, ...dataWithDefaultQty]); + }; + + + return ( <> - <Card sx={{ p: 2, mb: 2, mt:2}}> - <Grid container spacing={2}> - <Grid item xs={12}> - <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 1 }}> - <Typography variant="h6"> - {translate('table.field.outBound.stockWithdrawal')} - </Typography> - <Stack direction='row' spacing={2}> - <Button - variant="contained" - color="primary" - startIcon={<AddIcon />} - onClick={() => setCreateDialog(true)} - > - {translate('table.field.outBound.withdrawal')} - </Button> - <ConfirmButton - label={'鍒犻櫎'} - variant="outlined" - color="error" - onConfirm={handleDeleteItem} - /> - </Stack> - </Box> - </Grid> - </Grid> - </Card> - <Card sx={{ p: 2, mb: 2, mt:2}}> - <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> - <Grid container spacing={2}> - <Grid item md={2}> - <Box sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center', gap: 1 }}> - <Typography width={100} vvariant="h6" gutterBottom> - {translate('table.field.outBound.outSta')} - </Typography> - <DictSelect - label={translate("table.field.outStock.wkType")} - variant="filled" - group='2' - dictTypeCode="sys_business_type" - required - /> + <Card sx={{ p: 2, mb: 2, mt: 2 }}> + <Grid container spacing={2}> + <Grid item xs={12}> + <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 1 }}> + <Typography variant="h6"> + {translate('table.field.outBound.stockWithdrawal')} + </Typography> + <Stack direction='row' spacing={2}> + <Button + variant="contained" + color="primary" + startIcon={<AddIcon />} + onClick={() => setCreateDialog(true)} + > + {translate('table.field.outBound.withdrawal')} + </Button> + </Stack> </Box> - </Grid> - </Grid> - </Box> - </Card> - <Card sx={{ mb: 2}}> - <Box sx={{ }}> - <ModalTable tabelData={tabelData} setTableData={setTableData} selectedRows={selectedRows} setSelectedRows={setSelectedRows} tableRef={tableRef}></ModalTable> - </Box> - </Card> - <LocItemInfoModal + </Grid> + </Grid> + </Card> + <Card sx={{ p: 2, mb: 2 }}> + <Form> + <Grid container spacing={2}> + <Grid item xs={12}> + <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 1 }}> + <Typography variant="h6" > + {translate('table.field.outBound.outSta')} + </Typography> + <Stack direction='row' spacing={2} minWidth={200}> + <StaSelect + source="sta" + label={translate("table.field.outBound.outSta")} + onChange={(e) => { + setSta(e.target.value); + console.log("绔欑偣宸查�夋嫨:", e.target.value); + }} + size="small" + type="[101,103]" + /> + </Stack> + <Stack direction='row' spacing={2} minWidth={200}> + <SubmitButton + sta={sta} + data={tabelData} + setTableData={setTableData} + /> + </Stack> + </Box> + </Grid> + </Grid> + </Form> + </Card> + <Card sx={{ mb: 2 }}> + <Box sx={{}}> + <ModalTable tabelData={tabelData} setTableData={setTableData} selectedRows={selectedRows} setSelectedRows={setSelectedRows} tableRef={tableRef}></ModalTable> + </Box> + </Card> + <LocItemInfoModal open={createDialog} setOpen={setCreateDialog} data={tabelData} - setData={setTableData} + setData={handleSetData} /> - + </> ) } export default OutBoundList; +const SubmitButton = (props) => { + const translate = useTranslate(); + const notify = useNotify(); + const redirect = useRedirect(); + const refresh = useRefresh(); + const { sta, data, setTableData } = props; + const check = () => { + if (sta === "" || sta === undefined || sta === null) { + notify("璇烽�夋嫨绔欑偣"); + return; + } + if (data.length === 0) { + notify("璇烽�夋嫨鐗╂枡"); + return; + } + http(sta, data); + } + const http = async (sta, items) => { + console.log(items); + + const filter = items.filter(item => (item.outQty + item.workQty) > item.anfme); + if (filter.length > 0) { + notify(translate('toolbar.request.error.out_stock_qty')) + return + } + const { data: { code, data, msg } } = await request.post(`/locItem/generate/task`, { siteNo: sta, items: items }); + if (code === 200) { + notify(msg); + refresh() + setTableData([]) + redirect("/task") + } else { + notify(msg); + } + } + return ( + <ConfirmButton + variant="contained" + color="primary" + onConfirm={check} + label={"table.field.outBound.createTask"} + > + </ConfirmButton> + ) + +} const ModalTable = ({ tabelData, setTableData, selectedRows, setSelectedRows, tableRef }) => { const translate = useTranslate(); @@ -146,22 +218,32 @@ const [columns, setColumns] = useState([ { field: 'outQty', - headerName: translate('table.field.outBound.outQty'), + headerName: translate('table.field.outBound.outQty') + "*", width: 100, + type: 'number', editable: true, + headerClassName: "custom", }, { field: 'anfme', headerName: translate('table.field.locItem.anfme'), + type: 'number', width: 100, editable: false, - }, + }, + { + field: 'workQty', + headerName: translate('table.field.locItem.workQty'), + width: 100, + type: 'number', + editable: false, + }, { field: 'matnrCode', headerName: translate('table.field.locItem.matnrCode'), width: 130, editable: false, - }, + }, { field: 'maktx', headerName: translate('table.field.locItem.maktx'), @@ -201,7 +283,6 @@ cdata.current = tabelData }, [tabelData]); - const getDynamicFields = async () => { const { data: { code, data, msg }, @@ -222,14 +303,14 @@ const handleDelete = (row) => { - const newData = _.filter(cdata.current, (item) => item.matnrId !== row.matnrId); + const newData = _.filter(cdata.current, (item) => item.id !== row.id); setTableData(newData); }; const processRowUpdate = (newRow, oldRow) => { const rows = tabelData.map((r) => - r.matnrId === newRow.matnrId ? { ...newRow } : r + r.id === newRow.id ? { ...newRow } : r ) setTableData(rows) return newRow; -- Gitblit v1.9.1