|
@@ -1,232 +0,0 @@
|
1
|
|
-import React, { useState, useEffect, useRef } from 'react';
|
2
|
|
-import { Button, Modal, Select, Form, message } from 'antd';
|
3
|
|
-import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
4
|
|
-import moment from 'moment';
|
5
|
|
-import PageTable from '@/components/PageTable';
|
6
|
|
-import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
|
7
|
|
-import { getMachineryList } from '@/services/machinery';
|
8
|
|
-import { getMachineryTypeList } from '@/services/machineryType';
|
9
|
|
-import { Link } from 'umi';
|
10
|
|
-
|
11
|
|
-const formatterTime = (val) => {
|
12
|
|
- return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
|
13
|
|
-};
|
14
|
|
-
|
15
|
|
-export default (props) => {
|
16
|
|
- // 绑定表单
|
17
|
|
- const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
18
|
|
- const [form] = Form.useForm();
|
19
|
|
- const [editModal, setEditModal] = useState(false);
|
20
|
|
- const [loading, setLoading] = useState(false);
|
21
|
|
- const [machineryId, setMachineryId] = useState();
|
22
|
|
- const [device, setDeviceList] = useState();
|
23
|
|
- const actionRef = useRef();
|
24
|
|
- const [machineryTypeList, setMachineryTypeList] = useState([]);
|
25
|
|
- const [typeId, setTypeId] = useState();
|
26
|
|
- const [machineryList, setMachineryList] = useState([]);
|
27
|
|
- const { Option } = Select;
|
28
|
|
- const FormItem = Form.Item;
|
29
|
|
-
|
30
|
|
- //列表编辑
|
31
|
|
- const handelEdit = (val) => {
|
32
|
|
- if (val.machineryId != null) {
|
33
|
|
- setEditModal(false);
|
34
|
|
- const title = '确认当前设备要解绑"' + val.machineryName + '"农机设备吗?';
|
35
|
|
- Modal.confirm({
|
36
|
|
- title: title,
|
37
|
|
- okText: '确认',
|
38
|
|
- cancelText: '取消',
|
39
|
|
- onOk () {
|
40
|
|
- deleteDevice(val.deviceId)
|
41
|
|
- .then(() => {
|
42
|
|
- setLoading(false);
|
43
|
|
- message.success(`解绑成功`);
|
44
|
|
- onCancel();
|
45
|
|
- actionRef.current.reload();
|
46
|
|
-
|
47
|
|
- })
|
48
|
|
- .catch((err) => {
|
49
|
|
- setLoading(false);
|
50
|
|
- message.error(err.message || err);
|
51
|
|
- });
|
52
|
|
- }
|
53
|
|
- })
|
54
|
|
- } else {
|
55
|
|
- setEditModal(true);
|
56
|
|
- setDeviceList(val);
|
57
|
|
- }
|
58
|
|
-
|
59
|
|
- form.setFieldsValue(val);
|
60
|
|
- };
|
61
|
|
-
|
62
|
|
- //绑定弹窗关闭
|
63
|
|
- const onCancel = () => {
|
64
|
|
- setEditModal(false);
|
65
|
|
- };
|
66
|
|
-
|
67
|
|
- // 绑定提交
|
68
|
|
- const Submit = (values) => {
|
69
|
|
- let params = { ...device, ...values };
|
70
|
|
- setLoading(true);
|
71
|
|
- addDevice(params).then((res) => {
|
72
|
|
- setLoading(false);
|
73
|
|
- message.success(`绑定成功`);
|
74
|
|
- actionRef.current.reload();
|
75
|
|
- onCancel();
|
76
|
|
- });
|
77
|
|
- };
|
78
|
|
-
|
79
|
|
- useEffect(() => {
|
80
|
|
- getMachineryTypeList({ pageSize: 999 }).then((res) => {
|
81
|
|
- setMachineryTypeList(res.records);
|
82
|
|
- }).catch((err) => {
|
83
|
|
- console.log(err.message)
|
84
|
|
- });
|
85
|
|
- }, []);
|
86
|
|
-
|
87
|
|
- useEffect(() => {
|
88
|
|
- if (typeId) {
|
89
|
|
- getMachineryList({ typeId }).then((e) => {
|
90
|
|
- setMachineryList(e.records);
|
91
|
|
- }).catch((err) => {
|
92
|
|
- console.log(err.message)
|
93
|
|
- });
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- }, [typeId])
|
97
|
|
-
|
98
|
|
- const columns = [
|
99
|
|
- {
|
100
|
|
- title: '行号',
|
101
|
|
- dataIndex: 'deviceId',
|
102
|
|
- key: 'deviceId',
|
103
|
|
- },
|
104
|
|
- {
|
105
|
|
- title: '设备编号',
|
106
|
|
- dataIndex: 'deviceNo',
|
107
|
|
- key: 'deviceNo',
|
108
|
|
- search: false,
|
109
|
|
- },
|
110
|
|
- {
|
111
|
|
- title: '设备类型',
|
112
|
|
- dataIndex: 'deviceType',
|
113
|
|
- key: 'deviceType',
|
114
|
|
- valueEnum: {
|
115
|
|
- shensong: {
|
116
|
|
- text: '深松',
|
117
|
|
- },
|
118
|
|
- feifang: {
|
119
|
|
- text: '飞防',
|
120
|
|
- },
|
121
|
|
- },
|
122
|
|
- // request: () => queryTable(getDeviceList)(),
|
123
|
|
- },
|
124
|
|
- {
|
125
|
|
- title: '在线状态',
|
126
|
|
- dataIndex: 'onlineStatus',
|
127
|
|
- key: 'onlineStatus',
|
128
|
|
- valueEnum: {
|
129
|
|
- 1: {
|
130
|
|
- text: '在线',
|
131
|
|
- },
|
132
|
|
- 0: {
|
133
|
|
- text: '离线',
|
134
|
|
- },
|
135
|
|
- },
|
136
|
|
- // render: (_, record) => {
|
137
|
|
- // return record.onlineStatus === 1 ? '在线' : '离线';
|
138
|
|
- // },
|
139
|
|
- },
|
140
|
|
- {
|
141
|
|
- title: '注册时间',
|
142
|
|
- dataIndex: 'createDate',
|
143
|
|
- key: 'createDate',
|
144
|
|
- render: formatterTime,
|
145
|
|
- search: false,
|
146
|
|
- width: 240,
|
147
|
|
- },
|
148
|
|
- {
|
149
|
|
- title: '绑定农机',
|
150
|
|
- dataIndex: 'machineryId',
|
151
|
|
- key: 'machineryId',
|
152
|
|
- search: false,
|
153
|
|
- },
|
154
|
|
- {
|
155
|
|
- title: '操作',
|
156
|
|
- valueType: 'option',
|
157
|
|
- width: 160,
|
158
|
|
- render: (_, record) => [
|
159
|
|
- <Link to={`/Machinery/OperationStatistics`} key={2} >查看作业</Link>,
|
160
|
|
- <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
|
161
|
|
- {record.machineryId === null ? '绑定' : '解绑'}
|
162
|
|
- </Button>,
|
163
|
|
- ],
|
164
|
|
- },
|
165
|
|
- ];
|
166
|
|
-
|
167
|
|
- return (
|
168
|
|
- <PageHeaderWrapper>
|
169
|
|
- <PageTable
|
170
|
|
- request={getDeviceList}
|
171
|
|
- columns={columns}
|
172
|
|
- actionRef={actionRef}
|
173
|
|
- rowKey="deviceId"
|
174
|
|
- options={false}
|
175
|
|
- toolBarRender={() => [
|
176
|
|
- <Button
|
177
|
|
- key="1"
|
178
|
|
- type="primary"
|
179
|
|
- >
|
180
|
|
- +同步设备信息
|
181
|
|
- </Button>,
|
182
|
|
- ]}
|
183
|
|
- scroll={{ x: 1000 }}
|
184
|
|
- />
|
185
|
|
- <Modal
|
186
|
|
- forceRender
|
187
|
|
- title="绑定农机"
|
188
|
|
- visible={editModal}
|
189
|
|
- onCancel={onCancel}
|
190
|
|
- keyboard={false}
|
191
|
|
- maskClosable={false}
|
192
|
|
- destroyOnClose={true}
|
193
|
|
- footer={null}
|
194
|
|
- machineryId={machineryId}
|
195
|
|
- >
|
196
|
|
- <Form {...formItemLayout} onFinish={Submit} form={form}>
|
197
|
|
- <FormItem label="农机分类" name="typeId" rules={[{ required: true, message: '请选择农机分类' }]}>
|
198
|
|
- <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
|
199
|
|
- {machineryTypeList.map((item) => (
|
200
|
|
- <Option value={item.typeId} key={item.typeId}>
|
201
|
|
- {item.name}
|
202
|
|
- </Option>
|
203
|
|
- ))}
|
204
|
|
- </Select>
|
205
|
|
- </FormItem>
|
206
|
|
- <FormItem label="选择农机" name="machineryId" rules={[{ required: true, message: '请选择农机名' }]}>
|
207
|
|
- <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
|
208
|
|
- {machineryList.map((item) => (
|
209
|
|
- <Option value={item.machineryId} key={item.machineryId}>
|
210
|
|
- {item.name}
|
211
|
|
- </Option>
|
212
|
|
- ))}
|
213
|
|
- </Select>
|
214
|
|
- </FormItem>
|
215
|
|
- <FormItem label=" " colon={false}>
|
216
|
|
- <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
|
217
|
|
- 取消
|
218
|
|
- </Button>
|
219
|
|
- <Button
|
220
|
|
- type="primary"
|
221
|
|
- loading={loading}
|
222
|
|
- htmlType="Submit"
|
223
|
|
- style={{ marginTop: '2em', marginLeft: '2em' }}
|
224
|
|
- >
|
225
|
|
- 确认
|
226
|
|
- </Button>
|
227
|
|
- </FormItem>
|
228
|
|
- </Form>
|
229
|
|
- </Modal>
|
230
|
|
- </PageHeaderWrapper>
|
231
|
|
- );
|
232
|
|
-};
|