From 72ca54b5a36818de16acf81c9c395e9f35a39a67 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期三, 11 六月 2025 09:53:27 +0800
Subject: [PATCH] 下发执行页,添加默认请求方法
---
rsf-admin/src/page/orders/outStock/OutStockPublic.jsx | 329 ++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 268 insertions(+), 61 deletions(-)
diff --git a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
index 21b87bf..40e4607 100644
--- a/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
+++ b/rsf-admin/src/page/orders/outStock/OutStockPublic.jsx
@@ -1,4 +1,4 @@
-import { Box, Card, Grid, LinearProgress } from "@mui/material";
+import { Box, Card, Grid, LinearProgress, Select, MenuItem, ListItemText } from "@mui/material";
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
List,
@@ -13,7 +13,6 @@
ExportButton,
BulkDeleteButton,
WrapperField,
- Toolbar,
useRecordContext,
useTranslate,
useNotify,
@@ -36,16 +35,18 @@
SimpleForm,
required,
Form,
- SaveButton,
useRefresh,
- useGetList,
- useGetOne,
+ useRedirect,
} from 'react-admin';
-import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting';
+import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE, DEFAULT_ITEM_PAGE_SIZE, DEFAULT_TYPE } from '@/config/setting';
import { styled } from '@mui/material/styles';
-import { DataGrid } from '@mui/x-data-grid';
+import { DataGrid, useGridApiContext, GridActionsCellItem, useGridApiRef } from '@mui/x-data-grid';
import request from '@/utils/request';
-import DictSelect from "../../components/DictSelect";
+import ConfirmationNumberOutlinedIcon from '@mui/icons-material/ConfirmationNumberOutlined';
+import CloseSharpIcon from '@mui/icons-material/CloseSharp';
+import ConfirmButton from '../../components/ConfirmButton';
+import { Delete, Edit, Add } from '@mui/icons-material';
+import OutStockSiteDialog from "./OutStockSiteDialog";
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
'& .css-1vooibu-MuiSvgIcon-root': {
@@ -54,29 +55,56 @@
'& .RaDatagrid-row': {
cursor: 'auto'
},
+ '& .column-maktx': {
+ width: 200
+ }
}));
-
const OutStockPublic = (props) => {
- const { record, open } = props;
- const [formData, setFormData] = useState({
- orderId: record?.id
- });
+ const { record, open, setOpen } = props;
+ const notify = useNotify();
+ const gridRef = useGridApiRef();
+ const [rows, setRows] = useState({});
const translate = useTranslate();
+ const [selectedIds, setSelectedIds] = useState([]);
+ const [formData, setFormData] = useState({
+ orderId: record?.id,
+ waveId: DEFAULT_TYPE
+ });
+ const [dialog, setDialog] = useState(false);
+ const [selectedValue, setSelectedValue] = useState({});
+
+ const handleClickOpen = () => {
+ setDialog(true);
+ };
+
+ const handleClose = (value) => {
+ setDialog(false);
+ setSelectedValue(value);
+ const newRows = rows.map(item => {
+ return {
+ ...item,
+ siteNo: value?.site
+ }
+ })
+ setRows(newRows);
+ };
useEffect(() => {
- getWaveRule()
- }, [formData, open])
+ if (open) {
+ getWaveRule()
+ }
+ }, [open, formData])
const getWaveRule = async () => {
if (formData.waveId == null && formData.waveId == undefined) {
return
}
- const res = await request.post('/outStock/order/getOutTaskItems', {...formData});
- if (res?.data?.code === 200) {
- setRows(res.data.data.records)
+ const { data: { code, data, msg } } = await request.post('/outStock/order/getOutTaskItems', { ...formData });
+ if (code === 200) {
+ setRows(data)
} else {
- notify(res.data.msg);
+ notify(msg);
}
}
@@ -87,11 +115,12 @@
}));
};
+
return (
<>
<Box>
<Grid sx={{ display: "flex" }} container rowSpacing={2} columnSpacing={2}>
- <Grid item xl={6} gap={2} >
+ <Grid item xl={5.7} gap={2} >
<Card>
<Form>
<ReferenceInput
@@ -101,18 +130,12 @@
<AutocompleteInput
label="table.field.waveRule.type"
onChange={(e) => handleChange(e, 'waveId')}
+ defaultValue={15}
value={formData.type}
validate={required()}
/>
</ReferenceInput>
</Form>
- {/* <DictSelect
- label={translate("table.field.waveRule.type")}
- onChange={(e) => handleChange(e.target.value, 'type')}
- value={formData.type}
- dictTypeCode="sys_wave_rule_code"
- required
- /> */}
<List
resource="outStockItem"
storeKey='outStockItem'
@@ -137,7 +160,7 @@
preferenceKey='outStockItem'
bulkActionButtons={false}
rowClick={false}
- omit={['id', 'splrName', 'qty', 'poCode']}
+ omit={['id', 'splrName', 'qty', 'poCode', 'workQty']}
>
<NumberField source="id" />
<TextField source="asnCode" label="table.field.outStockItem.asnCode" />
@@ -153,55 +176,239 @@
</List>
</Card>
</Grid>
- <Grid item xl={6} gap={2}>
+ <Grid item xl={6.3} gap={2}>
<Card>
- <Box>
- <DataGrid
+ <Box sx={{ height: 500, width: '100%' }}>
+ <PreviewTable
rows={rows}
- columns={columns}
- initialState={{
- pagination: {
- paginationModel: {
- pageSize: 15,
- },
- },
- }}
- pageSizeOptions={[15, 25, 35, 45]}
- disableRowSelectionOnClick
+ gridRef={gridRef}
+ setRows={setRows}
+ record={record}
+ selectedIds={selectedIds}
+ setDialog={setDialog}
+ setSelectedIds={setSelectedIds}
/>
+ </Box>
+ <Box sx={{ textAlign: 'center' }}>
+ <CloseButton setOpen={setOpen} />
+ <SubmitButton selectedIds={selectedIds} setSelectedIds={setSelectedIds} gridRef={gridRef} record={record} />
</Box>
</Card>
</Grid>
+ </Grid>
+ <Grid>
+ <OutStockSiteDialog
+ selectedValue={selectedValue}
+ open={dialog}
+ onClose={handleClose}
+ />
</Grid>
</Box>
</>
);
}
+const PreviewTable = ({ rows, gridRef, setRows, record, selectedIds, setSelectedIds, setDialog }) => {
+ gridRef.current = useGridApiRef();
+
+ const columns = [
+ { field: 'id', headerName: 'ID', width: 40 },
+ { field: 'locCode', headerName: '搴撲綅', width: 110 },
+ { field: 'barcode', headerName: '瀹瑰櫒', width: 120 },
+ { field: 'batch', headerName: '鎵规', width: 90 },
+ { field: 'unit', headerName: '鍗曚綅', width: 90 },
+ { field: 'outQty', headerName: '鏈鍑哄簱鏁伴噺', width: 110 },
+ {
+ field: 'siteNo',
+ headerName: '鍑哄簱鍙�',
+ width: 90,
+ type: 'singleSelect',
+ editable: true,
+ renderCell: (params) => (
+ <OutStockSiteNo value={params.value} />
+ ),
+ renderEditCell: (params) => (
+ <OutStockSite {...params} />
+ ),
+ },
+ {
+ field: 'actions',
+ type: 'actions',
+ headerName: '鎿嶄綔',
+ with: 120,
+ getActions: (params) => [
+ <GridActionsCellItem
+ icon={<Delete />}
+ label="Delete"
+ onClick={() => handleDelete(params.row, rows, setRows)}
+ />,
+ ]
+ },
+ ]
+
+ /**
+ * 鍒犻櫎浜嬩欢
+ * @param {*} params
+ */
+ const handleDelete = (params, rows, setRows) => {
+ const outRows = rows.filter(row => {
+ return row.id !== params.id
+ })
+ setRows(outRows)
+ }
+
+ const OutStockSiteNo = React.memo(function OutStockSiteNo(props) {
+ const { value } = props;
+ if (!value) {
+ return null;
+ }
+ return (
+ <Box
+ sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
+ >
+ <span>{value}</span>
+ </Box>
+ );
+ });
+
+ const CustomToolBar = () => {
+ const selectSiteNo = () => {
+ setDialog(true)
+ }
+
+ return (
+ selectedIds.length > 0 ? <Box sx={{
+ p: 1,
+ display: 'flex',
+ justifyContent: 'flex-end',
+ borderTop: '1px solid rgba(224, 224, 224, 1)'
+ }}>
+ <Button
+ onClick={selectSiteNo}
+ variant="outlined"
+ label="toolbar.modiftySite"
+ size="medium"
+ sx={{ mr: 1 }} />
+ </Box> : <></>
+ );
+ }
+
+ const OutStockSite = (params) => {
+ const { id, field, siteNo, row: { staNos } } = params;
+ const apiRef = useGridApiContext();
+ const handleChange = async (event) => {
+ await apiRef.current.setEditCellValue(
+ { id, field, value: event.target.value },
+ event,
+ );
+ apiRef.current.stopCellEditMode({ id, field });
+ };
+
+ const handleClose = (event, reason) => {
+ if (reason === 'backdropClick') {
+ apiRef.current.stopCellEditMode({ id, field });
+ }
+ };
+
+ return (
+ <Select
+ value={siteNo}
+ onChange={handleChange}
+ MenuProps={{
+ onClose: handleClose,
+ }}
+ sx={{
+ height: '100%',
+ '& .MuiSelect-select': {
+ display: 'flex',
+ alignItems: 'center',
+ pl: 1,
+ },
+ }}
+ autoFocus
+ fullWidth
+ open
+ >
+ {staNos.map((option) => {
+ return (
+ <MenuItem
+ key={option}
+ value={option.staNo}
+ >
+ <ListItemText sx={{ overflow: 'hidden' }} primary={option.staNo} />
+ </MenuItem>
+ );
+ })}
+ </Select >
+ )
+ }
+
+ return (
+ <DataGrid
+ rows={rows}
+ columns={columns}
+ slots={{ toolbar: CustomToolBar }}
+ apiRef={gridRef}
+ initialState={{
+ pagination: {
+ paginationModel: {
+ pageSize: 15,
+ },
+ },
+ }}
+ checkboxSelection
+ pageSizeOptions={[15, 25, 35, 45]}
+ onRowSelectionModelChange={(ids) => {
+ setSelectedIds(ids)
+ }}
+ />
+ )
+}
-const rows = [
- { id: 1, locCode: '03-02-1-2-1', container: 'Snow', batch: 'Jon', curQty: 14 },
- { id: 2, locCode: '03-02-1-2-1', container: 'Lannister', batch: 'Cersei', curQty: 31 },
- { id: 3, locCode: '03-02-1-2-1', container: 'Lannister', batch: 'Jaime', curQty: 31 },
- { id: 4, locCode: '03-02-1-2-1', container: 'Stark', batch: 'Arya', curQty: 11 },
- { id: 5, locCode: '03-02-1-2-1', container: 'Targaryen', batch: 'Daenerys', curQty: null },
- { id: 6, locCode: '03-02-1-2-1', container: 'Melisandre', batch: null, curQty: 150 },
- { id: 7, locCode: '03-02-1-2-1', container: 'Clifford', batch: 'Ferrara', curQty: 44 },
- { id: 8, locCode: '03-02-1-2-1', container: 'Frances', batch: 'Rossini', curQty: 36 },
- { id: 9, locCode: '03-02-1-2-1', container: 'Roxie', batch: 'Harvey', curQty: 65 },
-]
-const columns = [
- { field: 'id', headerName: 'ID', width: 40 },
- { field: 'locCode', headerName: '搴撲綅', width: 110 },
- { field: 'container', headerName: '瀹瑰櫒', width: 120 },
- { field: 'batch', headerName: '鎵规', width: 90 },
- { field: 'unit', headerName: '鍗曚綅', width: 90 },
- { field: 'curQty', headerName: '鏈鍑哄簱鏁伴噺', width: 110 },
- { field: 'siteNo', headerName: '鍑哄簱鍙�', width: 90 }, ``
-]
+//鎻愪氦鎸夐挳
+const SubmitButton = ({ selectedIds, setSelectedIds, gridRef, record }) => {
+ const notify = useNotify();
+ const refresh = useRefresh();
+ const redirect = useRedirect();
+ const submit = async () => {
+ console.log(record);
+ const items = gridRef.current?.getSortedRows();
+ const { data: { code, data, msg } } = await request.post('/outStock/generate/tasks', { items, outId: record?.id });
+ if (code == 200) {
+ refresh();
+ redirect("/task")
+ } else {
+ notify(msg);
+ }
+ }
+ return (
+ <ConfirmButton
+ label="toolbar.confirm"
+ variant="contained"
+ size="medium"
+ onConfirm={submit}
+ startIcon={<ConfirmationNumberOutlinedIcon />}
+ />
+ )
+}
+//鍏抽棴鎸夐挳
+const CloseButton = ({ setOpen }) => {
+ const close = () => {
+ setOpen(false)
+ }
+ return (
+ <Button
+ label="toolbar.close"
+ variant="outlined"
+ size="medium"
+ onClick={close}
+ startIcon={<CloseSharpIcon />}
+ sx={{ margin: '3.5em' }} />
+ )
+}
export default OutStockPublic;
--
Gitblit v1.9.1