|
@@ -0,0 +1,388 @@
|
|
1
|
+import { useState, useEffect } from 'react';
|
|
2
|
+import { history } from 'umi';
|
|
3
|
+import { Form, Input, Drawer, DatePicker, Select, InputNumber, message, Button, List, Card, Descriptions } from 'antd';
|
|
4
|
+import ProCard from '@ant-design/pro-card';
|
|
5
|
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
|
6
|
+import moment from 'moment';
|
|
7
|
+import ExtendContent from '@/components/ExtendContent';
|
|
8
|
+import { UploadImage, UploadImageList } from '@/components/Upload';
|
|
9
|
+import Money from '@/components/Money';
|
|
10
|
+import { addMachinery, updateMachinery, getMachineryDetail } from '@/services/machinery';
|
|
11
|
+import { getMachineryTypeList } from '@/services/machineryType';
|
|
12
|
+import { getRegionList } from '@/services/region';
|
|
13
|
+import { getDeviceList, getdeviceDetail, getTerminalDeviceList, addDevice } from '@/services/device';
|
|
14
|
+import { getCooperativeList } from '@/services/cooperative';
|
|
15
|
+import selectedImg from '@/assets/selectedImg.png'
|
|
16
|
+import './style.less'
|
|
17
|
+
|
|
18
|
+const { Option } = Select;
|
|
19
|
+const { Search } = Input;
|
|
20
|
+const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
|
21
|
+
|
|
22
|
+const goBack = () => {
|
|
23
|
+ history.goBack();
|
|
24
|
+};
|
|
25
|
+const FormItem = Form.Item;
|
|
26
|
+export default (props) => {
|
|
27
|
+ const { location } = props;
|
|
28
|
+ const { id } = location.query;
|
|
29
|
+ const [form] = Form.useForm();
|
|
30
|
+ const [loading, setLoading] = useState(false);
|
|
31
|
+ const [imageList, setImageList] = useState([]);
|
|
32
|
+ //农机类型列表
|
|
33
|
+ const [machineryTypeList, setMachineryTypeList] = useState([]);
|
|
34
|
+ //区域列表
|
|
35
|
+ const [regionList, setRegionList] = useState([]);
|
|
36
|
+ //合作社列表
|
|
37
|
+ const [cooperativeList, setCooperativeList] = useState([]);
|
|
38
|
+
|
|
39
|
+ const Submit = (data) => {
|
|
40
|
+ var newData = { ...data }
|
|
41
|
+ if (data.buyDate) {
|
|
42
|
+ newData = { ...data, buyDate: data.buyDate.format('YYYY-MM-DD HH:mm:ss') };
|
|
43
|
+ }
|
|
44
|
+ setLoading(true);
|
|
45
|
+ if (id) {
|
|
46
|
+ updateMachinery(id, newData)
|
|
47
|
+ .then(() => {
|
|
48
|
+ setLoading(false);
|
|
49
|
+ message.success('数据更新成功');
|
|
50
|
+ goBack();
|
|
51
|
+ })
|
|
52
|
+ .catch((err) => {
|
|
53
|
+ setLoading(false);
|
|
54
|
+ message.error(err.message || err);
|
|
55
|
+ });
|
|
56
|
+ } else {
|
|
57
|
+ addMachinery(newData)
|
|
58
|
+ .then((res) => {
|
|
59
|
+ setLoading(false);
|
|
60
|
+ message.success('数据保存成功');
|
|
61
|
+ history.replace(`./Edit?id=${res.machineryId}`)
|
|
62
|
+ })
|
|
63
|
+ .catch((err) => {
|
|
64
|
+ setLoading(false);
|
|
65
|
+ message.error(err.message || err);
|
|
66
|
+ });
|
|
67
|
+ }
|
|
68
|
+ };
|
|
69
|
+
|
|
70
|
+ const imageInput = (image) => {
|
|
71
|
+ return {
|
|
72
|
+ uid: image.imageId,
|
|
73
|
+ url: image.url,
|
|
74
|
+ };
|
|
75
|
+ };
|
|
76
|
+
|
|
77
|
+ const imageOutput = (image) => {
|
|
78
|
+ return {
|
|
79
|
+ imageId: image?.raw?.imageId,
|
|
80
|
+ targetId: id,
|
|
81
|
+ url: image.url,
|
|
82
|
+ };
|
|
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
|
+ setVisible(true);
|
|
103
|
+ })
|
|
104
|
+ } else {
|
|
105
|
+ setVisible(true);
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ }
|
|
109
|
+ const handleClose = () => {
|
|
110
|
+ setVisible(false);
|
|
111
|
+ }
|
|
112
|
+ const onSearch = (val) => {
|
|
113
|
+ if (val == '') {
|
|
114
|
+ getDeviceList({ pageSize: 500 }).then((res) => {
|
|
115
|
+ setDeviceList(res.records);
|
|
116
|
+ })
|
|
117
|
+ } else {
|
|
118
|
+ setTerminalId(val)
|
|
119
|
+ }
|
|
120
|
+ }
|
|
121
|
+ //选中设备
|
|
122
|
+ const handleSelect = (item) => {
|
|
123
|
+ setDevice(item);
|
|
124
|
+ }
|
|
125
|
+ const handleOk = () => {
|
|
126
|
+ if (device != null) {
|
|
127
|
+ setBind(true)
|
|
128
|
+ }
|
|
129
|
+ handleClose();
|
|
130
|
+ }
|
|
131
|
+ const submitDevice = (data) => {
|
|
132
|
+ if (!bind) {
|
|
133
|
+ message.info('请绑定摄像头');
|
|
134
|
+ return;
|
|
135
|
+ }
|
|
136
|
+ let obj = {
|
|
137
|
+ deviceId: device.deviceId,
|
|
138
|
+ channel: data.channel,
|
|
139
|
+ netType: data.netType
|
|
140
|
+ }
|
|
141
|
+ let config = JSON.stringify(obj);
|
|
142
|
+ setDeviceLoading(true);
|
|
143
|
+ addDevice({ ...deviceDetail, machineryId: id, apiConfig: config }).then((res) => {
|
|
144
|
+ message.success('保存成功!');
|
|
145
|
+ setDeviceLoading(false);
|
|
146
|
+ goBack();
|
|
147
|
+ }).catch((err) => {
|
|
148
|
+ setDeviceLoading(false);
|
|
149
|
+ console.log(err.message);
|
|
150
|
+ })
|
|
151
|
+ }
|
|
152
|
+ useEffect(() => {
|
|
153
|
+ getDeviceList({ terminalId: terminalId, pageSize: 500 }).then((res) => {
|
|
154
|
+ setDeviceList(res.records);
|
|
155
|
+ })
|
|
156
|
+ }, [terminalId])
|
|
157
|
+
|
|
158
|
+ useEffect(() => {
|
|
159
|
+ getMachineryTypeList({ pageSize: 500 }).then((res) => {
|
|
160
|
+ setMachineryTypeList(res.records);
|
|
161
|
+ }).catch((err) => {
|
|
162
|
+ console.log(err.message)
|
|
163
|
+ });
|
|
164
|
+ getRegionList({ pageSize: 500 }).then((res) => {
|
|
165
|
+ setRegionList(res.records);
|
|
166
|
+ }).catch((err) => {
|
|
167
|
+ console.log(err.message)
|
|
168
|
+ });
|
|
169
|
+ getCooperativeList({ pageSize: 500 }).then((res) => {
|
|
170
|
+ setCooperativeList(res.records);
|
|
171
|
+ }).catch((err) => {
|
|
172
|
+ console.log(err.message)
|
|
173
|
+ });
|
|
174
|
+ }, [])
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+ useEffect(() => {
|
|
178
|
+ if (id) {
|
|
179
|
+ //编辑时获取基本信息内容
|
|
180
|
+ getMachineryDetail(id).then((res) => {
|
|
181
|
+ form.setFieldsValue({ ...res, buyDate: res.buyDate ? moment(res.buyDate, 'YYYY-MM-DD') : null });
|
|
182
|
+ }).catch((err) => {
|
|
183
|
+ console.log(err.message)
|
|
184
|
+ });
|
|
185
|
+ //获取设备信息内容
|
|
186
|
+ getdeviceDetail(id).then((res) => {
|
|
187
|
+ setDeviceDetail(res);
|
|
188
|
+ if (res) {
|
|
189
|
+ //json字符串转普通对象
|
|
190
|
+ let confit = JSON.parse(res.apiConfig)
|
|
191
|
+ deviceForm.setFieldsValue(confit);
|
|
192
|
+ if (res && res.deviceId != null) {
|
|
193
|
+ //获取绑定设备详情
|
|
194
|
+ getTerminalDeviceList(confit.deviceId).then((res) => {
|
|
195
|
+ setDevice(res);
|
|
196
|
+ setBind(true)
|
|
197
|
+ })
|
|
198
|
+ }
|
|
199
|
+ }
|
|
200
|
+ })
|
|
201
|
+ }
|
|
202
|
+ }, [id]);
|
|
203
|
+
|
|
204
|
+ return (
|
|
205
|
+ <PageHeaderWrapper>
|
|
206
|
+ <ProCard tabs={{ type: 'card' }} style={{ minHeight: '700px' }}>
|
|
207
|
+ <ProCard.TabPane key={1} tab="基本信息">
|
|
208
|
+ <Form {...formItemLayout} onFinish={Submit} form={form}>
|
|
209
|
+ <FormItem
|
|
210
|
+ label="农机名"
|
|
211
|
+ name="name"
|
|
212
|
+ rules={[{ required: true, message: '请输入农机名' }]}
|
|
213
|
+ >
|
|
214
|
+ <Input placeholder="请输入农机名" style={{ width: '350px' }} />
|
|
215
|
+ </FormItem>
|
|
216
|
+ <FormItem
|
|
217
|
+ label="农机类型"
|
|
218
|
+ name="typeId"
|
|
219
|
+ rules={[{ required: true, message: '请选择农机类型' }]}
|
|
220
|
+ >
|
|
221
|
+ <Select style={{ width: '350px' }}>
|
|
222
|
+ {machineryTypeList.map((item) => (
|
|
223
|
+ <Option value={item.typeId} key={item.typeId}>
|
|
224
|
+ {item.name}
|
|
225
|
+ </Option>
|
|
226
|
+ ))}
|
|
227
|
+ </Select>
|
|
228
|
+ </FormItem>
|
|
229
|
+ <FormItem label="主图" name="thumb" rules={[{ required: true, message: '请选择主图' }]}>
|
|
230
|
+ <UploadImage />
|
|
231
|
+ </FormItem>
|
|
232
|
+ <FormItem label="农机banner图集" name="images">
|
|
233
|
+ <UploadImageList
|
|
234
|
+ value={imageList}
|
|
235
|
+ onChange={setImageList}
|
|
236
|
+ input={imageInput}
|
|
237
|
+ output={imageOutput}
|
|
238
|
+ />
|
|
239
|
+ </FormItem>
|
|
240
|
+ <FormItem
|
|
241
|
+ label="区域"
|
|
242
|
+ name="regionId"
|
|
243
|
+ rules={[{ required: true, message: '请选择区域' }]}
|
|
244
|
+ >
|
|
245
|
+ <Select style={{ width: '350px' }}>
|
|
246
|
+ {regionList.map((item) => (
|
|
247
|
+ <Option value={item.regionId} key={item.regionId}>
|
|
248
|
+ {item.name}
|
|
249
|
+ </Option>
|
|
250
|
+ ))}
|
|
251
|
+ </Select>
|
|
252
|
+ </FormItem>
|
|
253
|
+ <FormItem
|
|
254
|
+ label="归属合作社"
|
|
255
|
+ name="orgId"
|
|
256
|
+ rules={[{ required: true, message: '请选择归属合作社' }]}
|
|
257
|
+ >
|
|
258
|
+ <Select style={{ width: '350px' }}>
|
|
259
|
+ {cooperativeList.map((item) => (
|
|
260
|
+ <Option value={item.orgId} key={item.orgId}>
|
|
261
|
+ {item.name}
|
|
262
|
+ </Option>
|
|
263
|
+ ))}
|
|
264
|
+ </Select>
|
|
265
|
+ </FormItem>
|
|
266
|
+ <FormItem label="单价" name="price" rules={[{ required: true, message: '请输入价格' }]}>
|
|
267
|
+ <Money style={{ width: '350px' }} />
|
|
268
|
+ </FormItem>
|
|
269
|
+ <FormItem label="购买时间" name="buyDate">
|
|
270
|
+ <DatePicker format="YYYY-MM-DD" style={{ width: '350px' }} />
|
|
271
|
+ </FormItem>
|
|
272
|
+ <FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
|
|
273
|
+ <Select placeholder="请选择农机状态" style={{ width: '350px' }}>
|
|
274
|
+ <Option value={1}>正常</Option>
|
|
275
|
+ <Option value={0}>维修</Option>
|
|
276
|
+ </Select>
|
|
277
|
+ </FormItem>
|
|
278
|
+ {id && (
|
|
279
|
+ <FormItem label="详细信息" colon={false}>
|
|
280
|
+ <ExtendContent targetType="machinery" targetId={id} onCancel={goBack} />
|
|
281
|
+ </FormItem>
|
|
282
|
+ )}
|
|
283
|
+ <FormItem label=" " colon={false}>
|
|
284
|
+ <Button type="default" onClick={goBack}>
|
|
285
|
+ 返回
|
|
286
|
+ </Button>
|
|
287
|
+ <Button
|
|
288
|
+ type="primary"
|
|
289
|
+ loading={loading}
|
|
290
|
+ htmlType="submit"
|
|
291
|
+ style={{ marginLeft: '4em' }}
|
|
292
|
+ >
|
|
293
|
+ 保存
|
|
294
|
+ </Button>
|
|
295
|
+ </FormItem>
|
|
296
|
+ </Form>
|
|
297
|
+ </ProCard.TabPane>
|
|
298
|
+ <ProCard.TabPane key={2} disabled={!id} tab="设备信息">
|
|
299
|
+ <Form {...formItemLayout} onFinish={submitDevice} form={deviceForm}>
|
|
300
|
+ <FormItem label='摄像头' >
|
|
301
|
+ <Button type='link' onClick={changeCamera}>{bind ? '已绑定' : '未绑定'}</Button>
|
|
302
|
+ </FormItem>
|
|
303
|
+ <FormItem
|
|
304
|
+ label="通道号"
|
|
305
|
+ name='channel'
|
|
306
|
+ rules={[{ required: true, message: '请输入通道号' }]}
|
|
307
|
+ >
|
|
308
|
+ <InputNumber min={1} placeholder="请输入通道号" style={{ width: '350px' }} />
|
|
309
|
+ </FormItem>
|
|
310
|
+ <FormItem
|
|
311
|
+ label="网络类型"
|
|
312
|
+ name='netType'
|
|
313
|
+ rules={[{ required: true, message: '请选择网络类型' }]}
|
|
314
|
+ >
|
|
315
|
+ <Select placeholder="请选择网络类型" style={{ width: '350px' }}>
|
|
316
|
+ <Option value={0}>内网</Option>
|
|
317
|
+ <Option value={1}>电信</Option>
|
|
318
|
+ <Option value={2}>移动</Option>
|
|
319
|
+ <Option value={3}>联通</Option>
|
|
320
|
+ </Select>
|
|
321
|
+ </FormItem>
|
|
322
|
+ <FormItem label=" " colon={false}>
|
|
323
|
+ <Button type="default" onClick={goBack}>
|
|
324
|
+ 返回
|
|
325
|
+ </Button>
|
|
326
|
+ <Button
|
|
327
|
+ type="primary"
|
|
328
|
+ loading={deviceLoading}
|
|
329
|
+ htmlType="submit"
|
|
330
|
+ style={{ marginLeft: '4em' }}
|
|
331
|
+ >
|
|
332
|
+ 保存
|
|
333
|
+ </Button>
|
|
334
|
+ </FormItem>
|
|
335
|
+ </Form>
|
|
336
|
+ <Drawer
|
|
337
|
+ title="摄像头列表"
|
|
338
|
+ width={500}
|
|
339
|
+ closable={false}
|
|
340
|
+ onClose={handleClose}
|
|
341
|
+ visible={visible}
|
|
342
|
+ >
|
|
343
|
+ <div style={{ display: 'flex', height: '100%', flexDirection: 'column' }}>
|
|
344
|
+ <Search
|
|
345
|
+ placeholder="请输入终端ID"
|
|
346
|
+ allowClear
|
|
347
|
+ enterButton="搜索"
|
|
348
|
+ size="middle"
|
|
349
|
+ onSearch={onSearch}
|
|
350
|
+ style={{ padding: '24px' }}
|
|
351
|
+ />
|
|
352
|
+ <List split={false} style={{ padding: '12px 0', flex: 1, overflowY: 'auto', background: 'rgb(240,242,245)' }}>
|
|
353
|
+ {
|
|
354
|
+ deviceList.map(item =>
|
|
355
|
+ <List.Item key={item.deviceId} onClick={() => handleSelect(item)}>
|
|
356
|
+ <Card className='listCard' hoverable>
|
|
357
|
+ <Descriptions labelStyle={{ width: '72px', display: 'inline-block', textAlign: 'end' }} >
|
|
358
|
+ <Descriptions.Item span={3} label='型号名称'>{item.modelName}</Descriptions.Item>
|
|
359
|
+ <Descriptions.Item span={3} label='协议'>{item.protocol}</Descriptions.Item>
|
|
360
|
+ <Descriptions.Item span={3} label='终端ID'>{item.terminalId}</Descriptions.Item>
|
|
361
|
+ <Descriptions.Item span={3} label='通道列表'>{item.deviceChannelList}</Descriptions.Item>
|
|
362
|
+ </Descriptions>
|
|
363
|
+ {
|
|
364
|
+ device && item.deviceId == device.deviceId && <img src={selectedImg} />
|
|
365
|
+ }
|
|
366
|
+ </Card>
|
|
367
|
+ </List.Item>
|
|
368
|
+ )
|
|
369
|
+ }
|
|
370
|
+
|
|
371
|
+ </List>
|
|
372
|
+ <div style={{ padding: '24px' }}>
|
|
373
|
+ <Button
|
|
374
|
+ type="primary"
|
|
375
|
+ style={{ float: 'right' }}
|
|
376
|
+ loading={loading}
|
|
377
|
+ onClick={handleOk}
|
|
378
|
+ >
|
|
379
|
+ 确定
|
|
380
|
+ </Button>
|
|
381
|
+ </div>
|
|
382
|
+ </div>
|
|
383
|
+ </Drawer>
|
|
384
|
+ </ProCard.TabPane>
|
|
385
|
+ </ProCard>
|
|
386
|
+ </PageHeaderWrapper>
|
|
387
|
+ );
|
|
388
|
+};
|