|
@@ -4,6 +4,8 @@ import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
4
|
4
|
import moment from 'moment';
|
5
|
5
|
import PageTable from '@/components/PageTable';
|
6
|
6
|
import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
|
|
7
|
+import { addMachinery, getMachineryList } from '@/services/machinery';
|
|
8
|
+import { getMachineryTypeList } from '@/services/machineryType';
|
7
|
9
|
import { queryTable } from '@/utils/request';
|
8
|
10
|
|
9
|
11
|
const { Option } = Select;
|
|
@@ -19,9 +21,12 @@ export default (props) => {
|
19
|
21
|
const [editModal, setEditModal] = useState(false);
|
20
|
22
|
const [loading, setLoading] = useState(false);
|
21
|
23
|
const [deviceId, setdeviceId] = useState();
|
22
|
|
- const [machineryId, setmachineryId] = useState();
|
|
24
|
+ const [machineryId, setMachineryId] = useState();
|
|
25
|
+ const [machineryTypeList, setMachineryTypeList] = useState([]);
|
23
|
26
|
const actionRef = useRef();
|
24
|
|
- const [newsTypeList, setNewsTypeList] = useState([]);
|
|
27
|
+ const [machineryList, setMachineryList] = useState([]);
|
|
28
|
+ const [typeId, setTypeId] = useState();
|
|
29
|
+ const e = 0;
|
25
|
30
|
// useEffect(() => {
|
26
|
31
|
// if (regionId) {
|
27
|
32
|
// } else {
|
|
@@ -31,14 +36,14 @@ export default (props) => {
|
31
|
36
|
|
32
|
37
|
//列表编辑
|
33
|
38
|
const handelEdit = (val) => {
|
34
|
|
- setmachineryId(val.machineryId);
|
|
39
|
+ setMachineryId(val.machineryId);
|
35
|
40
|
form.setFieldsValue(val);
|
36
|
41
|
setEditModal(true);
|
37
|
42
|
};
|
38
|
43
|
|
39
|
44
|
//绑定弹窗关闭
|
40
|
45
|
const onCancel = () => {
|
41
|
|
- setmachineryId();
|
|
46
|
+ setMachineryId();
|
42
|
47
|
form.resetFields();
|
43
|
48
|
setEditModal(false);
|
44
|
49
|
};
|
|
@@ -46,7 +51,7 @@ export default (props) => {
|
46
|
51
|
// 绑定提交
|
47
|
52
|
const Submit = (values) => {
|
48
|
53
|
setLoading(true);
|
49
|
|
- addDevice(...values, machineryId).then(() => {
|
|
54
|
+ addDevice(values).then(() => {
|
50
|
55
|
setLoading(false);
|
51
|
56
|
message.success(`绑定成功`);
|
52
|
57
|
onCancel();
|
|
@@ -65,16 +70,37 @@ export default (props) => {
|
65
|
70
|
// message.error(err.message || err);
|
66
|
71
|
// });
|
67
|
72
|
// }
|
|
73
|
+ console.log(values, 'fangfang')
|
68
|
74
|
};
|
69
|
75
|
|
70
|
76
|
useEffect(() => {
|
71
|
|
- getDeviceList().then((res) => {
|
72
|
|
- setNewsTypeList(res.records);
|
|
77
|
+ getMachineryTypeList({ pageSize: 999 }).then((res) => {
|
|
78
|
+ setMachineryTypeList(res.records);
|
73
|
79
|
}).catch((err) => {
|
74
|
80
|
console.log(err.message)
|
75
|
81
|
});
|
76
|
82
|
}, []);
|
77
|
83
|
|
|
84
|
+ useEffect(() => {
|
|
85
|
+ if (typeId) {
|
|
86
|
+ getMachineryTypeList({ typeId }).then((e) => {
|
|
87
|
+ setMachineryTypeList(e.records);
|
|
88
|
+ }).catch((err) => {
|
|
89
|
+ console.log(err.message)
|
|
90
|
+ });
|
|
91
|
+ }
|
|
92
|
+ }, [typeId])
|
|
93
|
+
|
|
94
|
+ useEffect(() => {
|
|
95
|
+ if (machineryId) {
|
|
96
|
+ getMachineryList({ machineryId }).then((e) => {
|
|
97
|
+ setMachineryList(e.records);
|
|
98
|
+ }).catch((err) => {
|
|
99
|
+ console.log(err.message)
|
|
100
|
+ });
|
|
101
|
+ }
|
|
102
|
+ }, [machineryId])
|
|
103
|
+
|
78
|
104
|
const columns = [
|
79
|
105
|
{
|
80
|
106
|
title: '行号',
|
|
@@ -140,9 +166,16 @@ export default (props) => {
|
140
|
166
|
request={getDeviceList}
|
141
|
167
|
columns={columns}
|
142
|
168
|
actionRef={actionRef}
|
143
|
|
- // rowKey="deviceId"
|
|
169
|
+ rowKey="deviceId"
|
144
|
170
|
options={false}
|
145
|
|
- // toolBarRender={actions}
|
|
171
|
+ toolBarRender={() => [
|
|
172
|
+ <Button
|
|
173
|
+ key="1"
|
|
174
|
+ type="primary"
|
|
175
|
+ >
|
|
176
|
+ +同步设备信息
|
|
177
|
+ </Button>,
|
|
178
|
+ ]}
|
146
|
179
|
scroll={{ x: 1000 }}
|
147
|
180
|
/>
|
148
|
181
|
<Modal
|
|
@@ -154,27 +187,30 @@ export default (props) => {
|
154
|
187
|
maskClosable={false}
|
155
|
188
|
destroyOnClose={true}
|
156
|
189
|
footer={null}
|
|
190
|
+ machineryId={machineryId}
|
157
|
191
|
>
|
158
|
|
- <Form {...formItemLayout} onFinish={Submit} form={form}>
|
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}
|
|
192
|
+ <Form {...formItemLayout} onFinish={Submit} form={form}>
|
|
193
|
+ <FormItem label="农机分类" rules={[{ required: true, message: '请选择农机分类' }]}>
|
|
194
|
+ <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
|
|
195
|
+ {machineryTypeList.map((item) => (
|
|
196
|
+ <Option value={item.typeId} key={item.typeId}>
|
|
197
|
+ {item.name}
|
165
|
198
|
</Option>
|
166
|
199
|
))}
|
167
|
200
|
</Select>
|
168
|
201
|
</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}
|
|
202
|
+ <FormItem label="选择农机" rules={[{ required: true, message: '请选择农机名' }]}>
|
|
203
|
+ <Select onChange={setMachineryId} allowClear style={{ width: '320px' }}>
|
|
204
|
+ {machineryList.map((item) => (
|
|
205
|
+ <Option value={item.machineryId} key={item.machineryId}>
|
|
206
|
+ {item.name}
|
174
|
207
|
</Option>
|
175
|
208
|
))}
|
176
|
209
|
</Select>
|
177
|
210
|
</FormItem>
|
|
211
|
+ {/* <FormItem label="选择农机" request={getMachineryList}>
|
|
212
|
+ <Input placeholder='请输入农机名称' name="name" rules={[{ required: true }]} />
|
|
213
|
+ </FormItem> */}
|
178
|
214
|
<FormItem label=" " colon={false}>
|
179
|
215
|
<Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
|
180
|
216
|
取消
|