skyouc
9 小时以前 ccb810bdcabb3a10b7463acbdb0aa66c44d9c0bc
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { useTranslate, useAuthProvider, Title, useNotify } from 'react-admin';
import { Box, Typography, LinearProgress, Stack, Grid } from '@mui/material';
import React, { useState, useRef, useEffect, useMemo } from "react";
import SensorOccupiedIcon from '@mui/icons-material/SensorOccupied';
import CardWithIcon from '../components/CardWithIcon';
import CommentIcon from '@mui/icons-material/Comment';
import WifiIcon from '@mui/icons-material/Wifi';
import { useTheme } from '@mui/material/styles';
import { useNavigate } from 'react-router-dom';
import { getSystemDicts } from '@/api/auth'
import { WordEffect } from './WordEffect';
import request from '@/utils/request';
import Welcome from "./Welcome";
import NbChart from "./NbChart";
import NbList from "./NbList";
import NbCard from "./NbCard";
import NbPie from './NbPie';
 
const styles = {
    flex: { display: 'flex' },
    flexColumn: { display: 'flex', flexDirection: 'column' },
    leftCol: { flex: 1, },
    rightCol: { flex: 1, },
    singleCol: { marginTop: '1em', marginBottom: '1em' },
};
 
const Dashboard = () => {
    const authProvider = useAuthProvider();
    const navigate = useNavigate();
    const theme = useTheme();
    const translate = useTranslate();
 
    useEffect(() => {
        authProvider.checkAuth().catch(() => {
            navigate('/login');
        })
        getSystemDicts().then((data) => {
            localStorage.setItem("sys_dicts", JSON.stringify(data));
        })
    }, [authProvider, navigate]);
 
    return (
        <>
            <Title title={"menu.dashboard"} />
            <Welcome />
            <DashboardSummaryView />
            <div
                style={{
                    boxSizing: 'border-box',
                    display: 'flex',
                    width: '100%',
                    height: '100%',
                    flexDirection: 'column',
                    justifyContent: 'flex-start',
                    alignItems: 'flex-start',
                    padding: '2rem 1rem',
                }}
            >
                {/* <WordEffect
                    words={translate('page.welcome.index')}
                    color={theme.palette.mode === 'light' ? '#666' : '#eeeeee'}
                />
                <WordEffect
                    words={translate('page.welcome.tech')}
                    color={theme.palette.mode === 'light' ? '#666' : '#eeeeee'}
                /> */}
            </div>
        </>
    )
}
 
const DashboardSummaryView = () => {
    const translate = useTranslate();
    const notify = useNotify();
    const [statistic, setStatistic] = useState({});
    const [stock, setStock] = useState([]);
    const [deadStock, setDeadStock] = useState([]);
    const [locUsage, setLocUsages] = useState([]);
    const [tasks, setTasks] = useState([]);
    const [total, setTotal] = useState(0);
 
 
    useEffect(() => {
        getDashBoardHeader()
        getRecentTrands()
        getRecentStocks()
        getRecentUsage()
        getExcingTasks()
 
    }, [])
 
    const getDashBoardHeader = async () => {
        await request.post('/asnOrder/dashbord/header').then(res => {
            const { code, msg, data } = res?.data;
            console.log(code);
            
            if (code === 200) {
                setStatistic(data);
            } else {
                notify(msg, { type: 'error', messageArgs: { _: msg } });
            }
        }).catch((error) => {
            notify(error.message, { type: 'error', messageArgs: { _: error.message } });
        })
    }
 
    const getRecentStocks = async () => {
        await request.post('/locItem/page', { current: 1, pageSize: 10, orderBy: 'create_time asc' }).then(res => {
            const { code, msg, data } = res?.data;
            if (code === 200) {
                setDeadStock(data?.records);
            } else {
                notify(msg, { type: 'error', messageArgs: { _: msg } });
            }
        }).catch((error) => {
            notify(error.message, { type: 'error', messageArgs: { _: error.message } });
        })
    }
 
    const getExcingTasks = async () => {
        await request.post('/task/page', { current: 1, pageSize: 100, orderBy: 'sort desc' }).then(res => {
            const { code, msg, data } = res?.data;
            if (code === 200) {
                setTasks(data?.records)
                setTotal(data?.total)
            } else {
                notify(msg, { type: 'error', messageArgs: { _: msg } });
            }
        }).catch((error) => {
            notify(error.message, { type: 'error', messageArgs: { _: error.message } });
        })
    }
 
    const getRecentUsage = () => {
        request.post("/loc/pie/list").then(res => {
            const { code, msg, data } = res?.data;
            if (code === 200) {
                setLocUsages(data?.data)
            } else {
                notify(msg, { type: 'error', messageArgs: { _: msg } });
            }
        }).catch((error) => {
            notify(error.message, { type: 'error', messageArgs: { _: error.message } });
        })
    }
 
    /**
     * 获取库近一个月出入库信息
     */
    const getRecentTrands = async () => {
        await request.post('/asnOrder/stock/trand').then(res => {
            const { code, msg, data } = res.data?.data;
            if (code === 200) {
                setStock(data)
            } else {
                notify(msg, { type: 'error', messageArgs: { _: msg } });
            }
        }).catch((error) => {
            notify(error.message, { type: 'error', messageArgs: { _: error.message } });
        })
    }
 
    return (
        <>
            <Grid container md={12} item>
                <Grid item md={8}>
                    <Box sx={{ display: "flex" }}>
                        <CardWithIcon
                            icon={WifiIcon}
                            subtitle={translate('page.dashboard.header.inStockQty')}
                            title={`${statistic?.inAnf}`}
                            type={"in"}
                            statistic={statistic}
                        />
                        <Spacer />
                        <CardWithIcon
                            icon={SensorOccupiedIcon}
                            subtitle={translate('page.dashboard.header.outStockQty')}
                            title={`${statistic?.outAnf}`}
                            type={"out"}
                            statistic={statistic}
                        />
                    </Box>
                    <Spacer />
                    <Box>
                        <NbChart orders={stock} />
                    </Box>
                    <Spacer />
                    <Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
                        <NbList deadStock={deadStock} />
                        <NbPie locUsage={locUsage} />
                    </Box>
                    <Spacer />
                </Grid>
                <Grid item md={4}>
                    <Box sx={{ display: 'flex' }}>
                        <Spacer />
                        <NbCard
                            icon={CommentIcon}
                            subtitle={translate('page.dashboard.header.taskWorkQty')}
                            title={`${statistic?.taskQty}`}
                            total={total}
                            to={{
                                pathname: '/task',
                                search: JSON.stringify({
                                    filter: JSON.stringify({ status: 1 }),
                                }),
                            }}
                            tasks={tasks}
                        />
                    </Box>
                </Grid>
            </Grid>
        </>
    )
}
 
const Spacer = () => <span style={{ width: '1em' }} />;
 
export default Dashboard;