|
@@ -1,17 +1,22 @@
|
1
|
1
|
import { useState, useEffect } from 'react';
|
2
|
|
-import { Form, Input, Card, DatePicker, Select, InputNumber, message, Button } from 'antd';
|
3
|
2
|
import { history } from 'umi';
|
|
3
|
+import { Form, Input, Drawer, DatePicker, Select, InputNumber, message, Button, List, Card, Descriptions } from 'antd';
|
4
|
4
|
import ProCard from '@ant-design/pro-card';
|
|
5
|
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
|
6
|
+import moment from 'moment';
|
5
|
7
|
import ExtendContent from '@/components/ExtendContent';
|
6
|
8
|
import { UploadImage, UploadImageList } from '@/components/Upload';
|
7
|
9
|
import Money from '@/components/Money';
|
8
|
10
|
import { addMachinery, updateMachinery, getMachineryDetail } from '@/services/machinery';
|
9
|
11
|
import { getMachineryTypeList } from '@/services/machineryType';
|
10
|
12
|
import { getRegionList } from '@/services/region';
|
|
13
|
+import { getDeviceList, getdeviceDetail, getTerminalDeviceList, addDevice } from '@/services/device';
|
11
|
14
|
import { getCooperativeList } from '@/services/cooperative';
|
12
|
|
-import moment from 'moment';
|
|
15
|
+import selectedImg from '@/assets/selectedImg.png'
|
|
16
|
+import './style.less'
|
13
|
17
|
|
14
|
18
|
const { Option } = Select;
|
|
19
|
+const { Search } = Input;
|
15
|
20
|
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
16
|
21
|
|
17
|
22
|
const goBack = () => {
|
|
@@ -37,7 +42,6 @@ export default (props) => {
|
37
|
42
|
newData = { ...data, buyDate: data.buyDate.format('YYYY-MM-DD HH:mm:ss') };
|
38
|
43
|
}
|
39
|
44
|
setLoading(true);
|
40
|
|
-
|
41
|
45
|
if (id) {
|
42
|
46
|
updateMachinery(id, newData)
|
43
|
47
|
.then(() => {
|
|
@@ -63,7 +67,6 @@ export default (props) => {
|
63
|
67
|
}
|
64
|
68
|
};
|
65
|
69
|
|
66
|
|
- const onDateChange = () => { };
|
67
|
70
|
const imageInput = (image) => {
|
68
|
71
|
return {
|
69
|
72
|
uid: image.imageId,
|
|
@@ -78,6 +81,64 @@ export default (props) => {
|
78
|
81
|
url: image.url,
|
79
|
82
|
};
|
80
|
83
|
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ //设备信息
|
|
87
|
+ const [deviceForm] = Form.useForm();
|
|
88
|
+ const [visible, setVisible] = useState(false);
|
|
89
|
+ const [terminalId, setTerminalId] = useState();
|
|
90
|
+ //设备列表
|
|
91
|
+ const [deviceList, setDeviceList] = useState([]);
|
|
92
|
+ const [device, setDevice] = useState();
|
|
93
|
+ const [bind, setBind] = useState(false);
|
|
94
|
+ const [deviceLoading, setDeviceLoading] = useState(false);
|
|
95
|
+ const [deviceDetail, setDeviceDetail] = useState();
|
|
96
|
+
|
|
97
|
+ //弹出设备列表抽屉
|
|
98
|
+ const changeCamera = () => {
|
|
99
|
+ if (device != null) {
|
|
100
|
+ getTerminalDeviceList(device.deviceId).then((res) => {
|
|
101
|
+ setDeviceList([res]);
|
|
102
|
+ })
|
|
103
|
+ }
|
|
104
|
+ setVisible(true);
|
|
105
|
+ }
|
|
106
|
+ const handleClose = () => {
|
|
107
|
+ setVisible(false);
|
|
108
|
+ }
|
|
109
|
+ const onSearch = (val) => { setTerminalId(val) }
|
|
110
|
+ //选中设备
|
|
111
|
+ const handleSelect = (item) => {
|
|
112
|
+ setDevice(item);
|
|
113
|
+ }
|
|
114
|
+ const handleOk = () => {
|
|
115
|
+ if (device != null) {
|
|
116
|
+ setBind(true)
|
|
117
|
+ }
|
|
118
|
+ handleClose();
|
|
119
|
+ }
|
|
120
|
+ const submitDevice = (data) => {
|
|
121
|
+ if (!bind) {
|
|
122
|
+ message.info('请绑定摄像头');
|
|
123
|
+ return;
|
|
124
|
+ }
|
|
125
|
+ let config = `{'deviceId':${device.deviceId},'channel':${data.channel},'netType':${data.netType}}`;
|
|
126
|
+ setDeviceLoading(true);
|
|
127
|
+ addDevice({ ...deviceDetail, machineryId: id, apiConfig: config }).then((res) => {
|
|
128
|
+ message.success('保存成功!');
|
|
129
|
+ setDeviceLoading(false);
|
|
130
|
+ goBack();
|
|
131
|
+ }).catch((err) => {
|
|
132
|
+ setDeviceLoading(false);
|
|
133
|
+ console.log(err.message);
|
|
134
|
+ })
|
|
135
|
+ }
|
|
136
|
+ useEffect(() => {
|
|
137
|
+ getDeviceList({ terminalId: terminalId, pageSize: 500 }).then((res) => {
|
|
138
|
+ setDeviceList(res.records);
|
|
139
|
+ })
|
|
140
|
+ }, [terminalId])
|
|
141
|
+
|
81
|
142
|
useEffect(() => {
|
82
|
143
|
getMachineryTypeList({ pageSize: 999 }).then((res) => {
|
83
|
144
|
setMachineryTypeList(res.records);
|
|
@@ -94,19 +155,39 @@ export default (props) => {
|
94
|
155
|
}).catch((err) => {
|
95
|
156
|
console.log(err.message)
|
96
|
157
|
});
|
|
158
|
+ }, [])
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+ useEffect(() => {
|
97
|
162
|
if (id) {
|
|
163
|
+ //编辑时获取基本信息内容
|
98
|
164
|
getMachineryDetail(id).then((res) => {
|
99
|
165
|
form.setFieldsValue({ ...res, buyDate: res.buyDate ? moment(res.buyDate, 'YYYY-MM-DD') : null });
|
100
|
166
|
}).catch((err) => {
|
101
|
167
|
console.log(err.message)
|
102
|
168
|
});
|
|
169
|
+ //获取设备信息内容
|
|
170
|
+ getdeviceDetail(id).then((res) => {
|
|
171
|
+ setDeviceDetail(res);
|
|
172
|
+ if (res) {
|
|
173
|
+ //eval('(' + res.apiConfig + ')') json字符串转普通对象
|
|
174
|
+ deviceForm.setFieldsValue(eval('(' + res.apiConfig + ')'));
|
|
175
|
+ if (res && res.deviceId != null) {
|
|
176
|
+ //获取绑定设备详情
|
|
177
|
+ getTerminalDeviceList(eval('(' + res.apiConfig + ')').deviceId).then((res) => {
|
|
178
|
+ setDevice(res);
|
|
179
|
+ setBind(true)
|
|
180
|
+ })
|
|
181
|
+ }
|
|
182
|
+ }
|
|
183
|
+ })
|
103
|
184
|
}
|
104
|
185
|
}, [id]);
|
105
|
186
|
|
106
|
187
|
return (
|
107
|
|
- <Card>
|
108
|
|
- <ProCard tabs={{ type: 'card' }}>
|
109
|
|
- <ProCard.TabPane key={1} tab="农机编辑">
|
|
188
|
+ <PageHeaderWrapper>
|
|
189
|
+ <ProCard tabs={{ type: 'card' }} style={{ minHeight: '700px' }}>
|
|
190
|
+ <ProCard.TabPane key={1} tab="基本信息">
|
110
|
191
|
<Form {...formItemLayout} onFinish={Submit} form={form}>
|
111
|
192
|
<FormItem
|
112
|
193
|
label="农机名"
|
|
@@ -169,7 +250,7 @@ export default (props) => {
|
169
|
250
|
<Money style={{ width: '350px' }} />
|
170
|
251
|
</FormItem>
|
171
|
252
|
<FormItem label="购买时间" name="buyDate">
|
172
|
|
- <DatePicker format="YYYY-MM-DD" onChange={onDateChange} style={{ width: '350px' }} />
|
|
253
|
+ <DatePicker format="YYYY-MM-DD" style={{ width: '350px' }} />
|
173
|
254
|
</FormItem>
|
174
|
255
|
<FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
|
175
|
256
|
<Select placeholder="请选择农机状态" style={{ width: '350px' }}>
|
|
@@ -197,7 +278,93 @@ export default (props) => {
|
197
|
278
|
</FormItem>
|
198
|
279
|
</Form>
|
199
|
280
|
</ProCard.TabPane>
|
|
281
|
+ <ProCard.TabPane key={2} disabled={!id} tab="设备信息">
|
|
282
|
+ <Form {...formItemLayout} onFinish={submitDevice} form={deviceForm}>
|
|
283
|
+ <FormItem label='摄像头' >
|
|
284
|
+ <Button type='link' onClick={changeCamera}>{bind ? '已绑定' : '未绑定'}</Button>
|
|
285
|
+ </FormItem>
|
|
286
|
+ <FormItem
|
|
287
|
+ label="通道号"
|
|
288
|
+ name='channel'
|
|
289
|
+ rules={[{ required: true, message: '请输入通道号' }]}
|
|
290
|
+ >
|
|
291
|
+ <InputNumber min={1} placeholder="请输入通道号" style={{ width: '350px' }} />
|
|
292
|
+ </FormItem>
|
|
293
|
+ <FormItem
|
|
294
|
+ label="网络类型"
|
|
295
|
+ name='netType'
|
|
296
|
+ rules={[{ required: true, message: '请选择网络类型' }]}
|
|
297
|
+ >
|
|
298
|
+ <Select placeholder="请选择网络类型" style={{ width: '350px' }}>
|
|
299
|
+ <Option value={0}>内网</Option>
|
|
300
|
+ <Option value={1}>电信</Option>
|
|
301
|
+ <Option value={2}>移动</Option>
|
|
302
|
+ <Option value={3}>联通</Option>
|
|
303
|
+ </Select>
|
|
304
|
+ </FormItem>
|
|
305
|
+ <FormItem label=" " colon={false}>
|
|
306
|
+ <Button type="default" onClick={goBack}>
|
|
307
|
+ 返回
|
|
308
|
+ </Button>
|
|
309
|
+ <Button
|
|
310
|
+ type="primary"
|
|
311
|
+ loading={deviceLoading}
|
|
312
|
+ htmlType="submit"
|
|
313
|
+ style={{ marginLeft: '4em' }}
|
|
314
|
+ >
|
|
315
|
+ 保存
|
|
316
|
+ </Button>
|
|
317
|
+ </FormItem>
|
|
318
|
+ </Form>
|
|
319
|
+ <Drawer
|
|
320
|
+ title="摄像头列表"
|
|
321
|
+ width={500}
|
|
322
|
+ closable={false}
|
|
323
|
+ onClose={handleClose}
|
|
324
|
+ visible={visible}
|
|
325
|
+ >
|
|
326
|
+ <div style={{ display: 'flex', height: '100%', flexDirection: 'column' }}>
|
|
327
|
+ <Search
|
|
328
|
+ placeholder="请输入终端ID"
|
|
329
|
+ allowClear
|
|
330
|
+ enterButton="搜索"
|
|
331
|
+ size="middle"
|
|
332
|
+ onSearch={onSearch}
|
|
333
|
+ />
|
|
334
|
+ <List split={false} style={{ margin: '16px 0', flex: 1, overflowY: 'auto' }}>
|
|
335
|
+ {
|
|
336
|
+ deviceList.map(item =>
|
|
337
|
+ <List.Item key={item.deviceId} onClick={() => handleSelect(item)}>
|
|
338
|
+ <Card className='listCard'>
|
|
339
|
+ <Descriptions labelStyle={{ width: '72px', display: 'inline-block', textAlign: 'end' }} >
|
|
340
|
+ <Descriptions.Item span={3} label='型号名称'>{item.modelName}</Descriptions.Item>
|
|
341
|
+ <Descriptions.Item span={3} label='协议'>{item.protocol}</Descriptions.Item>
|
|
342
|
+ <Descriptions.Item span={3} label='终端ID'>{item.terminalId}</Descriptions.Item>
|
|
343
|
+ <Descriptions.Item span={3} label='通道列表'>{item.deviceChannelList}</Descriptions.Item>
|
|
344
|
+ </Descriptions>
|
|
345
|
+ {
|
|
346
|
+ device && item.deviceId == device.deviceId && <img src={selectedImg} />
|
|
347
|
+ }
|
|
348
|
+ </Card>
|
|
349
|
+ </List.Item>
|
|
350
|
+ )
|
|
351
|
+ }
|
|
352
|
+
|
|
353
|
+ </List>
|
|
354
|
+ <div>
|
|
355
|
+ <Button
|
|
356
|
+ type="primary"
|
|
357
|
+ style={{ float: 'right' }}
|
|
358
|
+ loading={loading}
|
|
359
|
+ onClick={handleOk}
|
|
360
|
+ >
|
|
361
|
+ 确定
|
|
362
|
+ </Button>
|
|
363
|
+ </div>
|
|
364
|
+ </div>
|
|
365
|
+ </Drawer>
|
|
366
|
+ </ProCard.TabPane>
|
200
|
367
|
</ProCard>
|
201
|
|
- </Card>
|
|
368
|
+ </PageHeaderWrapper>
|
202
|
369
|
);
|
203
|
370
|
};
|