Yansen 2 years ago
parent
commit
d6f99cbe3f

+ 24
- 10
src/pages/Machinery/OperationStatistics/Detail.jsx View File

@@ -1,24 +1,38 @@
1 1
 import React from 'react';
2 2
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
3
-import { Card, Divider } from 'antd';
3
+import { Col, Row, Divider } from 'antd';
4
+import { getMachineryDetail } from '@/services/machinery';
4 5
 import Summary from './components/Summary';
5 6
 import Machines from './components/Machines';
7
+import MaImg from './components/MaImg';
6 8
 
7 9
 export default (props) => {
8 10
   const { location } = props;
9
-  const { user: userId } = location.query || {};
11
+  const { user, machineryId } = location.query || {};
12
+
13
+  const [current, setCurrent] = React.useState({});
14
+
15
+  const userId = user || current.ownerId;
16
+
17
+  React.useEffect(() => {
18
+    if (machineryId) {
19
+      getMachineryDetail(machineryId).then(setCurrent);
20
+    }
21
+  }, [machineryId]);
10 22
 
11 23
   return (
12 24
     <PageHeaderWrapper>
13
-      <Card>
14
-        <p>
25
+      <div style={{ display: 'flex' }}>
26
+        <div style={{ width: '360px', flex: 'none' }}>
15 27
           <Summary userId={userId} />
16
-        </p>
17
-        <Divider />
18
-        <p>
19
-          <Machines userId={userId} />
20
-        </p>
21
-      </Card>
28
+          <div style={{ marginTop: '24px' }}>
29
+            <MaImg machine={current} />
30
+          </div>
31
+        </div>
32
+        <div style={{ flex: '1', marginLeft: '24px' }}>
33
+          <Machines current={current} setCurrent={setCurrent} userId={userId} />
34
+        </div>
35
+      </div>
22 36
     </PageHeaderWrapper>
23 37
   );
24 38
 };

+ 16
- 0
src/pages/Machinery/OperationStatistics/components/MaImg.jsx View File

@@ -0,0 +1,16 @@
1
+import React from 'react';
2
+import { Card, Empty } from 'antd';
3
+
4
+export default (props) => {
5
+  const { machine = {} } = props;
6
+
7
+  return (
8
+    <Card title={machine.name}>
9
+      {machine.thumb ? (
10
+        <img alt="" src={machine.thumb} style={{ width: '100%' }} />
11
+      ) : (
12
+        <Empty description="暂无农机" />
13
+      )}
14
+    </Card>
15
+  );
16
+};

+ 107
- 0
src/pages/Machinery/OperationStatistics/components/MaJob.jsx View File

@@ -0,0 +1,107 @@
1
+import React from 'react';
2
+import { Button, Card, Table, message, Descriptions, Col, Row } from 'antd';
3
+import { getDeviceJobByOrg, exportDeviceJobByOrg } from '@/services/job';
4
+
5
+export default (props) => {
6
+  const { machine, userId } = props;
7
+
8
+  const columns = [
9
+    {
10
+      title: '设备类型',
11
+      dataIndex: 'deviceKind',
12
+      key: 'deviceKind',
13
+      render: (t) => (t === 'shensong' ? '深松' : t === 'feifang' ? '飞防' : '-'),
14
+    },
15
+    {
16
+      title: '设备编号',
17
+      dataIndex: 'deviceNo',
18
+      key: 'deviceNo',
19
+    },
20
+    {
21
+      title: '作业面积(亩)',
22
+      dataIndex: 'jobArea',
23
+      key: 'jobArea',
24
+    },
25
+    {
26
+      title: '作业时间',
27
+      dataIndex: 'jobTime',
28
+      key: 'jobTime',
29
+    },
30
+  ];
31
+
32
+  const [loading, setLoading] = React.useState(false);
33
+  const [list, setList] = React.useState([]);
34
+  const [total, setTotal] = React.useState(0);
35
+  const [page, setPage] = React.useState({ current: 1, pageSize: 10, total: 0 });
36
+
37
+  const pagination = React.useMemo(
38
+    () => ({
39
+      ...page,
40
+      showTotal: (total, range) => `总计 ${total} 条`,
41
+      onChange: (page, pageSize) => {
42
+        setPage({
43
+          current: page,
44
+          pageSize,
45
+          total: 0,
46
+        });
47
+
48
+        queryData({
49
+          machineryId: machine.machineryId,
50
+          userId,
51
+          pageNum: page,
52
+          pageSize,
53
+        });
54
+      },
55
+    }),
56
+    [page, machine, userId],
57
+  );
58
+
59
+  const queryData = (params) => {
60
+    setLoading(true);
61
+    getDeviceJobByOrg({ ...params, startDate: '2022-01-01', endDate: '2099-12-31' })
62
+      .then((res) => {
63
+        setLoading(false);
64
+        const { list: dtList, totalArea } = res;
65
+        setList(dtList.records || []);
66
+        setTotal(totalArea || 0);
67
+        setPage({
68
+          current: dtList.current,
69
+          pageSize: dtList.size,
70
+          total: dtList.total,
71
+        });
72
+      })
73
+      .catch((err) => {
74
+        console.error(err);
75
+        setLoading(false);
76
+      });
77
+  };
78
+
79
+  React.useEffect(() => {
80
+    if (userId && machine) {
81
+      const { machineryId } = machine;
82
+      queryData({
83
+        machineryId,
84
+        userId,
85
+        pageNum: 1,
86
+        pageSize: 10,
87
+      });
88
+    }
89
+  }, [machine, userId]);
90
+
91
+  return (
92
+    <div>
93
+      <div style={{ textAlign: 'left', marginBottom: '16px', fontSize: '16px' }}>
94
+        <span>总作业面积 </span>
95
+        <strong>{total}</strong>
96
+        <span> 亩</span>
97
+      </div>
98
+      <Table
99
+        loading={loading}
100
+        rowKey="jobNo"
101
+        columns={columns}
102
+        dataSource={list}
103
+        pagination={pagination}
104
+      />
105
+    </div>
106
+  );
107
+};

+ 24
- 7
src/pages/Machinery/OperationStatistics/components/Machines.jsx View File

@@ -1,19 +1,37 @@
1 1
 import React from 'react';
2
-import { Spin, Tabs } from 'antd';
2
+import { Card, Tabs } from 'antd';
3
+import MaJob from './MaJob';
3 4
 import { getMachineryListByUser } from '@/services/device';
4 5
 
5 6
 export default (props) => {
6
-  const { userId } = props;
7
+  const { userId, current, setCurrent } = props;
7 8
 
8 9
   const [loading, setLoading] = React.useState(false);
9 10
   const [machines, setMachines] = React.useState([]);
11
+  const [activeTab, setActiveTab] = React.useState();
12
+
13
+  const tabList = React.useMemo(() => {
14
+    return machines.map((x) => ({ key: x.machineryId, tab: x.name }));
15
+  }, [machines]);
16
+
17
+  const onTabChange = (key) => {
18
+    setCurrent(machines.filter((x) => x.machineryId === key)[0]);
19
+  };
20
+
21
+  React.useEffect(() => {
22
+    if (current) {
23
+      setActiveTab(current.machineryId);
24
+    }
25
+  }, [current]);
10 26
 
11 27
   React.useEffect(() => {
12 28
     if (userId) {
13 29
       setLoading(true);
14 30
       getMachineryListByUser(userId)
15 31
         .then((res) => {
16
-          setMachines(res);
32
+          const list = res || [];
33
+          setMachines(list);
34
+          setCurrent(list[0] || {});
17 35
           setLoading(false);
18 36
         })
19 37
         .catch((err) => {
@@ -24,9 +42,8 @@ export default (props) => {
24 42
   }, [userId]);
25 43
 
26 44
   return (
27
-    <Spin spinning={loading}>
28
-      <h3 style={{ fontWeight: 700 }}>作业信息</h3>
29
-      <Tabs></Tabs>
30
-    </Spin>
45
+    <Card loading={loading} tabList={tabList} activeTabKey={activeTab} onTabChange={onTabChange}>
46
+      <MaJob machine={current} userId={userId} />
47
+    </Card>
31 48
   );
32 49
 };

+ 16
- 7
src/pages/Machinery/OperationStatistics/components/Summary.jsx View File

@@ -1,7 +1,9 @@
1 1
 import React from 'react';
2
-import { Descriptions, Spin } from 'antd';
2
+import { Card, Avatar, Spin } from 'antd';
3 3
 import { getUserDetail } from '@/services/user';
4 4
 
5
+const defAva = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png';
6
+
5 7
 export default (props) => {
6 8
   const { userId } = props;
7 9
 
@@ -24,11 +26,18 @@ export default (props) => {
24 26
   }, [userId]);
25 27
 
26 28
   return (
27
-    <Spin spinning={loading}>
28
-      <Descriptions title="用户信息">
29
-        <Descriptions.Item label="姓名">{user.userName}</Descriptions.Item>
30
-        <Descriptions.Item label="电话">{user.phone}</Descriptions.Item>
31
-      </Descriptions>
32
-    </Spin>
29
+    <Card
30
+      loading={loading}
31
+      cover={
32
+        <div style={{ margin: '0 auto', marginTop: '2em', width: '128px' }}>
33
+          <Avatar src={user.avatar || defAva} size={128} />
34
+        </div>
35
+      }
36
+    >
37
+      <Card.Meta
38
+        title={<div style={{ textAlign: 'center' }}>{user.userName}</div>}
39
+        description={<div style={{ textAlign: 'center' }}>{user.phone}</div>}
40
+      />
41
+    </Card>
33 42
   );
34 43
 };

+ 0
- 0
src/pages/Machinery/OperationStatistics/components/useJob.jsx View File