魏熙美 hace 5 años
padre
commit
8f917257b4

+ 1
- 1
config/config.js Ver fichero

@@ -455,7 +455,7 @@ export default {
455 455
 
456 456
   proxy: {
457 457
     '/api/': {
458
-      target: 'http://192.168.0.84:8080/',
458
+      target: 'http://localhost:8080/',
459 459
       changeOrigin: true,
460 460
       // pathRewrite: { '^/server': '' },
461 461
     },

+ 74
- 0
src/components/XForm/ImageListUpload.jsx Ver fichero

@@ -0,0 +1,74 @@
1
+import React from 'react';
2
+import { Upload, Icon, Modal } from 'antd';
3
+import './style.less';
4
+import { uploaderProps } from '../../utils/upload';
5
+
6
+function getBase64(file) {
7
+  return new Promise((resolve, reject) => {
8
+    const reader = new FileReader();
9
+    reader.readAsDataURL(file);
10
+    reader.onload = () => resolve(reader.result);
11
+    reader.onerror = error => reject(error);
12
+  });
13
+}
14
+
15
+class ImageListUpload extends React.Component {
16
+  state = {
17
+    previewVisible: false,
18
+    previewImage: '',
19
+    fileList: [],
20
+  };
21
+
22
+  handleCancel = () => this.setState({ previewVisible: false });
23
+
24
+  handlePreview = async file => {
25
+    if (!file.url && !file.preview) {
26
+      file.preview = await getBase64(file.originFileObj);
27
+    }
28
+
29
+    this.setState({
30
+      previewImage: file.url || file.preview,
31
+      previewVisible: true,
32
+    });
33
+  };
34
+
35
+  handleChange = ({ fileList }) => {
36
+    this.setState({ fileList })
37
+    if (typeof this.props.onChange === 'function') {
38
+      // return item.response.url
39
+      const images = fileList.filter(item => item.status === 'done')
40
+      this.props.onChange(images.map(item => item.response.url))
41
+    }
42
+  };
43
+
44
+  render() {
45
+    const { previewVisible, previewImage, fileList } = this.state;
46
+
47
+    const { value } = this.props
48
+
49
+    const uploadButton = (
50
+      <div>
51
+        <Icon type="plus" />
52
+        <div className="ant-upload-text">Upload</div>
53
+      </div>
54
+    );
55
+    return (
56
+      <div className="clearfix">
57
+        <Upload
58
+          listType="picture-card"
59
+          fileList={fileList || value}
60
+          onPreview={this.handlePreview}
61
+          onChange={this.handleChange}
62
+          { ...uploaderProps }
63
+        >
64
+          {fileList.length >= 8 ? null : uploadButton}
65
+        </Upload>
66
+        <Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
67
+          <img alt="example" style={{ width: '100%' }} src={previewImage} />
68
+        </Modal>
69
+      </div>
70
+    );
71
+  }
72
+}
73
+
74
+export default ImageListUpload;

+ 13
- 0
src/components/XForm/style.css Ver fichero

@@ -0,0 +1,13 @@
1
+:global .avatar-uploader > .ant-upload {
2
+  width: 128px;
3
+  height: 128px;
4
+}
5
+/* you can make up upload button and sample style by using stylesheets */
6
+.ant-upload-select-picture-card i {
7
+  font-size: 32px;
8
+  color: #999;
9
+}
10
+.ant-upload-select-picture-card .ant-upload-text {
11
+  margin-top: 8px;
12
+  color: #666;
13
+}

+ 12
- 0
src/components/XForm/style.less Ver fichero

@@ -6,3 +6,15 @@
6 6
     }
7 7
   }
8 8
 }
9
+
10
+
11
+/* you can make up upload button and sample style by using stylesheets */
12
+.ant-upload-select-picture-card i {
13
+  font-size: 32px;
14
+  color: #999;
15
+}
16
+
17
+.ant-upload-select-picture-card .ant-upload-text {
18
+  margin-top: 8px;
19
+  color: #666;
20
+}

+ 13
- 0
src/components/XForm/style.wxss Ver fichero

@@ -0,0 +1,13 @@
1
+:global .avatar-uploader > .ant-upload {
2
+  width: 128px;
3
+  height: 128px;
4
+}
5
+/* you can make up upload button and sample style by using stylesheets */
6
+.ant-upload-select-picture-card i {
7
+  font-size: 32px;
8
+  color: #999;
9
+}
10
+.ant-upload-select-picture-card .ant-upload-text {
11
+  margin-top: 8px;
12
+  color: #666;
13
+}

+ 60
- 13
src/pages/building/list/add/components/base.jsx Ver fichero

@@ -1,11 +1,12 @@
1 1
 import React, { useState, useEffect } from 'react';
2
-import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, InputNumber } from 'antd';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, InputNumber, notification } from 'antd';
3 3
 import moment from 'moment';
4 4
 import request from '../../../../../utils/request';
5 5
 import apis from '../../../../../services/apis';
6 6
 import Styles from '../style.less';
7 7
 import { router } from 'umi';
8 8
 import ImageUpload from '../../../../../components/XForm/ImageUpload'
9
+import ImageListUpload from '../../../../../components/XForm/ImageListUpload'
9 10
 import Wangedit from '../../../../../components/Wangedit/Wangedit'
10 11
 import TagGroup from './tags'
11 12
 
@@ -23,21 +24,67 @@ const formItemLayout = {
23 24
   },
24 25
 };
25 26
 
27
+
28
+function openNotificationWithIcon(type, message) {
29
+  notification[type]({
30
+    message,
31
+    description:
32
+      '',
33
+  });
34
+}
35
+
36
+
26 37
 function AddBuilding(props) {
27 38
   const { getFieldDecorator } = props.form;
28 39
 
40
+  if (props.building.buildingId !== undefined) {
41
+    const { buildingId } = props.building
42
+    if (buildingId !== '') {
43
+      // eslint-disable-next-line react-hooks/rules-of-hooks
44
+      useEffect(() => {
45
+        getById(buildingId)
46
+      }, [])
47
+    }
48
+  }
49
+
50
+   // 获取详情信息
51
+   function getById(currentId) {
52
+    const { url, method } = apis.building.buildingGetById
53
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(currentId)
54
+
55
+    request({ url: tempUrl, method }).then(res => {
56
+      res.openingDate = moment(res.openingDate)
57
+      res.receivedDate = moment(res.receivedDate)
58
+      props.form.setFieldsValue(res)
59
+    })
60
+  }
61
+
29 62
   function handleSubmit(e) {
30 63
     e.preventDefault();
31 64
     props.form.validateFieldsAndScroll((err, values) => {
32 65
       if (!err) {
33
-        console.log('Received values of form: ', values);
66
+        addBuilding(values)
34 67
       }
35 68
     });
36 69
   }
37 70
 
71
+  function addBuilding(data) {
72
+    data.openingDate = moment(data.openingDate, 'yyyy-MM-dd HH:mm:ss')
73
+    data.receivedDate = moment(data.receivedDate, 'yyyy-MM-dd HH:mm:ss')
74
+    data.buildingProjectType = []
75
+    // 项目主图
76
+    data.img = data.avatarImage && data.avatarImage.map((item, index) => ({ imgType: 'banner', url: item, orderNo: index + 1 }))
77
+
78
+    request({ ...apis.building.addBuilding, data: { ...data } }).then(() => {
79
+      openNotificationWithIcon('success', '操作成功')
80
+    }).catch(err => {
81
+      openNotificationWithIcon('error', err.message)
82
+    })
83
+  }
84
+
38 85
   return (
39 86
         <Form {...formItemLayout} onSubmit={handleSubmit}>
40
-          <Form.Item label="楼盘编号">
87
+          <Form.Item label="楼盘编号" hasFeedback>
41 88
             {getFieldDecorator('code')(<Input />)}
42 89
           </Form.Item>
43 90
           <Form.Item label="楼盘名称" hasFeedback>
@@ -47,13 +94,13 @@ function AddBuilding(props) {
47 94
             {getFieldDecorator('name')(<Input />)}
48 95
           </Form.Item>
49 96
           <Form.Item label="项目类型" hasFeedback>
50
-            {getFieldDecorator('name')(<Input />)}
97
+            {getFieldDecorator('buildingProjectType')(<Input />)}
51 98
           </Form.Item>
52 99
           <Form.Item label="均价" hasFeedback>
53 100
             {getFieldDecorator('price')(<Input />)}
54 101
           </Form.Item>
55 102
           <Form.Item label="开盘时间" hasFeedback>
56
-            {getFieldDecorator('openingDate')(<DatePicker />)}
103
+            {getFieldDecorator('openingDate')(<DatePicker format="YYYY/MM/DD" />)}
57 104
           </Form.Item>
58 105
           <Form.Item label="电话" hasFeedback>
59 106
             {getFieldDecorator('tel')(<Input />)}
@@ -79,17 +126,17 @@ function AddBuilding(props) {
79 126
             )}
80 127
           </Form.Item>
81 128
           <Form.Item label="项目主图" hasFeedback>
82
-            {getFieldDecorator('tags')(
83
-              <ImageUpload />,
129
+            {getFieldDecorator('avatarImage')(
130
+              <ImageListUpload />,
84 131
             )}
85 132
           </Form.Item>
86 133
           <Form.Item label="地址图片" hasFeedback>
87
-            {getFieldDecorator('tags')(
134
+            {getFieldDecorator('mapImg')(
88 135
               <ImageUpload />,
89 136
             )}
90 137
           </Form.Item>
91 138
           <Form.Item label="海报底图" hasFeedback>
92
-            {getFieldDecorator('tags')(
139
+            {getFieldDecorator('poster')(
93 140
               <ImageUpload />,
94 141
             )}
95 142
           </Form.Item>
@@ -123,11 +170,11 @@ function AddBuilding(props) {
123 170
           <Form.Item label="项目坐标" hasFeedback>
124 171
             {getFieldDecorator('coordinate')(<Input disabled />)}
125 172
           </Form.Item>
126
-          <Form.Item label="项目地址" hasFeedback>
127
-            {getFieldDecorator('coordinate')(<Input />)}
173
+          <Form.Item label="地图位置" hasFeedback>
174
+            {(<Input />)}
128 175
           </Form.Item>
129 176
           <Form.Item label="周边交通" hasFeedback>
130
-            {getFieldDecorator('buildingArea')(
177
+            {getFieldDecorator('buildingTransport')(
131 178
               <TagGroup />,
132 179
             )}
133 180
           </Form.Item>
@@ -184,7 +231,7 @@ function AddBuilding(props) {
184 231
             {getFieldDecorator('rightsYear')(<InputNumber />)}
185 232
           </Form.Item>
186 233
           <Form.Item label="预售许可证" hasFeedback>
187
-            {getFieldDecorator('decoration')(
234
+            {getFieldDecorator('preSalePermit')(
188 235
               <ImageUpload />,
189 236
             )}
190 237
           </Form.Item>

+ 1
- 1
src/pages/building/list/add/components/imageSet.jsx Ver fichero

@@ -138,7 +138,7 @@ function imageSet(props) {
138 138
 
139 139
       {/* 编辑页 */}
140 140
       {/*  onSuccess是子组件传递事件信息  */}
141
-      <ModalImage visibleData={visibleData} key={visibleData.apartmentId} onSuccess={getList}/>
141
+      <ModalImage visibleData={visibleData} key={1} onSuccess={getList}/>
142 142
     </>
143 143
   )
144 144
 }

+ 1
- 1
src/pages/building/list/add/components/modalImage.jsx Ver fichero

@@ -89,7 +89,7 @@ class ModalImage extends React.Component {
89 89
     const { url, method } = apis.building.buildingApartmentGetById
90 90
     const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(apartmentId)
91 91
 
92
-    request({ url: tempUrl, method , params: { ...params } }).then(res => {
92
+    request({ url: tempUrl, method, params: { ...params } }).then(res => {
93 93
       // res.img = res.buildingImgList.map((item, _) => item.url)
94 94
       res.img = res.buildingImgList[0].url
95 95
       this.props.form.setFieldsValue(res)

+ 15
- 1
src/pages/building/list/add/components/tags.jsx Ver fichero

@@ -34,15 +34,29 @@ class EditableTagGroup extends React.Component {
34 34
       inputVisible: false,
35 35
       inputValue: '',
36 36
     });
37
+
38
+    if (typeof this.props.onChange === 'function') {
39
+      const tempTags = tags.join(',')
40
+      this.props.onChange(tempTags);
41
+    }
37 42
   };
38 43
 
39 44
   saveInputRef = input => (this.input = input);
40 45
 
41 46
   render() {
42 47
     const { tags, inputVisible, inputValue } = this.state;
48
+
49
+    const { value } = this.props
50
+    let data = []
51
+    if (value !== undefined && value !== null) {
52
+      data = value.split(',')
53
+    } else {
54
+      data = tags
55
+    }
56
+
43 57
     return (
44 58
       <div>
45
-        {tags.map((tag, index) => {
59
+        {data.map((tag, index) => {
46 60
           const isLongTag = tag.length > 20;
47 61
           const tagElem = (
48 62
             <Tag key={tag} closable onClose={() => this.handleClose(tag)}>

+ 10
- 21
src/pages/building/list/add/index.jsx Ver fichero

@@ -29,35 +29,24 @@ const formItemLayout = {
29 29
 };
30 30
 
31 31
 function AddBuilding(props) {
32
-  // eslint-disable-next-line react-hooks/rules-of-hooks
33
-  const [dataSource, setDataSource] = useState({ records: [] })
34
-
35
-  const [buildingAreaTags, setBuildingAreaTags] = useState({ tags: ['Unremovable', 'Tag 2', 'Tag 3'], inputVisible: false, inputValue: '' })
36
-
37
-
38
-  const { getFieldDecorator } = props.form;
39
-
40
-  function handleSubmit(e) {
41
-    e.preventDefault();
42
-    props.form.validateFieldsAndScroll((err, values) => {
43
-      if (!err) {
44
-        console.log('Received values of form: ', values);
45
-      }
46
-    });
47
-  }
48
-
49 32
   function tabsCallback(key) {
50 33
     console.log(key);
51 34
   }
52 35
 
36
+  console.log(props.location)
37
+
53 38
   return (
54 39
     <Tabs defaultActiveKey="1" onChange={tabsCallback}>
55 40
       <TabPane tab="基本信息" key="1">
56
-        <Base />
57
-      </TabPane>
58
-      <TabPane tab="图片" key="2">
59
-        <ImageSet building={{ buildingId: '159fd19bb973b6972c10fbebf07ddeb1' }} />
41
+        <Base building={{ buildingId: props.location.query && props.location.query.id }} />
60 42
       </TabPane>
43
+      {
44
+        props.location.query.id &&
45
+        <TabPane tab="图片" key="2">
46
+          {/* '159fd19bb973b6972c10fbebf07ddeb1' */}
47
+          <ImageSet building={{ buildingId: props.location.query && props.location.query.id }} />
48
+        </TabPane>
49
+      }
61 50
     </Tabs>
62 51
   )
63 52
 }

+ 87
- 8
src/pages/building/list/index.jsx Ver fichero

@@ -1,5 +1,5 @@
1 1
 import React, { useState, useEffect } from 'react';
2
-import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert } from 'antd';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, notification, Modal } from 'antd';
3 3
 import moment from 'moment';
4 4
 import request from '../../../utils/request';
5 5
 import apis from '../../../services/apis';
@@ -13,6 +13,14 @@ const { Meta } = Card;
13 13
 
14 14
 const tempDate = [{ code: 's101' }]
15 15
 
16
+function openNotificationWithIcon(type, message) {
17
+  notification[type]({
18
+    message,
19
+    description:
20
+      '',
21
+  });
22
+}
23
+
16 24
 /**
17 25
  *卡片
18 26
  *
@@ -21,6 +29,76 @@ const tempDate = [{ code: 's101' }]
21 29
 function CartBody(props) {
22 30
   const { data } = props
23 31
 
32
+
33
+  function toEdi(record) {
34
+    router.push({
35
+      pathname: '/building/list/add',
36
+      query: {
37
+        id: record.buildingId,
38
+      },
39
+    })
40
+  }
41
+
42
+  /**
43
+   *发布 取消 发布
44
+   *
45
+   * @param {*} record
46
+   */
47
+  function pulicAndUnPulic(record) {
48
+    const modal = Modal.confirm();
49
+    const buidingStatus = record.status === 1 ? 2 : 1
50
+    const title = record.status === 1 ? '确认取消发布此数据?' : '确认发布此数据?'
51
+
52
+    modal.update({
53
+      content: title,
54
+      okText: '确认',
55
+      cancelText: '关闭',
56
+      onOk: () => {
57
+        request({ ...apis.building.updateStatus, data: { id: record.buildingId, status: buidingStatus } }).then(() => {
58
+          openNotificationWithIcon('success', '操作成功')
59
+          props.onSuccess()
60
+        }).catch(err => {
61
+          openNotificationWithIcon('error', err.message)
62
+        })
63
+
64
+        modal.destroy();
65
+      },
66
+      onCancel: () => {
67
+        modal.destroy();
68
+      },
69
+    });
70
+  }
71
+
72
+  /**
73
+   *删除楼盘
74
+   *
75
+   * @param {*} record
76
+   */
77
+  function deleteBuilding(record) {
78
+    const { url, method } = apis.building.deleteBuilding
79
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(record.buildingId)
80
+
81
+    const modal = Modal.confirm();
82
+    modal.update({
83
+      content: '确定删除此楼盘?',
84
+      okText: '确认',
85
+      cancelText: '关闭',
86
+      onOk: () => {
87
+        request({ url: tempUrl, method }).then(() => {
88
+          openNotificationWithIcon('success', '操作成功')
89
+          props.onSuccess()
90
+        }).catch(err => {
91
+          openNotificationWithIcon('error', err.message)
92
+        })
93
+
94
+        modal.destroy();
95
+      },
96
+      onCancel: () => {
97
+        modal.destroy();
98
+      },
99
+    });
100
+  }
101
+
24 102
   return (
25 103
           <Card
26 104
             hoverable
@@ -31,7 +109,7 @@ function CartBody(props) {
31 109
             <p className={Styles.cardText}>
32 110
               <span className={Styles.title}>楼盘编号</span>
33 111
               <span >:{ data.code }</span>
34
-              <span className={Styles.ediText}>
112
+              <span className={Styles.ediText} onClick={() => toEdi(data)}>
35 113
                 编辑
36 114
                 <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '10px' }} />
37 115
               </span>
@@ -52,20 +130,21 @@ function CartBody(props) {
52 130
             </p>
53 131
             <p className={Styles.cardItem}>
54 132
               <span className={Styles.title}>发布状态</span>
55
-              <span >:{ data.status === '1' ? '已发布' : '未发布' }</span>
133
+              <span >:{ data.status === 1 ? '已发布' : '未发布' }</span>
56 134
             </p>
57 135
             <p className={Styles.cardItem}>
58 136
               <span className={Styles.title}>录入时间</span>
59 137
               <span >:{ data.createDate }</span>
60 138
             </p>
61 139
             <p style={{ margin: '15px 0', position: 'relative', fontSize: '18px' }}>
62
-              <span style={{ color: '#1990FF' }}>
63
-                取消发布
140
+              <span style={{ color: '#1990FF' }} onClick={() => pulicAndUnPulic(data)}>
141
+                {/* 已发布的时候,需要显示取消发布的字样 */}
142
+                { data.status === 1 ? '取消发布' : '发布' }
64 143
                 <Icon type="close-circle" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
65 144
               </span>
66 145
               <span style={{
67 146
                 color: '#FF4A4A', position: 'absolute', right: '0',
68
-              }} >
147
+              }} onClick={() => deleteBuilding(data)}>
69 148
                 删除
70 149
                 <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
71 150
               </span>
@@ -213,9 +292,9 @@ function body(props) {
213 292
       {/* 卡片内容,显示楼盘项目  */}
214 293
       <Row style={{ padding: ' 0 10px' }}>
215 294
         {
216
-          dataSource.records.map((item, index) => (
295
+          dataSource.records.map((item, _) => (
217 296
               <Col span={8}>
218
-                <CartBody data={item} key={item.buildingId}/>
297
+                <CartBody data={item} key={item.buildingId} onSuccess={getList}/>
219 298
               </Col>
220 299
             ))
221 300
         }

+ 16
- 0
src/services/apis.js Ver fichero

@@ -22,6 +22,22 @@ export default {
22 22
       method: 'GET',
23 23
       url: `${prefix}/buildinglist`,
24 24
     },
25
+    updateStatus: {
26
+      method: 'PUT',
27
+      url: `${prefix}/building/update/status`,
28
+    },
29
+    addBuilding: {
30
+      method: 'POST',
31
+      url: `${prefix}/building/add`,
32
+    },
33
+    buildingGetById: {
34
+      method: 'GET',
35
+      url: `${prefix}/buildingSelectId/id`,
36
+    },
37
+    deleteBuilding: {
38
+      method: 'DELETE',
39
+      url: `${prefix}/building/delete/id`,
40
+    },
25 41
     buildingApartment: {
26 42
       method: 'GET',
27 43
       url: `${prefix}/buildingApartment/buildingId/id`,