From 7820edd7c7e26f4858bbe7dec1bc30de9e1155a3 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 08 十一月 2024 13:53:20 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/page/loc/BulkUpdateButton.jsx |  119 ++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 61 insertions(+), 58 deletions(-)

diff --git a/zy-acs-flow/src/page/loc/BulkUpdateButton.jsx b/zy-acs-flow/src/page/loc/BulkUpdateButton.jsx
index bfe5f0e..9be7c09 100644
--- a/zy-acs-flow/src/page/loc/BulkUpdateButton.jsx
+++ b/zy-acs-flow/src/page/loc/BulkUpdateButton.jsx
@@ -21,53 +21,54 @@
 
 const BulkUpdateButton = ({ resource, label = 'ra.action.update', ...rest }) => {
     const [open, setOpen] = useState(false);
-    const [formData, setFormData] = useState({});
 
     const refresh = useRefresh();
     const notify = useNotify();
     const translate = useTranslate();
     const unselectAll = useUnselectAll(resource);
-    const { selectedIds, onUnselectItems } = useListContext();
-
-    const [updateMany, { loading }] = useUpdateMany(
-        resource,
-        { ids: selectedIds, data: formData },
-        {
-            onSuccess: () => {
-                setOpen(false);
-                refresh();
-                notify('common.response.success', { type: 'info' });
-                unselectAll();
-            },
-            onError: (error) => {
-                notify(error.msg || 'common.response.fail', { type: 'error' });
-            }
-        }
-    );
+    const { selectedIds } = useListContext();
 
     const handleOpen = () => setOpen(true);
     const handleClose = () => setOpen(false);
 
-    const handleChange = (e) => {
-        const { name, value } = e.target;
-        setFormData({
-            ...formData,
-            [name]: value,
-        });
-    };
+    const [updateMany, { loading }] = useUpdateMany();
 
-    const handleSubmit = () => {
-        console.log(formData);
-        updateMany();
+    const handleSubmit = (data) => {
+        const filteredData = Object.fromEntries(
+            Object.entries(data).filter(([key, value]) => value !== null && value !== undefined)
+        );
+        delete filteredData['memoWrap'];
+        if (Object.keys(filteredData).length > 0) {
+            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' });
+        }
     };
 
     return (
         <>
             <RaButton onClick={handleOpen} startIcon={<UpdateIcon />} label={label} />
             <Dialog open={open} onClose={handleClose}>
-                <DialogTitle>{translate('ra.action.update')}</DialogTitle>
-                <DialogContent>
-                    <Form>
+                <Form onSubmit={handleSubmit}>
+                    <DialogTitle>{translate('ra.action.update')}</DialogTitle>
+                    <DialogContent>
                         <Grid container rowSpacing={2} columnSpacing={2}>
                             <Grid item xs={6} display="flex" gap={1}>
                                 <ReferenceInput
@@ -105,33 +106,35 @@
                                 </Stack>
                             </Grid>
                         </Grid>
-                    </Form>
-                </DialogContent>
-                <Divider sx={{ mb: 1 }} />
-                <DialogActions sx={{ mb: 1 }}>
-                    <RaButton
-                        onClick={handleClose}
-                        variant="contained"
-                        color="inherit"
-                        size='large'
-                        label='ra.action.cancel'
-                        sx={{ mr: 1 }}
-                    >
-                        <CloseIcon />
-                    </RaButton>
-                    <RaButton
-                        onClick={handleSubmit}
-                        variant="contained"
-                        color="primary"
-                        size='large'
-                        label='ra.action.save'
-                        disabled={loading}
-                        sx={{ mr: 1 }}
-                    >
-                        <ContentSave />
-                    </RaButton>
-                </DialogActions>
-            </Dialog>
+                    </DialogContent>
+                    <Divider sx={{ mb: 1 }} />
+                    <DialogActions sx={{ mb: 1 }}>
+                        <RaButton
+                            onClick={handleClose}
+                            variant="contained"
+                            color="inherit"
+                            size='large'
+                            label='ra.action.cancel'
+                            aria-label={false}
+                            sx={{ mr: 1 }}
+                        >
+                            <CloseIcon />
+                        </RaButton>
+                        <RaButton
+                            type="submit"
+                            variant="contained"
+                            color="primary"
+                            size='large'
+                            label='ra.action.save'
+                            aria-label={false}
+                            disabled={loading}
+                            sx={{ mr: 1 }}
+                        >
+                            <ContentSave />
+                        </RaButton>
+                    </DialogActions>
+                </Form>
+            </Dialog >
         </>
     );
 };

--
Gitblit v1.9.1