From cd67e854d4715bc92a16dc7bffdbde7be1da9957 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期四, 27 三月 2025 13:02:37 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/page/mission/MissionResend.jsx |   92 +++++++++++++++++++++++++++++----------------
 1 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/zy-acs-flow/src/page/mission/MissionResend.jsx b/zy-acs-flow/src/page/mission/MissionResend.jsx
index 1d9518f..85823b3 100644
--- a/zy-acs-flow/src/page/mission/MissionResend.jsx
+++ b/zy-acs-flow/src/page/mission/MissionResend.jsx
@@ -36,6 +36,7 @@
 import DialogCloseButton from "../components/DialogCloseButton";
 import { format } from 'date-fns';
 import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
+import request from '@/utils/request';
 
 const MissionResend = ({ open, id }) => {
     const redirect = useRedirect();
@@ -136,8 +137,7 @@
                             </Box>
                         )}
 
-                        <ActionTable actionIds={record?.actionIds} />
-
+                        <ActionTable actionIds={record?.actionIds} currCode={record.currCode} handleClose={handleClose} />
                     </Box>
                 </Box>
             </Stack>
@@ -147,39 +147,41 @@
 
 const headCells = [
     {
-        id: 'name',
+        id: 'actionType',
         numeric: false,
         disablePadding: true,
-        label: 'Dessert聽(100g serving)',
+        label: 'table.field.action.actionType',
     },
     {
-        id: 'calories',
+        id: 'code',
         numeric: true,
         disablePadding: false,
-        label: 'Calories',
+        label: 'table.field.action.code',
     },
     {
-        id: 'fat',
+        id: 'taskId',
         numeric: true,
         disablePadding: false,
-        label: 'Fat聽(g)',
+        label: 'table.field.action.taskId',
     },
     {
-        id: 'carbs',
+        id: 'val',
         numeric: true,
         disablePadding: false,
-        label: 'Carbs聽(g)',
+        label: 'table.field.action.val',
     },
     {
-        id: 'protein',
+        id: 'params',
         numeric: true,
         disablePadding: false,
-        label: 'Protein聽(g)',
+        label: 'table.field.action.params',
     },
 ];
 
-const ActionTable = ({ actionIds }) => {
+const ActionTable = ({ actionIds, currCode, handleClose }) => {
     const dataProvider = useDataProvider();
+    const translate = useTranslate();
+    const notify = useNotify();
     const [actions, setActions] = useState([]);
     const [selected, setSelected] = React.useState([]);
 
@@ -188,6 +190,13 @@
             dataProvider.getMany('action', { ids: actionIds }).then(res => {
                 if (res.data?.length > 0) {
                     setActions(res.data);
+
+                    // init selected
+                    const indexOfCurrCode = res.data.findIndex(item => item.code === currCode);
+                    if (indexOfCurrCode !== -1) {
+                        const selectedIds = res.data.slice(indexOfCurrCode).map(item => item.id);
+                        setSelected(selectedIds);
+                    }
                 }
             })
         }
@@ -221,16 +230,35 @@
         setSelected(newSelected);
     };
 
+    const resendSubmit = () => {
+        if (!!selected?.length) {
+            request.post("/mission/resend", selected.map(id => ({ id }))).then(res => {
+                const { code, msg, data } = res.data;
+                if (code === 200) {
+                    notify(msg || 'common.response.success', { type: 'success', messageArgs: { _: msg } });
+                    handleClose();
+                } else {
+                    notify(msg || 'common.response.fail', { type: 'error', messageArgs: { _: msg } });
+                }
+            }).catch(error => {
+                notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } });
+            })
+        }
+    }
 
     return (
         <>
             <Box sx={{ width: '100%' }}>
-                <Paper sx={{ width: '100%', mb: 2 }}>
+                <Paper sx={{
+                    width: '100%',
+                    mb: 2,
+                }}>
                     <Toolbar
                         sx={[
                             {
                                 pl: { sm: 2 },
                                 pr: { xs: 1, sm: 1 },
+                                minHeight: '52.5px !important',
                             },
                             selected.length > 0 && {
                                 bgcolor: (theme) =>
@@ -245,29 +273,25 @@
                                 variant="subtitle1"
                                 component="div"
                             >
-                                {selected.length} selected
+                                {selected.length} {translate('common.action.selected')}
                             </Typography>
                         ) : (
                             <Typography
                                 sx={{ flex: '1 1 100%' }}
-                                variant="h6"
+                                variant="subtitle1"
                                 id="tableTitle"
                                 component="div"
                             >
-                                Actions
+                                {translate('table.field.mission.actions')}
                             </Typography>
                         )}
                         {selected.length > 0 && (
-                            <Tooltip title="Delete">
-                                <IconButton>
-                                    <Button
-                                        onClick={() => {
-                                            alert('clicked');
-                                        }}
-                                    >
-                                        ss
-                                    </Button>
-                                </IconButton>
+                            <Tooltip title="Resend">
+                                <Button
+                                    onClick={resendSubmit}
+                                >
+                                    {translate('ra.action.confirm')}
+                                </Button>
                             </Tooltip>
                         )}
                     </Toolbar>
@@ -297,7 +321,7 @@
                                             align={headCell.numeric ? 'right' : 'left'}
                                             padding={headCell.disablePadding ? 'none' : 'normal'}
                                         >
-                                            {headCell.label}
+                                            {translate(headCell.label)}
                                         </TableCell>
                                     ))}
                                 </TableRow>
@@ -333,12 +357,14 @@
                                                 scope="row"
                                                 padding="none"
                                             >
-                                                {row.name}
+                                                [ {row.priority} ]
+                                                &nbsp;&nbsp;
+                                                {row.actionType$}
                                             </TableCell>
-                                            <TableCell align="right">{row.calories}</TableCell>
-                                            <TableCell align="right">{row.fat}</TableCell>
-                                            <TableCell align="right">{row.carbs}</TableCell>
-                                            <TableCell align="right">{row.protein}</TableCell>
+                                            <TableCell align="right">{row.code}</TableCell>
+                                            <TableCell align="right">{row.taskId$}</TableCell>
+                                            <TableCell align="right">{row.val}</TableCell>
+                                            <TableCell align="right">{row.params}</TableCell>
                                         </TableRow>
                                     );
                                 })}

--
Gitblit v1.9.1