fangmingyue před 2 roky
rodič
revize
24848f2316
2 změnil soubory, kde provedl 57 přidání a 59 odebrání
  1. 1
    1
      config/proxy.js
  2. 56
    58
      src/pages/SystemManagement/Sensing/index.jsx

+ 1
- 1
config/proxy.js Zobrazit soubor

11
     // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
11
     // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
12
     '/api/': {
12
     '/api/': {
13
       // 要代理的地址
13
       // 要代理的地址
14
-      target: 'http://192.168.89.147:7080',
14
+      target: 'http://192.168.89.76:7080',
15
       // target: 'http://192.168.89.76:7080',
15
       // target: 'http://192.168.89.76:7080',
16
       // target: 'http://machine.njyunzhi.com',
16
       // target: 'http://machine.njyunzhi.com',
17
       // 配置了这个可以从 http 代理到 https
17
       // 配置了这个可以从 http 代理到 https

+ 56
- 58
src/pages/SystemManagement/Sensing/index.jsx Zobrazit soubor

1
 import React, { useState, useEffect, useRef } from 'react';
1
 import React, { useState, useEffect, useRef } from 'react';
2
-import { Button, Select, Modal, Form, Input, message } from 'antd';
2
+import { Button, Modal, Select, Form, message } from 'antd';
3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
 import moment from 'moment';
4
 import moment from 'moment';
5
+import { history } from 'umi';
5
 import PageTable from '@/components/PageTable';
6
 import PageTable from '@/components/PageTable';
6
 import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
7
 import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
7
-import { addMachinery, getMachineryList } from '@/services/machinery';
8
+import { getMachineryList } from '@/services/machinery';
8
 import { getMachineryTypeList } from '@/services/machineryType';
9
 import { getMachineryTypeList } from '@/services/machineryType';
9
-import { queryTable } from '@/utils/request';
10
 
10
 
11
-const { Option } = Select;
12
 const formatterTime = (val) => {
11
 const formatterTime = (val) => {
13
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
12
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
14
 };
13
 };
15
-const FormItem = Form.Item;
16
 
14
 
17
 export default (props) => {
15
 export default (props) => {
18
   // 绑定表单
16
   // 绑定表单
20
   const [form] = Form.useForm();
18
   const [form] = Form.useForm();
21
   const [editModal, setEditModal] = useState(false);
19
   const [editModal, setEditModal] = useState(false);
22
   const [loading, setLoading] = useState(false);
20
   const [loading, setLoading] = useState(false);
23
-  const [deviceId, setdeviceId] = useState();
24
   const [machineryId, setMachineryId] = useState();
21
   const [machineryId, setMachineryId] = useState();
25
-  const [machineryTypeList, setMachineryTypeList] = useState([]);
22
+  const [device, setDeviceList] = useState();
23
+  const [deviceId, setDeviceId] = useState();
26
   const actionRef = useRef();
24
   const actionRef = useRef();
27
-  const [machineryList, setMachineryList] = useState([]);
25
+  const [machineryTypeList, setMachineryTypeList] = useState([]);
28
   const [typeId, setTypeId] = useState();
26
   const [typeId, setTypeId] = useState();
27
+  const [machineryList, setMachineryList] = useState([]);
28
+  const { Option } = Select;
29
+  const FormItem = Form.Item;
29
 
30
 
30
-  // useEffect(() => {
31
-  //   if (regionId) {
32
-  //   } else {
33
-  //     form.resetFields();
34
-  //   }
35
-  // }, [regionId]);
36
-
37
-  const handleChange = (e) => {
38
-    getMachineryTypeList().then((e) => {
39
-      setTypeId(e.records);
40
-      console.log('qqqqqqqq', e.records);
41
-    })
31
+  const goBack = () => {
32
+    history.goBack();
42
   };
33
   };
43
 
34
 
44
   //列表编辑
35
   //列表编辑
45
   const handelEdit = (val) => {
36
   const handelEdit = (val) => {
46
-    setMachineryId(val.machineryId);
37
+    if (val.machineryId != null) {
38
+      setEditModal(false);
39
+      const title = '确认当前设备要解绑"' + val.machineryName + '"农机设备吗?';
40
+      Modal.confirm({
41
+        title: title,
42
+        okText: '确认',
43
+        cancelText: '取消',
44
+        onOk () {
45
+          deleteDevice(machineryId)
46
+            .then(() => {
47
+              setLoading(false);
48
+              message.success(`解绑成功`);
49
+              onCancel();
50
+              actionRef.current.reload();
51
+
52
+            })
53
+            .catch((err) => {
54
+              setLoading(false);
55
+              message.error(err.message || err);
56
+            });
57
+        }
58
+      })
59
+    } else {
60
+      setEditModal(true);
61
+      setDeviceList(val);
62
+    }
63
+
47
     form.setFieldsValue(val);
64
     form.setFieldsValue(val);
48
-    setEditModal(true);
49
   };
65
   };
50
 
66
 
51
   //绑定弹窗关闭
67
   //绑定弹窗关闭
57
 
73
 
58
   // 绑定提交
74
   // 绑定提交
59
   const Submit = (values) => {
75
   const Submit = (values) => {
76
+    let params = { ...device, ...values };
60
     setLoading(true);
77
     setLoading(true);
61
-    addDevice(values).then(() => {
78
+    addDevice(params).then((res) => {
62
       setLoading(false);
79
       setLoading(false);
63
       message.success(`绑定成功`);
80
       message.success(`绑定成功`);
64
-      onCancel();
65
       actionRef.current.reload();
81
       actionRef.current.reload();
82
+      goBack();
66
     });
83
     });
67
-    // if (machineryId) {
68
-    //   deleteDevice(machineryId)
69
-    //     .then(() => {
70
-    //       setLoading(false);
71
-    //       message.success(`解绑成功`);
72
-    //       onCancel();
73
-    //       actionRef.current.reload();
74
-    //     })
75
-    //     .catch((err) => {
76
-    //       setLoading(false);
77
-    //       message.error(err.message || err);
78
-    //     });
79
-    // }
80
-    console.log(values, 'fangfang')
81
   };
84
   };
82
 
85
 
83
   useEffect(() => {
86
   useEffect(() => {
86
     }).catch((err) => {
89
     }).catch((err) => {
87
       console.log(err.message)
90
       console.log(err.message)
88
     });
91
     });
89
-    getMachineryList({ pageSize: 999 }).then((e) => {
90
-      setMachineryList(e.records);
91
-    }).catch((err) => {
92
-      console.log(err.message)
93
-    });
94
   }, []);
92
   }, []);
95
 
93
 
96
   useEffect(() => {
94
   useEffect(() => {
97
     if (typeId) {
95
     if (typeId) {
98
-      getMachineryTypeList({ typeId }).then((e) => {
99
-        setMachineryTypeList(e.records);
100
-      }).catch((err) => {
101
-        console.log(err.message)
102
-      });
103
-      getMachineryList({ machineryId }).then((e) => {
96
+      getMachineryList({ typeId }).then((e) => {
104
         setMachineryList(e.records);
97
         setMachineryList(e.records);
105
       }).catch((err) => {
98
       }).catch((err) => {
106
         console.log(err.message)
99
         console.log(err.message)
107
       });
100
       });
108
     }
101
     }
102
+
109
   }, [typeId])
103
   }, [typeId])
110
 
104
 
111
   const columns = [
105
   const columns = [
124
       title: '设备类型',
118
       title: '设备类型',
125
       dataIndex: 'deviceType',
119
       dataIndex: 'deviceType',
126
       key: 'deviceType',
120
       key: 'deviceType',
127
-      valueType: 'select',
121
+      valueEnum: {
122
+        shensong: {
123
+          text: '深松',
124
+        },
125
+        feifang: {
126
+          text: '飞防',
127
+        },
128
+      },
128
       // request: () => queryTable(getDeviceList)(),
129
       // request: () => queryTable(getDeviceList)(),
129
     },
130
     },
130
     {
131
     {
154
       valueType: 'option',
155
       valueType: 'option',
155
       width: 160,
156
       width: 160,
156
       render: (_, record) => [
157
       render: (_, record) => [
157
-        <Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
158
+        <Button type="link" style={{ padding: 0 }} key={1}>
158
           查看作业
159
           查看作业
159
         </Button>,
160
         </Button>,
160
-        <Button type="link" style={{ padding: 0 }} key={2} onClick={() => handelEdit(record)}>
161
+        <Button type="link" style={{ padding: 0 }} key={2}>
161
           修改
162
           修改
162
         </Button>,
163
         </Button>,
163
         <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
164
         <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
197
         machineryId={machineryId}
198
         machineryId={machineryId}
198
       >
199
       >
199
         <Form  {...formItemLayout} onFinish={Submit} form={form}>
200
         <Form  {...formItemLayout} onFinish={Submit} form={form}>
200
-          <FormItem label="农机分类" rules={[{ required: true, message: '请选择农机分类' }]}>
201
-            <Select value={typeId} onChange={handleChange} allowClear style={{ width: '320px' }}>
201
+          <FormItem label="农机分类" name="typeId" rules={[{ required: true, message: '请选择农机分类' }]}>
202
+            <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
202
               {machineryTypeList.map((item) => (
203
               {machineryTypeList.map((item) => (
203
                 <Option value={item.typeId} key={item.typeId}>
204
                 <Option value={item.typeId} key={item.typeId}>
204
                   {item.name}
205
                   {item.name}
206
               ))}
207
               ))}
207
             </Select>
208
             </Select>
208
           </FormItem>
209
           </FormItem>
209
-          <FormItem label="选择农机" rules={[{ required: true, message: '请选择农机名' }]}>
210
+          <FormItem label="选择农机" name="machineryId" rules={[{ required: true, message: '请选择农机名' }]}>
210
             <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
211
             <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
211
               {machineryList.map((item) => (
212
               {machineryList.map((item) => (
212
                 <Option value={item.machineryId} key={item.machineryId}>
213
                 <Option value={item.machineryId} key={item.machineryId}>
215
               ))}
216
               ))}
216
             </Select>
217
             </Select>
217
           </FormItem>
218
           </FormItem>
218
-          {/* <FormItem label="选择农机" request={getMachineryList}>
219
-            <Input placeholder='请输入农机名称' name="name" rules={[{ required: true }]} />
220
-          </FormItem> */}
221
           <FormItem label=" " colon={false}>
219
           <FormItem label=" " colon={false}>
222
             <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
220
             <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
223
               取消
221
               取消