Bladeren bron

项目类型

魏熙美 5 jaren geleden
bovenliggende
commit
25ff71f52f

+ 6
- 1
config/config.js Bestand weergeven

@@ -127,6 +127,11 @@ export default {
127 127
                   name: '项目类型',
128 128
                   component: './building/type/index',
129 129
                 },
130
+                {
131
+                  path: '/building/type/edi',
132
+                  name: '',
133
+                  component: './building/type/edi',
134
+                },
130 135
               ],
131 136
             },
132 137
             {
@@ -276,7 +281,7 @@ export default {
276 281
   
277 282
   proxy: {
278 283
     '/api/': {
279
-      target: 'http://192.168.0.84:8080/',
284
+      target: 'http://localhost:8080/',
280 285
       changeOrigin: true,
281 286
       // pathRewrite: { '^/server': '' },
282 287
     },

+ 35
- 15
src/pages/building/list/index.jsx Bestand weergeven

@@ -1,5 +1,6 @@
1 1
 import React, { useState, useEffect } from 'react';
2
-import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination } from 'antd';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert } from 'antd';
3
+import moment from 'moment';
3 4
 import request from '../../../utils/request';
4 5
 import apis from '../../../services/apis';
5 6
 import Styles from './style.less';
@@ -23,7 +24,7 @@ function CartBody(props) {
23 24
           <Card
24 25
             hoverable
25 26
             style={{ minWidth: '400px', borderRadius: '12px', margin: '10px', boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)' }}
26
-            cover={<img alt="example" src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png" style={{ borderRadius: '12px 12px 0 0', width: '100%', height: '14vw' }}></img>}
27
+            cover={<img alt="example" src={ data.poster } style={{ borderRadius: '12px 12px 0 0', width: '100%', height: '14vw' }}></img>}
27 28
             bodyStyle={{ padding: '10px 20px' }}
28 29
           >
29 30
             <p className={Styles.cardText}>
@@ -46,7 +47,7 @@ function CartBody(props) {
46 47
             </p>
47 48
             <p className={Styles.cardItem}>
48 49
               <span className={Styles.title}>项目地址</span>
49
-              <span >:{ data.address }</span>
50
+              <span className={ Styles.address }>:{ data.address }</span>
50 51
             </p>
51 52
             <p className={Styles.cardItem}>
52 53
               <span className={Styles.title}>发布状态</span>
@@ -54,7 +55,7 @@ function CartBody(props) {
54 55
             </p>
55 56
             <p className={Styles.cardItem}>
56 57
               <span className={Styles.title}>录入时间</span>
57
-              <span >:2019-08-28 17</span>
58
+              <span >:{ data.createDate }</span>
58 59
             </p>
59 60
             <p style={{ margin: '15px 0', position: 'relative', fontSize: '18px' }}>
60 61
               <span style={{ color: '#1990FF' }}>
@@ -82,17 +83,29 @@ function body(props) {
82 83
   const { getFieldDecorator } = props.form
83 84
 
84 85
   // eslint-disable-next-line react-hooks/rules-of-hooks
85
-  const { dataSource, setDataSource } = useState(tempDate || [])
86
-  console.log(dataSource)
86
+  const [dataSource, setDataSource] = useState({ records: [] })
87 87
 
88 88
   // eslint-disable-next-line react-hooks/rules-of-hooks
89 89
   useEffect(() => {
90
+    getList({ pageNum: 1, pageSize: 9 })
91
+  }, [])
92
+
93
+  function getList(params) {
90 94
     // 网路请求
91
-    request({ ...apis.building }).then(res => {
95
+    request({ ...apis.building.getList, params: { ...params } }).then(res => {
92 96
       setDataSource(res)
97
+    }).catch(err => {
98
+      // eslint-disable-next-line no-unused-expressions
99
+      <Alert
100
+        style={{
101
+          marginBottom: 24,
102
+        }}
103
+        message={err}
104
+        type="error"
105
+        showIcon
106
+      />
93 107
     })
94
-  })
95
-
108
+  }
96 109
 
97 110
   // 提交事件
98 111
   function handleSubmit(e) {
@@ -101,6 +114,8 @@ function body(props) {
101 114
       if (!err) {
102 115
         // eslint-disable-next-line no-console
103 116
         console.log('提交数据: ', values)
117
+        const { startDate } = values
118
+        getList({ pageNum: 1, pageSize: 9, ...values })
104 119
       }
105 120
     });
106 121
   }
@@ -113,8 +128,13 @@ function body(props) {
113 128
 
114 129
   // 分页
115 130
   function onChange(pageNumber) {
116
-    // eslint-disable-next-line no-console
117
-    console.log('Page: ', pageNumber);
131
+    // eslint-disable-next-line react-hooks/rules-of-hooks
132
+      getList({ pageNum: pageNumber, pageSize: 9 })
133
+  }
134
+
135
+  function getDate(value, dateString) {
136
+    // moment(value).format('YYYY-MM-DD HH:mm:ss')
137
+    console.log(value, dateString)
118 138
   }
119 139
 
120 140
   return (
@@ -139,7 +159,7 @@ function body(props) {
139 159
         </Form.Item>
140 160
         <Form.Item>
141 161
           {getFieldDecorator('startDate')(
142
-            <DatePicker placeholder="开盘时间" />,
162
+            <DatePicker placeholder="开盘时间" format="YYYY-MM-DD" onChange={getDate} />,
143 163
           )}
144 164
         </Form.Item>
145 165
         <Form.Item>
@@ -187,16 +207,16 @@ function body(props) {
187 207
       {/* 卡片内容,显示楼盘项目  */}
188 208
       <Row style={{ padding: ' 0 10px' }}>
189 209
         {
190
-          dataSource.map((item, index) => (
210
+          dataSource.records.map((item, index) => (
191 211
               <Col span={8}>
192
-                <CartBody data={item} key={item.code}/>
212
+                <CartBody data={item} key={item.buildingId}/>
193 213
               </Col>
194 214
             ))
195 215
         }
196 216
       </Row>
197 217
       {/* 分页 */}
198 218
       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
199
-        <Pagination showQuickJumper defaultCurrent={1} total={500} onChange={onChange} />
219
+        <Pagination showQuickJumper defaultCurrent={1} total={dataSource.total} onChange={onChange} />
200 220
       </div>
201 221
     </>
202 222
   );

+ 54
- 0
src/pages/building/list/style.css Bestand weergeven

@@ -0,0 +1,54 @@
1
+.SubmitButton {
2
+  background: #3a91d5;
3
+  border-radius: 7px;
4
+  border: 0px;
5
+}
6
+.SelectFrom {
7
+  width: 180px;
8
+  background: #ffffff;
9
+  border-radius: 7px;
10
+  border: 1px solid #dbdbdb;
11
+}
12
+.addButton {
13
+  background: #50be00;
14
+  border-radius: 4px;
15
+  border: 0px;
16
+  margin: 10px 0px;
17
+}
18
+.cardText {
19
+  font-size: 18px;
20
+  color: #333;
21
+  line-height: 24px;
22
+  display: flex;
23
+  align-items: center;
24
+  position: relative;
25
+}
26
+.cardItem {
27
+  font-size: 18px;
28
+  font-weight: 400;
29
+  color: #666;
30
+  line-height: 24px;
31
+  display: flex;
32
+  align-items: center;
33
+}
34
+.ediText {
35
+  font-size: 18px;
36
+  color: #ff925c;
37
+  line-height: 24px;
38
+  position: absolute;
39
+  right: 0;
40
+}
41
+.title {
42
+  display: inline-block;
43
+  width: 84px;
44
+  justify-content: space-between;
45
+  text-align: justify;
46
+  text-align-last: justify;
47
+}
48
+.address {
49
+  width: 400px;
50
+  height: 24px;
51
+  text-overflow: ellipsis;
52
+  white-space: nowrap;
53
+  overflow: hidden;
54
+}

+ 10
- 1
src/pages/building/list/style.less Bestand weergeven

@@ -45,4 +45,13 @@
45 45
   justify-content: space-between;
46 46
   text-align: justify;
47 47
   text-align-last:justify
48
-}
48
+}
49
+
50
+.address { 
51
+  width: 400px;
52
+  height: 24px; 
53
+  text-overflow: ellipsis; 
54
+  white-space: nowrap;
55
+  overflow: hidden;
56
+}
57
+

+ 54
- 0
src/pages/building/list/style.wxss Bestand weergeven

@@ -0,0 +1,54 @@
1
+.SubmitButton {
2
+  background: #3a91d5;
3
+  border-radius: 7px;
4
+  border: 0px;
5
+}
6
+.SelectFrom {
7
+  width: 180px;
8
+  background: #ffffff;
9
+  border-radius: 7px;
10
+  border: 1px solid #dbdbdb;
11
+}
12
+.addButton {
13
+  background: #50be00;
14
+  border-radius: 4px;
15
+  border: 0px;
16
+  margin: 10px 0px;
17
+}
18
+.cardText {
19
+  font-size: 18px;
20
+  color: #333;
21
+  line-height: 24px;
22
+  display: flex;
23
+  align-items: center;
24
+  position: relative;
25
+}
26
+.cardItem {
27
+  font-size: 18px;
28
+  font-weight: 400;
29
+  color: #666;
30
+  line-height: 24px;
31
+  display: flex;
32
+  align-items: center;
33
+}
34
+.ediText {
35
+  font-size: 18px;
36
+  color: #ff925c;
37
+  line-height: 24px;
38
+  position: absolute;
39
+  right: 0;
40
+}
41
+.title {
42
+  display: inline-block;
43
+  width: 84px;
44
+  justify-content: space-between;
45
+  text-align: justify;
46
+  text-align-last: justify;
47
+}
48
+.address {
49
+  width: 400px;
50
+  height: 24px;
51
+  text-overflow: ellipsis;
52
+  white-space: nowrap;
53
+  overflow: hidden;
54
+}

+ 78
- 0
src/pages/building/type/edi.jsx Bestand weergeven

@@ -0,0 +1,78 @@
1
+import React from 'react';
2
+import { Input, Button, Row, Col, Form, Alert } from 'antd';
3
+import router from 'umi/router';
4
+import Styles from './style.less';
5
+import request from '../../../utils/request';
6
+import apis from '../../../services/apis';
7
+
8
+function body(props) {
9
+  const { getFieldDecorator } = props.form;
10
+
11
+  console.log('id: ', props.location.query.id)
12
+
13
+  function handleSubmit(e) {
14
+    e.preventDefault();
15
+    props.form.validateFields((err, values) => {
16
+      if (!err) {
17
+        // 提交数据
18
+        values.status = 1
19
+        values.createDate = new Date()
20
+        submitData(values)
21
+      }
22
+    });
23
+  }
24
+
25
+  function submitData(data) {
26
+    request({ ...apis.buildingType.add, data: { ...data } }).then(() => {
27
+      // eslint-disable-next-line no-unused-expressions
28
+      <Alert
29
+        style={{
30
+          marginBottom: 24,
31
+        }}
32
+        message="操作成功"
33
+        type="success"
34
+        showIcon
35
+      />
36
+      router.go(-1)
37
+    }).catch(err => {
38
+      // eslint-disable-next-line no-unused-expressions
39
+      <Alert
40
+        style={{
41
+          marginBottom: 24,
42
+        }}
43
+        message={ err }
44
+        type="err"
45
+        showIcon
46
+      />
47
+    })
48
+  }
49
+
50
+  return (
51
+    <>
52
+        <Form onSubmit={handleSubmit} style={{ width: '500px', margin: 'auto' }}>
53
+          <Form.Item>
54
+            {getFieldDecorator('buildingTypeName', {
55
+              rules: [{ required: true, message: '请输入名称' }],
56
+            })(
57
+              <Input
58
+                placeholder="名称"
59
+              />,
60
+            )}
61
+          </Form.Item>
62
+          <Form.Item style={{ display: 'flex', justifyContent: 'space-between' }}>
63
+            <Button type="primary" htmlType="submit" className={ Styles.addButton } style={{ margin: '0' }}>
64
+              确定
65
+            </Button>
66
+            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
67
+            <Button onClick={() => router.go(-1)}>
68
+              取消
69
+            </Button>
70
+          </Form.Item>
71
+        </Form>
72
+    </>
73
+  )
74
+}
75
+
76
+const WrappedBuidingTypeForm = Form.create({ name: 'body' })(body);
77
+
78
+export default WrappedBuidingTypeForm

+ 88
- 55
src/pages/building/type/index.jsx Bestand weergeven

@@ -1,73 +1,106 @@
1
-import React, { useState } from 'react';
2
-import { Button, Table, Pagination } from 'antd'
1
+import React, { useState, useEffect } from 'react';
2
+import { Button, Table, Pagination, Alert, Icon, Tag } from 'antd'
3
+import router from 'umi/router';
4
+import moment from 'moment';
3 5
 import Styles from './style.less'
6
+import request from '../../../utils/request';
7
+import apis from '../../../services/apis';
4 8
 
5
-const dataSource = [
6
-  {
7
-    key: '1',
8
-    name: '胡彦斌',
9
-    age: 32,
10
-    address: '西湖区湖底公园1号',
11
-  },
12
-  {
13
-    key: '2',
14
-    name: '胡彦祖',
15
-    age: 42,
16
-    address: '西湖区湖底公园1号',
17
-  },
18
-];
19
-
20
-const columns = [
21
-  {
22
-    title: '姓名',
23
-    dataIndex: 'name',
24
-    key: 'name',
25
-  },
26
-  {
27
-    title: '年龄',
28
-    dataIndex: 'age',
29
-    key: 'age',
30
-  },
31
-  {
32
-    title: '住址',
33
-    dataIndex: 'address',
34
-    key: 'address',
35
-  },
36
-];
9
+function body() {
10
+  // eslint-disable-next-line react-hooks/rules-of-hooks
11
+  const [data, setData] = useState([{ records: [] }])
37 12
 
38
-// 分页
39
-function onChange(pageNumber, set) {
40
-  // eslint-disable-next-line no-console
41
-  console.log('Page: ', pageNumber);
42
-  const data = [
13
+  const columns = [
14
+    {
15
+      title: '编号',
16
+      dataIndex: 'buildingTypeId',
17
+      key: 'buildingTypeId',
18
+    },
19
+    {
20
+      title: '类型名称',
21
+      dataIndex: 'buildingTypeName',
22
+      key: 'buildingTypeName',
23
+      render: (_, record) => <Tag color="blue" onClick={() => toEdi(record.buildingTypeId)}>{ record.buildingTypeName }</Tag>,
24
+    },
43 25
     {
44
-      key: '1',
45
-      name: '一号',
46
-      age: 32,
47
-      address: '西湖区湖底公园1号',
26
+      title: '创建时间',
27
+      dataIndex: 'createDate',
28
+      key: 'createDate',
29
+      render: (_, record) => <sapn>{moment(record.createDate).format('YYYY-MM-DD')}</sapn>,
48 30
     },
49 31
     {
50
-      key: '2',
51
-      name: '二号',
52
-      age: 42,
53
-      address: '西湖区湖底公园1号',
32
+      title: '操作',
33
+      dataIndex: 'row',
34
+      key: 'row',
35
+      render: (_, record) => (
36
+        <span onClick={() => deleteType(record)}>
37
+          <span style={{
38
+              color: '#FF4A4A', right: '0',
39
+          }} >
40
+              删除
41
+          <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
42
+          </span>
43
+        </span>
44
+      ),
54 45
     },
55 46
   ];
56 47
 
57
-  set(data)
58
-}
59
-
60
-function body() {
61 48
   // eslint-disable-next-line react-hooks/rules-of-hooks
62
-  const [data, setData] = useState(dataSource || [])
49
+  useEffect(() => {
50
+    getList({ pageNum: 1, pageSize: 10 })
51
+  }, [])
52
+
53
+  function getList(params) {
54
+    request({ ...apis.buildingType.getList, params: { ...params } }).then(res => {
55
+      setData(res)
56
+    }).catch(err => {
57
+      // eslint-disable-next-line no-unused-expressions
58
+      <Alert
59
+        style={{
60
+          marginBottom: 24,
61
+        }}
62
+        message={err}
63
+        type="error"
64
+        showIcon
65
+      />
66
+    })
67
+  }
68
+
69
+  // 分页
70
+  function onChange(pageNumber) {
71
+    // eslint-disable-next-line no-console
72
+    console.log('Page: ', pageNumber);
73
+    getList({ pageNum: pageNumber, pageSize: 10 })
74
+  }
75
+
76
+  // 删除
77
+  function deleteType(row) {
78
+    const { url, method } = apis.buildingType.update
79
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(row.buildingTypeId)
80
+
81
+    row.status = -1
82
+    request({ url: tempUrl, method, data: { ...row } }).then(() => {
83
+      getList({ pageNum: data.current, pageSize: 10 })
84
+    })
85
+  }
86
+
87
+  // 跳转修改页
88
+  function toEdi(id) {
89
+    router.push({
90
+      pathname: '/building/type/edi',
91
+      query: {
92
+        id,
93
+      },
94
+    });
95
+  }
63 96
 
64 97
   return (
65 98
     <>
66
-      <Button type="primary" className={Styles.addButton}>新增类型</Button>
67
-      <Table dataSource={data} columns={columns} pagination={false}/>
99
+      <Button type="primary" className={Styles.addButton} onClick={toEdi}>新增类型</Button>
100
+      <Table dataSource={data.records} columns={columns} pagination={false}/>
68 101
       {/* 分页 */}
69 102
       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
70
-        <Pagination showQuickJumper defaultCurrent={1} total={500} onChange={e => onChange(e, setData)} />
103
+        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={onChange} />
71 104
       </div>
72 105
     </>
73 106
   )

+ 19
- 1
src/services/apis.js Bestand weergeven

@@ -13,8 +13,26 @@ export default {
13 13
   },
14 14
   building: {
15 15
     getList: {
16
-      methods: 'GET',
16
+      method: 'GET',
17 17
       url: `${prefix}/buildinglist`,
18 18
     },
19 19
   },
20
+  buildingType: {
21
+    getList: {
22
+      method: 'GET',
23
+      url: `${prefix}/tdBuildingType`,
24
+    },
25
+    delete: {
26
+      method: 'DELETE',
27
+      url: `${prefix}/tdBuildingType/id`,
28
+    },
29
+    update: {
30
+      method: 'PUT',
31
+      url: `${prefix}/tdBuildingType/id`,
32
+    },
33
+    add: {
34
+      method: 'POST',
35
+      url: `${prefix}/tdBuildingType`,
36
+    },
37
+  },
20 38
 }