|
@@ -1,100 +1,106 @@
|
1
|
1
|
import React, { useState, useEffect, useRef } from 'react';
|
2
|
|
-import { Button, Popconfirm, Modal, Form, Input, message } from 'antd';
|
|
2
|
+import { Button, Select, Modal, Form, Input, message } from 'antd';
|
3
|
3
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
4
|
4
|
import moment from 'moment';
|
5
|
5
|
import PageTable from '@/components/PageTable';
|
|
6
|
+import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
|
|
7
|
+import { queryTable } from '@/utils/request';
|
6
|
8
|
|
|
9
|
+const { Option } = Select;
|
7
|
10
|
const formatterTime = (val) => {
|
8
|
11
|
return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
|
9
|
12
|
};
|
10
|
13
|
const FormItem = Form.Item;
|
11
|
14
|
|
12
|
15
|
export default (props) => {
|
|
16
|
+ // 绑定表单
|
13
|
17
|
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
14
|
18
|
const [form] = Form.useForm();
|
15
|
19
|
const [editModal, setEditModal] = useState(false);
|
16
|
20
|
const [loading, setLoading] = useState(false);
|
17
|
|
- const [regionId, setRegionId] = useState();
|
|
21
|
+ const [deviceId, setdeviceId] = useState();
|
|
22
|
+ const [machineryId, setmachineryId] = useState();
|
18
|
23
|
const actionRef = useRef();
|
19
|
|
-
|
20
|
|
- // const Submit = (values) => {
|
21
|
|
- // setLoading(true);
|
22
|
|
- // if (regionId) {
|
23
|
|
- // updateRegion(regionId, values).then(() => {
|
24
|
|
- // setLoading(false);
|
25
|
|
- // message.success(`修改成功`);
|
26
|
|
- // onCancel();
|
27
|
|
- // actionRef.current.reload();
|
28
|
|
- // }).catch((err) => {
|
29
|
|
- // setLoading(false);
|
30
|
|
- // console.log(err.message)
|
31
|
|
- // });
|
32
|
|
- // } else {
|
33
|
|
- // addRegion(values)
|
34
|
|
- // .then(() => {
|
35
|
|
- // setLoading(false);
|
36
|
|
- // message.success(`保存成功`);
|
37
|
|
- // onCancel();
|
38
|
|
- // actionRef.current.reload();
|
39
|
|
- // })
|
40
|
|
- // .catch((err) => {
|
41
|
|
- // setLoading(false);
|
42
|
|
- // message.error(err.message || err);
|
43
|
|
- // });
|
44
|
|
- // }
|
45
|
|
- // };
|
46
|
|
- // const handelEdit = (val) => {
|
47
|
|
- // setRegionId(val.regionId);
|
48
|
|
- // form.setFieldsValue(val);
|
49
|
|
- // setEditModal(true);
|
50
|
|
- // };
|
51
|
|
- // const onCancel = () => {
|
52
|
|
- // setRegionId();
|
53
|
|
- // form.resetFields();
|
54
|
|
- // setEditModal(false);
|
55
|
|
- // };
|
56
|
|
- // const handleDelete = (id) => {
|
57
|
|
- // deleteRegion(id)
|
58
|
|
- // .then(() => {
|
59
|
|
- // message.success('删除成功');
|
60
|
|
- // actionRef.current.reload();
|
61
|
|
- // })
|
62
|
|
- // .catch((err) => {
|
63
|
|
- // console.log(err.message)
|
64
|
|
- // });
|
65
|
|
- // };
|
|
24
|
+ const [newsTypeList, setNewsTypeList] = useState([]);
|
66
|
25
|
// useEffect(() => {
|
67
|
26
|
// if (regionId) {
|
68
|
27
|
// } else {
|
69
|
28
|
// form.resetFields();
|
70
|
29
|
// }
|
71
|
30
|
// }, [regionId]);
|
72
|
|
- // const actions = () => [
|
73
|
|
- // <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
|
74
|
|
- // 新增
|
75
|
|
- // </Button>,
|
76
|
|
- // ];
|
|
31
|
+
|
|
32
|
+ //列表编辑
|
|
33
|
+ const handelEdit = (val) => {
|
|
34
|
+ setmachineryId(val.machineryId);
|
|
35
|
+ form.setFieldsValue(val);
|
|
36
|
+ setEditModal(true);
|
|
37
|
+ };
|
|
38
|
+
|
|
39
|
+ //绑定弹窗关闭
|
|
40
|
+ const onCancel = () => {
|
|
41
|
+ setmachineryId();
|
|
42
|
+ form.resetFields();
|
|
43
|
+ setEditModal(false);
|
|
44
|
+ };
|
|
45
|
+
|
|
46
|
+ // 绑定提交
|
|
47
|
+ const Submit = (values) => {
|
|
48
|
+ setLoading(true);
|
|
49
|
+ addDevice(...values, machineryId).then(() => {
|
|
50
|
+ setLoading(false);
|
|
51
|
+ message.success(`绑定成功`);
|
|
52
|
+ onCancel();
|
|
53
|
+ actionRef.current.reload();
|
|
54
|
+ });
|
|
55
|
+ // if (machineryId) {
|
|
56
|
+ // deleteDevice(machineryId)
|
|
57
|
+ // .then(() => {
|
|
58
|
+ // setLoading(false);
|
|
59
|
+ // message.success(`解绑成功`);
|
|
60
|
+ // onCancel();
|
|
61
|
+ // actionRef.current.reload();
|
|
62
|
+ // })
|
|
63
|
+ // .catch((err) => {
|
|
64
|
+ // setLoading(false);
|
|
65
|
+ // message.error(err.message || err);
|
|
66
|
+ // });
|
|
67
|
+ // }
|
|
68
|
+ };
|
|
69
|
+
|
|
70
|
+ useEffect(() => {
|
|
71
|
+ getDeviceList().then((res) => {
|
|
72
|
+ setNewsTypeList(res.records);
|
|
73
|
+ }).catch((err) => {
|
|
74
|
+ console.log(err.message)
|
|
75
|
+ });
|
|
76
|
+ }, []);
|
|
77
|
+
|
77
|
78
|
const columns = [
|
78
|
79
|
{
|
79
|
80
|
title: '行号',
|
80
|
|
- dataIndex: 'name',
|
81
|
|
- key: 'name',
|
|
81
|
+ dataIndex: 'deviceId',
|
|
82
|
+ key: 'deviceId',
|
82
|
83
|
},
|
83
|
84
|
{
|
84
|
85
|
title: '设备编号',
|
85
|
|
- dataIndex: 'name',
|
86
|
|
- key: 'name',
|
|
86
|
+ dataIndex: 'deviceNo',
|
|
87
|
+ key: 'deviceNo',
|
87
|
88
|
search: false,
|
88
|
89
|
},
|
89
|
90
|
{
|
90
|
91
|
title: '设备类型',
|
91
|
|
- dataIndex: 'name',
|
92
|
|
- key: 'name',
|
|
92
|
+ dataIndex: 'deviceType',
|
|
93
|
+ key: 'deviceType',
|
|
94
|
+ valueType: 'select',
|
|
95
|
+ // request: () => queryTable(getDeviceList)(),
|
93
|
96
|
},
|
94
|
97
|
{
|
95
|
98
|
title: '在线状态',
|
96
|
|
- dataIndex: 'name',
|
97
|
|
- key: 'name',
|
|
99
|
+ dataIndex: 'onlineStatus',
|
|
100
|
+ key: 'onlineStatus',
|
|
101
|
+ render: (_, record) => {
|
|
102
|
+ return record.onlineStatus === 1 ? '在线' : '离线';
|
|
103
|
+ },
|
98
|
104
|
},
|
99
|
105
|
{
|
100
|
106
|
title: '注册时间',
|
|
@@ -106,8 +112,8 @@ export default (props) => {
|
106
|
112
|
},
|
107
|
113
|
{
|
108
|
114
|
title: '绑定农机',
|
109
|
|
- dataIndex: 'name',
|
110
|
|
- key: 'name',
|
|
115
|
+ dataIndex: 'machineryId',
|
|
116
|
+ key: 'machineryId',
|
111
|
117
|
search: false,
|
112
|
118
|
},
|
113
|
119
|
{
|
|
@@ -116,19 +122,14 @@ export default (props) => {
|
116
|
122
|
width: 160,
|
117
|
123
|
render: (_, record) => [
|
118
|
124
|
<Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
|
119
|
|
- 编辑
|
|
125
|
+ 查看作业
|
|
126
|
+ </Button>,
|
|
127
|
+ <Button type="link" style={{ padding: 0 }} key={2} onClick={() => handelEdit(record)}>
|
|
128
|
+ 修改
|
|
129
|
+ </Button>,
|
|
130
|
+ <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
|
|
131
|
+ {record.machineryId === null ? '绑定' : '解绑'}
|
120
|
132
|
</Button>,
|
121
|
|
- <Popconfirm
|
122
|
|
- key={2}
|
123
|
|
- title="您是否确认删除 ?"
|
124
|
|
- onConfirm={() => handleDelete(record.regionId)}
|
125
|
|
- okText="确定"
|
126
|
|
- cancelText="取消"
|
127
|
|
- >
|
128
|
|
- <Button style={{ padding: 0 }} type="link">
|
129
|
|
- 删除
|
130
|
|
- </Button>
|
131
|
|
- </Popconfirm>,
|
132
|
133
|
],
|
133
|
134
|
},
|
134
|
135
|
];
|
|
@@ -136,16 +137,17 @@ export default (props) => {
|
136
|
137
|
return (
|
137
|
138
|
<PageHeaderWrapper>
|
138
|
139
|
<PageTable
|
|
140
|
+ request={getDeviceList}
|
139
|
141
|
columns={columns}
|
140
|
142
|
actionRef={actionRef}
|
141
|
|
- rowKey="regionId"
|
|
143
|
+ // rowKey="deviceId"
|
142
|
144
|
options={false}
|
143
|
145
|
// toolBarRender={actions}
|
144
|
146
|
scroll={{ x: 1000 }}
|
145
|
147
|
/>
|
146
|
|
- {/* <Modal
|
|
148
|
+ <Modal
|
147
|
149
|
forceRender
|
148
|
|
- title={regionId ? '区域编辑' : '区域新增'}
|
|
150
|
+ title="绑定农机"
|
149
|
151
|
visible={editModal}
|
150
|
152
|
onCancel={onCancel}
|
151
|
153
|
keyboard={false}
|
|
@@ -154,24 +156,40 @@ export default (props) => {
|
154
|
156
|
footer={null}
|
155
|
157
|
>
|
156
|
158
|
<Form {...formItemLayout} onFinish={Submit} form={form}>
|
157
|
|
- <FormItem label="区域名" name="name" rules={[{ required: true, message: '请输入' }]}>
|
158
|
|
- <Input placeholder="请输入" />
|
|
159
|
+ <FormItem label="农机分类" name="deviceType" rules={[{ required: true, message: '请选择农机分类' }]}
|
|
160
|
+ >
|
|
161
|
+ <Select allowClear style={{ width: '320px' }}>
|
|
162
|
+ {newsTypeList.map((item) => (
|
|
163
|
+ <Option value={item.deviceType} key={item.deviceType}>
|
|
164
|
+ {item.deviceType}
|
|
165
|
+ </Option>
|
|
166
|
+ ))}
|
|
167
|
+ </Select>
|
|
168
|
+ </FormItem>
|
|
169
|
+ <FormItem label="选择农机" name="deviceNo" rules={[{ required: true, message: '请选择农机名' }]}>
|
|
170
|
+ <Select allowClear style={{ width: '320px' }}>
|
|
171
|
+ {newsTypeList.map((item) => (
|
|
172
|
+ <Option value={item.deviceNo} key={item.deviceNo}>
|
|
173
|
+ {item.deviceNo}
|
|
174
|
+ </Option>
|
|
175
|
+ ))}
|
|
176
|
+ </Select>
|
159
|
177
|
</FormItem>
|
160
|
178
|
<FormItem label=" " colon={false}>
|
161
|
|
- <Button type="default" onClick={onCancel}>
|
|
179
|
+ <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
|
162
|
180
|
取消
|
163
|
181
|
</Button>
|
164
|
182
|
<Button
|
165
|
183
|
type="primary"
|
166
|
184
|
loading={loading}
|
167
|
185
|
htmlType="Submit"
|
168
|
|
- style={{ marginLeft: '4em' }}
|
|
186
|
+ style={{ marginTop: '2em', marginLeft: '2em' }}
|
169
|
187
|
>
|
170
|
188
|
确认
|
171
|
189
|
</Button>
|
172
|
190
|
</FormItem>
|
173
|
191
|
</Form>
|
174
|
|
- </Modal> */}
|
|
192
|
+ </Modal>
|
175
|
193
|
</PageHeaderWrapper>
|
176
|
194
|
);
|
177
|
195
|
};
|