#
luxiaotao1123
2024-11-08 1dd993cf842ced0e49bb962bca09c10ad37dd89a
zy-acs-flow/src/page/loc/BulkUpdateButton.jsx
@@ -12,6 +12,7 @@
    NumberInput,
    TextInput,
    useTranslate,
    useResourceContext,
} from 'react-admin';
import { Dialog, DialogActions, DialogContent, DialogTitle, Grid, Stack, Divider } from '@mui/material';
import UpdateIcon from '@mui/icons-material/Update';
@@ -19,44 +20,45 @@
import ContentSave from '@mui/icons-material/Save';
import CloseIcon from '@mui/icons-material/Close';
const BulkUpdateButton = ({ resource, label = 'ra.action.update', ...rest }) => {
const BulkUpdateButton = ({ label = 'ra.action.update' }) => {
    const [open, setOpen] = useState(false);
    const refresh = useRefresh();
    const notify = useNotify();
    const translate = useTranslate();
    const resource = useResourceContext();
    const unselectAll = useUnselectAll(resource);
    const { selectedIds } = useListContext();
    const handleOpen = () => setOpen(true);
    const handleClose = () => setOpen(false);
    const [updateMany, { loading }] = useUpdateMany(
        resource,
        { ids: selectedIds, data: {} },
        {
            onSuccess: () => {
                setOpen(false);
                refresh();
                notify('common.response.success', { type: 'info' });
                unselectAll();
            },
            onError: (error) => {
                notify(error.msg || 'common.response.fail', { type: 'error' });
            }
        }
    );
    const [updateMany, { loading }] = useUpdateMany();
    const handleSubmit = (data) => {
        delete filteredData['memoWrap'];
        const filteredData = Object.fromEntries(
            Object.entries(data).filter(([key, value]) => value !== null && value !== undefined)
        );
        delete filteredData['memoWrap'];
        if (Object.keys(filteredData).length > 0) {
            console.log(filteredData);
            updateMany({
                data: filteredData,
            });
            updateMany(
                resource,
                {
                    ids: selectedIds,
                    data: filteredData,
                },
                {
                    onSuccess: () => {
                        setOpen(false);
                        refresh();
                        notify('common.response.success', { type: 'success' });
                        unselectAll();
                    },
                    onError: (error) => {
                        notify(error.message || 'common.response.fail', { type: 'error' });
                    },
                }
            );
        } else {
            notify('common.response.fail', { type: 'warning' });
        }
@@ -115,6 +117,7 @@
                            color="inherit"
                            size='large'
                            label='ra.action.cancel'
                            aria-label={false}
                            sx={{ mr: 1 }}
                        >
                            <CloseIcon />
@@ -125,6 +128,7 @@
                            color="primary"
                            size='large'
                            label='ra.action.save'
                            aria-label={false}
                            disabled={loading}
                            sx={{ mr: 1 }}
                        >