#
vincentlu
2025-05-13 ebd2f4397a92c6a5096de1b86d59154363344720
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
    useTranslate,
    TabbedShowLayout,
    useShowContext,
} from 'react-admin';
import {
    Box,
    Button,
    Card,
    CardContent,
    Stack,
    Typography,
    Avatar,
    Skeleton,
    Divider,
    List,
    ListItem,
    ListItemAvatar,
    ListItemText,
    ListItemSecondaryAction,
} from '@mui/material';
import { formatDistance } from 'date-fns';
import request from '@/utils/request';
import { useTheme } from '@mui/material/styles';
import { getTaskStsColor } from '@/utils/color-util';
import ListEmptyTip from "../../components/ListEmptyTip";
 
const TaskItem = ({ record, now }) => {
    const translate = useTranslate();
    const theme = useTheme();
 
    return (
        <>
            <ListItem button>
                <Stack direction="row" spacing={1} alignItems="center" width="100%">
                    <ListItemAvatar>
                        <Avatar
                            alt={record.seqNum}
                            variant="rounded"
                            sx={{
                                '& img': { objectFit: 'contain' },
                                fontSize: '0.9rem',
                                width: 40,
                                height: 25,
                                bgcolor: getTaskStsColor(record.taskSts$),
                            }}
                        >
                            {record.seqNum}
                        </Avatar>
                    </ListItemAvatar>
                    <ListItemText
                        primary={<>
                            <Stack direction={'row'}>
                                <Typography
                                    variant="body1"
                                    color="textSecondary"
                                    component="span"
                                    sx={{ fontWeight: '600' }}
                                >
                                    {record.taskType$}
                                </Typography>
                                <Typography
                                    variant="caption"
                                    color="textSecondary"
                                    component="span"
                                >
                                    &nbsp;-&nbsp; {record.taskTypeEl}
                                </Typography>
                            </Stack>
 
                        </>}
                        secondary={
                            <>
                                <Typography
                                    variant="body2"
                                    color="textSecondary"
                                    component="span"
                                    sx={{ fontWeight: 'bold' }}
                                >
                                    {record.taskSts$}
                                </Typography>
                            </>
                        }
                    />
                    <ListItemText
                        variant="body2"
                        color="textSecondary"
                        primary={<>
                            <Typography
                                variant="body2"
                                color="textPrimary"
                                component="span"
                            >
                                {record.oriLoc$ || ''}{record.oriSta$ || ''} - {record.destLoc$ || ''}{record.destSta$ || ''}
                            </Typography>
                        </>}
                        secondary={`code: ${record.destCode$ || ''}`}
                    />
                    <ListItemSecondaryAction>
                        <Typography
                            variant="body2"
                            color="textSecondary"
                            component="span"
                        >
                            last update {' '}
                            {formatDistance(record.createTime, now)} ago{' '}
                        </Typography>
                    </ListItemSecondaryAction>
                </Stack>
            </ListItem>
        </>
    )
}
 
export const AgvShowTask = ({ agvId, pageSize = 10 }) => {
    const [currCount, setCurrCount] = useState(pageSize);
    const [records, setRecords] = useState(null);
    const [total, setTotal] = useState(0);
    const translate = useTranslate();
 
    useEffect(() => {
        const http = async () => {
            const res = await request.post('task/page', {
                agvId: agvId,
                pageSize: currCount,
                orderBy: 'create_time desc',
            });
            const { code, msg, data } = res.data;
            if (code === 200) {
                setTotal(data.total);
                setRecords(data.records);
            } else {
                setTotal(0);
                setRecords(null);
            }
        }
        if (agvId) { http() }
    }, [agvId, currCount]);
 
    if (!records) {
        return (
            <Stack mt={0.5}>
                {Array.from({ length: 5 }).map((_, index) => (
                    <Stack spacing={2} sx={{ mt: 1 }} key={index}>
                        <Stack
                            direction="row"
                            spacing={2}
                            sx={{ alignItems: 'center' }}
                        >
                            <Skeleton
                                variant="circular"
                                width={20}
                                height={20}
                            />
                            <Skeleton width="100%" />
                        </Stack>
                        <Skeleton variant="rectangular" height={50} />
                        <Divider />
                    </Stack>
                ))}
            </Stack>
        );
    }
    const now = Date.now();
 
    return (
        <>
            {records.length > 0 ? (
                <Box >
                    <List>
                        {records.map(record => {
                            return (
                                <React.Fragment key={record.id}>
                                    <TaskItem
                                        key={record.id}
                                        record={record}
                                        now={now}
                                    />
                                    <Divider />
                                </React.Fragment>
                            )
                        })}
                        {currCount < total && (
                            <Button
                                onClick={() =>
                                    setCurrCount(
                                        currCount =>
                                            currCount + pageSize
                                    )
                                }
                                fullWidth
                                sx={{ mt: 1 }}
                            >
                                {translate('common.action.loadMore')}
                            </Button>
                        )}
                    </List>
                </Box>
            ) : (
                <ListEmptyTip />
            )}
 
        </>
    )
}