ソースを参照

Merge branch 'master' of http://git.ycjcjy.com/nanyang/machinery-admin

Yansen 2 年 前
コミット
e97935fd05
共有2 個のファイルを変更した57 個の追加59 個の削除を含む
  1. 1
    1
      config/proxy.js
  2. 56
    58
      src/pages/SystemManagement/Sensing/index.jsx

+ 1
- 1
config/proxy.js ファイルの表示

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

+ 56
- 58
src/pages/SystemManagement/Sensing/index.jsx ファイルの表示

@@ -1,18 +1,16 @@
1 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 3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
4 4
 import moment from 'moment';
5
+import { history } from 'umi';
5 6
 import PageTable from '@/components/PageTable';
6 7
 import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
7
-import { addMachinery, getMachineryList } from '@/services/machinery';
8
+import { getMachineryList } from '@/services/machinery';
8 9
 import { getMachineryTypeList } from '@/services/machineryType';
9
-import { queryTable } from '@/utils/request';
10 10
 
11
-const { Option } = Select;
12 11
 const formatterTime = (val) => {
13 12
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
14 13
 };
15
-const FormItem = Form.Item;
16 14
 
17 15
 export default (props) => {
18 16
   // 绑定表单
@@ -20,32 +18,50 @@ export default (props) => {
20 18
   const [form] = Form.useForm();
21 19
   const [editModal, setEditModal] = useState(false);
22 20
   const [loading, setLoading] = useState(false);
23
-  const [deviceId, setdeviceId] = useState();
24 21
   const [machineryId, setMachineryId] = useState();
25
-  const [machineryTypeList, setMachineryTypeList] = useState([]);
22
+  const [device, setDeviceList] = useState();
23
+  const [deviceId, setDeviceId] = useState();
26 24
   const actionRef = useRef();
27
-  const [machineryList, setMachineryList] = useState([]);
25
+  const [machineryTypeList, setMachineryTypeList] = useState([]);
28 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 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 64
     form.setFieldsValue(val);
48
-    setEditModal(true);
49 65
   };
50 66
 
51 67
   //绑定弹窗关闭
@@ -57,27 +73,14 @@ export default (props) => {
57 73
 
58 74
   // 绑定提交
59 75
   const Submit = (values) => {
76
+    let params = { ...device, ...values };
60 77
     setLoading(true);
61
-    addDevice(values).then(() => {
78
+    addDevice(params).then((res) => {
62 79
       setLoading(false);
63 80
       message.success(`绑定成功`);
64
-      onCancel();
65 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 86
   useEffect(() => {
@@ -86,26 +89,17 @@ export default (props) => {
86 89
     }).catch((err) => {
87 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 94
   useEffect(() => {
97 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 97
         setMachineryList(e.records);
105 98
       }).catch((err) => {
106 99
         console.log(err.message)
107 100
       });
108 101
     }
102
+
109 103
   }, [typeId])
110 104
 
111 105
   const columns = [
@@ -124,7 +118,14 @@ export default (props) => {
124 118
       title: '设备类型',
125 119
       dataIndex: 'deviceType',
126 120
       key: 'deviceType',
127
-      valueType: 'select',
121
+      valueEnum: {
122
+        shensong: {
123
+          text: '深松',
124
+        },
125
+        feifang: {
126
+          text: '飞防',
127
+        },
128
+      },
128 129
       // request: () => queryTable(getDeviceList)(),
129 130
     },
130 131
     {
@@ -154,10 +155,10 @@ export default (props) => {
154 155
       valueType: 'option',
155 156
       width: 160,
156 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 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 163
         </Button>,
163 164
         <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
@@ -197,8 +198,8 @@ export default (props) => {
197 198
         machineryId={machineryId}
198 199
       >
199 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 203
               {machineryTypeList.map((item) => (
203 204
                 <Option value={item.typeId} key={item.typeId}>
204 205
                   {item.name}
@@ -206,7 +207,7 @@ export default (props) => {
206 207
               ))}
207 208
             </Select>
208 209
           </FormItem>
209
-          <FormItem label="选择农机" rules={[{ required: true, message: '请选择农机名' }]}>
210
+          <FormItem label="选择农机" name="machineryId" rules={[{ required: true, message: '请选择农机名' }]}>
210 211
             <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
211 212
               {machineryList.map((item) => (
212 213
                 <Option value={item.machineryId} key={item.machineryId}>
@@ -215,9 +216,6 @@ export default (props) => {
215 216
               ))}
216 217
             </Select>
217 218
           </FormItem>
218
-          {/* <FormItem label="选择农机" request={getMachineryList}>
219
-            <Input placeholder='请输入农机名称' name="name" rules={[{ required: true }]} />
220
-          </FormItem> */}
221 219
           <FormItem label=" " colon={false}>
222 220
             <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
223 221
               取消