|
@@ -1,65 +1,154 @@
|
1
|
1
|
import React, { useState, useEffect, useRef } from 'react';
|
2
|
2
|
import { Button, Modal, Select, Form, message } from 'antd';
|
3
|
3
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
4
|
|
-import { addDevice, deleteDevice } from '@/services/device';
|
|
4
|
+import {
|
|
5
|
+ addDevice,
|
|
6
|
+ deleteDevice,
|
|
7
|
+ syncShenSong,
|
|
8
|
+ addRawDevice,
|
|
9
|
+ deleteRawDevice,
|
|
10
|
+} from '@/services/device';
|
5
|
11
|
import List from './components/List';
|
6
|
12
|
import MaBind from './components/MaBind';
|
7
|
13
|
import FeiFangForm from './components/FeiFangForm';
|
8
|
14
|
|
9
|
15
|
export default (props) => {
|
10
|
|
- // 绑定表单
|
11
|
|
-
|
12
|
16
|
const [open, setOpen] = useState(false);
|
13
|
|
- const [openfeiyang, setOpenFeiYang] = useState(false);
|
|
17
|
+ const [syncing, setSyncing] = React.useState(false);
|
|
18
|
+ const [syncing2, setSyncing2] = React.useState(false);
|
14
|
19
|
const [device, setDevice] = useState();
|
15
|
20
|
const listRef = useRef();
|
|
21
|
+ const actRef = useRef();
|
|
22
|
+
|
|
23
|
+ const modalTitle = actRef.current === 'add' ? '新增设备' : '绑定农机';
|
16
|
24
|
|
17
|
25
|
// 绑定农机
|
18
|
26
|
const onBind = ({ machineryId }) => {
|
|
27
|
+ const hide = message.loading('请稍候...', 0);
|
19
|
28
|
const data = { ...device, machineryId };
|
20
|
|
- addDevice(data).then((res) => {
|
21
|
|
- setOpen(false);
|
22
|
|
- message.success(`绑定成功`);
|
23
|
|
- listRef.current.reload();
|
24
|
|
- });
|
|
29
|
+ addDevice(data)
|
|
30
|
+ .then((res) => {
|
|
31
|
+ hide();
|
|
32
|
+ setOpen(false);
|
|
33
|
+ message.success(`绑定成功`);
|
|
34
|
+ listRef.current.reload();
|
|
35
|
+ })
|
|
36
|
+ .catch((err) => {
|
|
37
|
+ hide();
|
|
38
|
+ message.error(err.message || err);
|
|
39
|
+ });
|
25
|
40
|
};
|
26
|
41
|
|
27
|
42
|
// 解绑
|
28
|
43
|
const unBind = (deviceId) => {
|
|
44
|
+ const hide = message.loading('请稍候...', 0);
|
29
|
45
|
deleteDevice(deviceId)
|
30
|
46
|
.then(() => {
|
31
|
|
- // setLoading(false);
|
|
47
|
+ hide();
|
32
|
48
|
message.success(`解绑成功`);
|
33
|
49
|
listRef.current.reload();
|
34
|
50
|
})
|
35
|
51
|
.catch((err) => {
|
36
|
|
- // setLoading(false);
|
|
52
|
+ hide();
|
37
|
53
|
message.error(err.message || err);
|
38
|
54
|
});
|
39
|
55
|
};
|
40
|
56
|
|
41
|
|
- // 设备农机绑定或者解绑操作
|
42
|
|
- const onBindOpt = (row) => {
|
|
57
|
+ // 删除设备
|
|
58
|
+ const onDelete = (row) => {
|
|
59
|
+ const hide = message.loading('请稍候...', 0);
|
|
60
|
+ deleteRawDevice(row.deviceId)
|
|
61
|
+ .then(() => {
|
|
62
|
+ hide();
|
|
63
|
+ message.success('删除成功');
|
|
64
|
+ listRef.current.reload();
|
|
65
|
+ })
|
|
66
|
+ .catch((err) => {
|
|
67
|
+ hide();
|
|
68
|
+ message.error(err.message || err);
|
|
69
|
+ });
|
|
70
|
+ };
|
|
71
|
+
|
|
72
|
+ // 新增飞防设备
|
|
73
|
+ const onAddDevice = ({ deviceNo, deviceKind = 'feifang' }) => {
|
|
74
|
+ setSyncing2(true);
|
|
75
|
+ addRawDevice({ deviceKind, deviceNo })
|
|
76
|
+ .then((res) => {
|
|
77
|
+ message.success('添加设备成功');
|
|
78
|
+ setSyncing2(false);
|
|
79
|
+ setOpen(false);
|
|
80
|
+ listRef.current.reload();
|
|
81
|
+ })
|
|
82
|
+ .catch((err) => {});
|
|
83
|
+ };
|
|
84
|
+
|
|
85
|
+ // 同步深松
|
|
86
|
+ const onSyncShenSong = () => {
|
|
87
|
+ setSyncing(true);
|
|
88
|
+ syncShenSong()
|
|
89
|
+ .then((res) => {
|
|
90
|
+ setSyncing(false);
|
|
91
|
+ listRef.current.reload();
|
|
92
|
+ message.success('同步完成');
|
|
93
|
+ })
|
|
94
|
+ .catch(() => {
|
|
95
|
+ setSyncing(false);
|
|
96
|
+ });
|
|
97
|
+ };
|
|
98
|
+
|
|
99
|
+ // 同步飞防
|
|
100
|
+ const onSyncFeiFang = () => {
|
|
101
|
+ actRef.current = 'add';
|
|
102
|
+ setOpen(true);
|
|
103
|
+ };
|
|
104
|
+
|
|
105
|
+ // 设备操作
|
|
106
|
+ const onOperate = (row, act) => {
|
|
107
|
+ actRef.current = act;
|
43
|
108
|
setDevice({ ...row });
|
44
|
109
|
|
45
|
|
- if (!row.machineryId) {
|
46
|
|
- // 农机ID 不存在, 说明是绑定业务
|
47
|
|
- setOpen(true);
|
48
|
|
- } else {
|
49
|
|
- unBind(row.deviceId);
|
|
110
|
+ switch (act) {
|
|
111
|
+ case 'bind':
|
|
112
|
+ setOpen(true);
|
|
113
|
+ break;
|
|
114
|
+ case 'unbind':
|
|
115
|
+ unBind(row.deviceId);
|
|
116
|
+ break;
|
|
117
|
+ case 'delete':
|
|
118
|
+ onDelete(row);
|
|
119
|
+ break;
|
|
120
|
+ default:
|
|
121
|
+ break;
|
50
|
122
|
}
|
51
|
123
|
};
|
52
|
124
|
|
53
|
|
- //同步飞防弹窗
|
54
|
|
- const onFeiFang = () => {
|
55
|
|
- setOpenFeiYang(true);
|
56
|
|
- }
|
57
|
|
-
|
58
|
125
|
return (
|
59
|
126
|
<PageHeaderWrapper>
|
60
|
|
- <List ref={listRef} onBindOpt={onBindOpt} onFeiFang={onFeiFang} onSyncDevice={console.log} />
|
61
|
|
- <MaBind open={open} device={device} onCancel={() => setOpen(false)} onFinish={onBind} />
|
62
|
|
- <FeiFangForm openfeiyang={openfeiyang} onCancel={() => setOpenFeiYang(false)} />
|
|
127
|
+ <List
|
|
128
|
+ ref={listRef}
|
|
129
|
+ onOperate={onOperate}
|
|
130
|
+ toolBar={[
|
|
131
|
+ <Button ghost key={1} type="primary" loading={syncing} onClick={onSyncShenSong}>
|
|
132
|
+ 同步深松
|
|
133
|
+ </Button>,
|
|
134
|
+ <Button ghost key={3} type="primary" loading={syncing2} onClick={onSyncFeiFang}>
|
|
135
|
+ 同步飞防
|
|
136
|
+ </Button>,
|
|
137
|
+ ]}
|
|
138
|
+ />
|
|
139
|
+ <Modal
|
|
140
|
+ title={modalTitle}
|
|
141
|
+ visible={open}
|
|
142
|
+ maskClosable={false}
|
|
143
|
+ footer={null}
|
|
144
|
+ onCancel={() => setOpen(false)}
|
|
145
|
+ >
|
|
146
|
+ {actRef.current === 'add' ? (
|
|
147
|
+ <FeiFangForm onCancel={() => setOpen(false)} onFinish={onAddDevice} />
|
|
148
|
+ ) : (
|
|
149
|
+ <MaBind onCancel={() => setOpen(false)} onFinish={onBind} />
|
|
150
|
+ )}
|
|
151
|
+ </Modal>
|
63
|
152
|
</PageHeaderWrapper>
|
64
|
153
|
);
|
65
|
154
|
};
|