瀏覽代碼

项目类型

魏熙美 5 年之前
父節點
當前提交
ccb4fc5e7a
共有 3 個文件被更改,包括 56 次插入9 次删除
  1. 49
    6
      src/pages/building/type/edi.jsx
  2. 3
    3
      src/pages/building/type/index.jsx
  3. 4
    0
      src/services/apis.js

+ 49
- 6
src/pages/building/type/edi.jsx 查看文件

@@ -1,4 +1,4 @@
1
-import React from 'react';
1
+import React, { useState, useEffect } from 'react';
2 2
 import { Input, Button, Row, Col, Form, Alert } from 'antd';
3 3
 import router from 'umi/router';
4 4
 import Styles from './style.less';
@@ -8,22 +8,48 @@ import apis from '../../../services/apis';
8 8
 function body(props) {
9 9
   const { getFieldDecorator } = props.form;
10 10
 
11
-  console.log('id: ', props.location.query.id)
11
+  // eslint-disable-next-line react-hooks/rules-of-hooks
12
+  let data = {}
13
+  const { id } = props.location.query;
14
+
15
+  if (id !== '') {
16
+    // eslint-disable-next-line react-hooks/rules-of-hooks
17
+    useEffect(() => {
18
+      getById(id)
19
+    }, [])
20
+  }
12 21
 
13 22
   function handleSubmit(e) {
14 23
     e.preventDefault();
15 24
     props.form.validateFields((err, values) => {
16 25
       if (!err) {
17 26
         // 提交数据
18
-        values.status = 1
19
-        values.createDate = new Date()
20 27
         submitData(values)
21 28
       }
22 29
     });
23 30
   }
24 31
 
25
-  function submitData(data) {
26
-    request({ ...apis.buildingType.add, data: { ...data } }).then(() => {
32
+  // 获取详情信息
33
+  function getById(currentId) {
34
+    const { url, method } = apis.buildingType.getById
35
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(currentId)
36
+
37
+    request({ url: tempUrl, method }).then(res => {
38
+      data = res
39
+      props.form.setFieldsValue(res)
40
+    })
41
+  }
42
+
43
+  function submitData(dataSources) {
44
+    if (id !== '') {
45
+      // 修改
46
+      updateType(dataSources)
47
+      return
48
+    }
49
+
50
+    dataSources.status = 1
51
+    dataSources.createDate = new Date()
52
+    request({ ...apis.buildingType.add, data: { ...dataSources } }).then(() => {
27 53
       // eslint-disable-next-line no-unused-expressions
28 54
       <Alert
29 55
         style={{
@@ -47,9 +73,26 @@ function body(props) {
47 73
     })
48 74
   }
49 75
 
76
+    // 修改
77
+    function updateType(row) {
78
+      const { url, method } = apis.buildingType.update
79
+      const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(row.buildingTypeId)
80
+
81
+      request({ url: tempUrl, method, data: { ...row } }).then(() => {
82
+        router.go(-1)
83
+      })
84
+    }
85
+
50 86
   return (
51 87
     <>
52 88
         <Form onSubmit={handleSubmit} style={{ width: '500px', margin: 'auto' }}>
89
+          <Form.Item style={{ display: 'none' }}>
90
+            {getFieldDecorator('buildingTypeId')(
91
+              <Input
92
+                placeholder="buildingTtypeId"
93
+              />,
94
+            )}
95
+          </Form.Item>
53 96
           <Form.Item>
54 97
             {getFieldDecorator('buildingTypeName', {
55 98
               rules: [{ required: true, message: '请输入名称' }],

+ 3
- 3
src/pages/building/type/index.jsx 查看文件

@@ -85,18 +85,18 @@ function body() {
85 85
   }
86 86
 
87 87
   // 跳转修改页
88
-  function toEdi(id) {
88
+  function toEdi(currentId) {
89 89
     router.push({
90 90
       pathname: '/building/type/edi',
91 91
       query: {
92
-        id,
92
+        id: currentId || '',
93 93
       },
94 94
     });
95 95
   }
96 96
 
97 97
   return (
98 98
     <>
99
-      <Button type="primary" className={Styles.addButton} onClick={toEdi}>新增类型</Button>
99
+      <Button type="primary" className={Styles.addButton} onClick={() => toEdi()}>新增类型</Button>
100 100
       <Table dataSource={data.records} columns={columns} pagination={false}/>
101 101
       {/* 分页 */}
102 102
       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>

+ 4
- 0
src/services/apis.js 查看文件

@@ -34,5 +34,9 @@ export default {
34 34
       method: 'POST',
35 35
       url: `${prefix}/tdBuildingType`,
36 36
     },
37
+    getById: {
38
+      method: 'GET',
39
+      url: `${prefix}/tdBuildingType/id`,
40
+    },
37 41
   },
38 42
 }