张延森 3 years ago
parent
commit
cb7f710962

+ 1
- 0
config/config.js View File

@@ -75,6 +75,7 @@ export default {
75 75
   targets: {
76 76
     ie: 11,
77 77
   },
78
+  history: 'hash',
78 79
   // umi routes: https://umijs.org/zh/guide/router.html
79 80
   routes,
80 81
   // Theme for antd: https://ant.design/docs/react/customize-theme-cn

+ 42
- 5
src/pages/building/Edit/Apartment/Form.jsx View File

@@ -1,22 +1,59 @@
1
-import React from 'react'
2
-import { Button, Form, Input, Select } from 'antd'
1
+import React, { useEffect, useState } from 'react'
2
+import { Button, Form, Input, message, Select } from 'antd'
3 3
 import ImageUpload from '@/components/XForm/ImageUpload'
4
+import { fetch, apis } from '@/utils/request'
4 5
 import ModalForm from '../components/ModalForm'
5 6
 import InputNumber from '../components/InputNumber'
6 7
 import { validMinNum } from '../utils'
7 8
 
8 9
 const Option = Select.Option
9 10
 const fullWidth = { width: '100%' }
11
+const saveData = fetch(apis.building.buildingApartmentAdd)
12
+const updateData = fetch(apis.building.buildingApartmentUpdate)
10 13
 
11 14
 const AMForm = (props) => {
12
-  const { visible, onCancel, form } = props
13
-  const { getFieldDecorator } = form
15
+  const { visible, onCancel, form, onSubmit } = props
16
+  const { getFieldDecorator, setFieldsValue, resetFields, validateFields } = form
17
+
18
+  const [loading, setLoading] = useState(false)
19
+
20
+  const handleSubmit = (e) => {
21
+    e.preventDefault();
22
+    validateFields((err, values) => {
23
+      if (err) {
24
+        console.error(err)
25
+        return
26
+      }
27
+
28
+      const request = props.formData.apartmentId ? updateData : saveData
29
+      const data = {
30
+        ...(props.formData),
31
+        ...values,
32
+      }
33
+
34
+      setLoading(true)
35
+      request({ data }).then((res) => {
36
+        setLoading(false)
37
+        message.success('操作成功')
38
+        props.onSuccess(res)
39
+      }).catch((err) => {
40
+        setLoading(false)
41
+        console.error(err)
42
+      })
43
+    })
44
+  }
45
+
46
+  useEffect(() => {
47
+    resetFields()
48
+    setFieldsValue(props.formData || {})
49
+  }, [props.formData])
14 50
 
15 51
   return (
16 52
     <ModalForm
17 53
       title="户型设置"
18 54
       visible={visible}
19 55
       onCancel={onCancel}
56
+      onSubmit={handleSubmit}
20 57
     >
21 58
       <Form.Item label="编号" style={{ display: 'none' }}>
22 59
           {getFieldDecorator('apartmentId')(<Input />)}
@@ -68,7 +105,7 @@ const AMForm = (props) => {
68 105
           })(<InputNumber min={0} step={1} style={fullWidth} />)}
69 106
       </Form.Item>
70 107
       <Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
71
-        <Button style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
108
+        <Button loading={loading} style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
72 109
         <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button>
73 110
       </Form.Item>
74 111
     </ModalForm>

+ 9
- 3
src/pages/building/Edit/Apartment/List.jsx View File

@@ -1,8 +1,8 @@
1 1
 import React from 'react'
2
-import { Button, Table } from 'antd'
2
+import { Button, Table, Popconfirm } from 'antd'
3
+import moment from 'moment'
3 4
 
4 5
 export default (props) => {
5
-  
6 6
   const columns = [
7 7
     {
8 8
       title: '户型名称',
@@ -56,6 +56,12 @@ export default (props) => {
56 56
   ]
57 57
 
58 58
   return (
59
-    <Table columns={columns} style={{marginTop: '1em', width: '100%'}} rowKey="apartmentId" />
59
+    <Table
60
+      loading={props.loading}
61
+      dataSource={props.dataSource}
62
+      columns={columns}
63
+      style={{marginTop: '1em', width: '100%'}}
64
+      rowKey="apartmentId"
65
+    />
60 66
   )
61 67
 }

+ 58
- 5
src/pages/building/Edit/Apartment/index.jsx View File

@@ -1,18 +1,71 @@
1
-import React, { useState } from 'react'
2
-import { Button } from 'antd'
1
+import React, { useEffect, useState, useRef } from 'react'
2
+import { Button, message } from 'antd'
3
+import { fetch, apis } from '@/utils/request'
3 4
 import Form from './Form'
4 5
 import List from './List'
5 6
 
7
+const fetchList = fetch(apis.building.buildingApartment)
8
+const deleteData = fetch(apis.building.buildingApartmentDelete)
9
+
6 10
 export default (props) => {
11
+  const { history } = props;
12
+  const { query } = history.location;
13
+  const { id } = query;
14
+
7 15
   const [visible, setVisible] = useState(false)
16
+  const [loading, setLoading] = useState(false)
17
+  const [list, setList] = useState([])
18
+  const apartmentRef = useRef()
19
+
20
+  const getList = () => {
21
+    const urlData = { id }
22
+    const params = { apartmentType: 'apart' }
23
+
24
+    setLoading(true)
25
+    fetchList({ urlData, params }).then((res) => {
26
+      setList(res || [])
27
+      setLoading(false)
28
+    }).catch((err) => {
29
+      console.error(err.message || err)
30
+      setLoading(false)
31
+    })
32
+  }
33
+
34
+  const handleEdit = (record) => {
35
+    apartmentRef.current = record
36
+    setVisible(true)
37
+  }
38
+
39
+  const handleDelete = (record) => {
40
+    const urlData = { id: record.apartmentId }
41
+
42
+    setLoading(true)
43
+    deleteData({ urlData }).then(() => {
44
+      getList()
45
+      message.success('删除成功')
46
+      setLoading(false)
47
+    }).catch((err) => {
48
+      console.error(err.message || err)
49
+      setLoading(false)
50
+    })
51
+  }
52
+
53
+  const handleSuccess = () => {
54
+    getList()
55
+    setVisible(false)
56
+  }
57
+
58
+  useEffect(() => {
59
+    getList()
60
+  }, [id])
8 61
 
9 62
   return (
10 63
     <div>
11 64
       <div>
12
-        <Button type="primary" onClick={() => setVisible(true)}>新增户型</Button>
65
+        <Button type="primary" onClick={handleEdit}>新增户型</Button>
13 66
       </div>
14
-      <Form visible={visible} onCancel={() => setVisible(false)} />
15
-      <List />
67
+      <Form visible={visible} onCancel={() => setVisible(false)} formData={apartmentRef.current} onSuccess={handleSuccess} />
68
+      <List loading={loading} dataSource={list} onEdit={handleEdit} onDelete={handleDelete} />
16 69
     </div>
17 70
   )
18 71
 }

+ 6
- 1
src/pages/building/Edit/Basic/index.jsx View File

@@ -17,6 +17,7 @@ import usePois from './usePois'
17 17
 import useQuery from './useQuery'
18 18
 import useBrands from './useBrands'
19 19
 import { initForm, saveData } from './form'
20
+import { router } from 'umi'
20 21
 
21 22
 const fullWidth= { width: '100%' }
22 23
 const Item = Form.Item
@@ -101,9 +102,13 @@ const BuildingBasic = React.forwardRef((props, ref) => {
101 102
           ...values,
102 103
           pois,
103 104
           arrounds,
104
-        }).then(() => {
105
+        }).then((res) => {
105 106
           updateFormLoading(false)
106 107
           notification.success({ message: '保存项目基础信息成功' })
108
+
109
+          if (!id) {
110
+            router.replace(`/building/add?id=${res.buildingId}`)
111
+          }
107 112
         }).catch((err) => {
108 113
           console.error(err)
109 114
           updateFormLoading(false)

+ 1
- 1
src/utils/request.js View File

@@ -46,7 +46,7 @@ request.interceptors.request.use((url, options) => {
46 46
 
47 47
   return (
48 48
     {
49
-      // url: 'http://81.69.196.8:8567' + apiURL,
49
+      // url: 'https://xlk.njyz.tech' + apiURL,
50 50
       url: apiURL,
51 51
       options: {
52 52
         ...opts,