Browse Source

项目图片设置

魏熙美 5 years ago
parent
commit
659104b8c6

+ 39
- 5
src/pages/building/list/add/components/imageSet.jsx View File

5
 import apis from '../../../../../services/apis';
5
 import apis from '../../../../../services/apis';
6
 import Styles from '../style.less';
6
 import Styles from '../style.less';
7
 import { router } from 'umi';
7
 import { router } from 'umi';
8
+import ModalImage from './modalImage';
8
 
9
 
9
 
10
 
10
 const saleType = [
11
 const saleType = [
32
   // eslint-disable-next-line react-hooks/rules-of-hooks
33
   // eslint-disable-next-line react-hooks/rules-of-hooks
33
   const [data, setData] = useState([])
34
   const [data, setData] = useState([])
34
 
35
 
36
+  // eslint-disable-next-line react-hooks/rules-of-hooks
37
+  const [visibleData, setVisibleData] = useState({ visible: false, apartmentId: '', buildingId: '' })
38
+
35
   // eslint-disable-next-line react-hooks/rules-of-hooks
39
   // eslint-disable-next-line react-hooks/rules-of-hooks
36
   useEffect(() => {
40
   useEffect(() => {
37
     getList()
41
     getList()
46
   }
50
   }
47
 
51
 
48
   function getList(params) {
52
   function getList(params) {
49
-    console.log(props)
50
     // 网路请求
53
     // 网路请求
51
     const { url, method } = apis.building.buildingApartment
54
     const { url, method } = apis.building.buildingApartment
52
     const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(props.building.buildingId)
55
     const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(props.building.buildingId)
54
     request({ url: tempUrl, method, params: { ...params } }).then(res => {
57
     request({ url: tempUrl, method, params: { ...params } }).then(res => {
55
       setData(res)
58
       setData(res)
56
     }).catch(err => {
59
     }).catch(err => {
57
-      openNotificationWithIcon('error', err)
60
+      openNotificationWithIcon('error', err.message)
61
+    })
62
+  }
63
+
64
+  /**
65
+   *打开编辑页
66
+   *
67
+   * @param {*} record
68
+   */
69
+  function showEdi(record) {
70
+    setVisibleData({ visible: true, apartmentId: record === undefined ? '' : record.apartmentId, buildingId: props.building.buildingId })
71
+  }
72
+
73
+  /**
74
+   * 删除
75
+   *
76
+   * @param {*} record
77
+   */
78
+  function deleteApartment(record) {
79
+    // 网路请求
80
+    const { url, method } = apis.building.buildingApartmentDelete
81
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(record.apartmentId)
82
+
83
+    request({ url: tempUrl, method }).then(res => {
84
+      getList()
85
+      openNotificationWithIcon('error', '操作成功')
86
+    }).catch(err => {
87
+      openNotificationWithIcon('error', err.message)
58
     })
88
     })
59
   }
89
   }
60
 
90
 
94
       key: 'apartmentId',
124
       key: 'apartmentId',
95
       render: (_, record) => (
125
       render: (_, record) => (
96
         <>
126
         <>
97
-          <Button type="link" style={{ color: 'red' }}>编辑</Button>
98
-          <Button type="link" style={{ color: 'red' }}>删除</Button>
127
+          <Button type="link" style={{ color: 'red' }} onClick={() => showEdi(record)}>编辑</Button>
128
+          <Button type="link" style={{ color: 'red' }} onClick={() => deleteApartment(record)}>删除</Button>
99
         </>
129
         </>
100
       ),
130
       ),
101
     },
131
     },
103
 
133
 
104
   return (
134
   return (
105
     <>
135
     <>
106
-      <Button type="primary">新增图片库</Button>
136
+      <Button type="primary" onClick={() => showEdi()}>新增图片库</Button>
107
       <Table dataSource={data} columns={columns} pagination={false} />
137
       <Table dataSource={data} columns={columns} pagination={false} />
138
+
139
+      {/* 编辑页 */}
140
+      {/*  onSuccess是子组件传递事件信息  */}
141
+      <ModalImage visibleData={visibleData} key={visibleData.apartmentId} onSuccess={getList}/>
108
     </>
142
     </>
109
   )
143
   )
110
 }
144
 }

+ 223
- 0
src/pages/building/list/add/components/modalImage.jsx View File

1
+import React, { useState, useEffect } from 'react';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions, notification } from 'antd';
3
+import moment from 'moment';
4
+import request from '../../../../../utils/request';
5
+import apis from '../../../../../services/apis';
6
+import Styles from '../style.less';
7
+import ImageUpload from '../../../../../components/XForm/ImageUpload'
8
+import Wangedit from '../../../../../components/Wangedit/Wangedit'
9
+
10
+
11
+const { Option } = Select;
12
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+const { Meta } = Card;
14
+
15
+const { TextArea } = Input;
16
+
17
+
18
+const formItemLayout = {
19
+  labelCol: {
20
+    xs: { span: 24 },
21
+    sm: { span: 2 },
22
+  },
23
+  wrapperCol: {
24
+    xs: { span: 24 },
25
+    sm: { span: 16 },
26
+  },
27
+};
28
+
29
+const saleType = [
30
+  {
31
+    id: 1,
32
+    name: '待定',
33
+  },
34
+  {
35
+    id: 2,
36
+    name: '售罄',
37
+  },
38
+  {
39
+    id: 3,
40
+    name: '在售',
41
+  },
42
+]
43
+
44
+/**
45
+ * 图片信息
46
+ *
47
+ * @param {*} props
48
+ * @returns
49
+ */
50
+class ModalImage extends React.Component {
51
+  constructor(props) {
52
+    super(props);
53
+    this.state = {
54
+       visibleData: { visible: false, apartmentId: '', buildingId: '' },
55
+    }
56
+  }
57
+
58
+  // 挂载之后
59
+  // componentDidMount() {
60
+  //
61
+  // }
62
+
63
+  componentDidUpdate(preProps, preState) {
64
+    console.log(this.props.visibleData)
65
+    if (this.props.visibleData.visible !== preState.visibleData.visible) {
66
+      this.getById()
67
+      this.setState({ visibleData: this.props.visibleData });
68
+    }
69
+  }
70
+
71
+  // 弹框确定按钮
72
+  // eslint-disable-next-line react/sort-comp
73
+  handleOk() {
74
+    this.setState({ visibleData: { visible: false, apartmentId: '', buildingId: '' } })
75
+  }
76
+
77
+  // 弹框取消按钮
78
+  handleCancel() {
79
+    this.setState({ visibleData: { visible: false, apartmentId: '', buildingId: '' } })
80
+  }
81
+
82
+  getById(params) {
83
+    const { apartmentId } = this.props.visibleData
84
+    if (apartmentId === '' || apartmentId === undefined) {
85
+      return
86
+    }
87
+
88
+    // 网路请求
89
+    const { url, method } = apis.building.buildingApartmentGetById
90
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(apartmentId)
91
+
92
+    request({ url: tempUrl, method , params: { ...params } }).then(res => {
93
+      // res.img = res.buildingImgList.map((item, _) => item.url)
94
+      res.img = res.buildingImgList[0].url
95
+      this.props.form.setFieldsValue(res)
96
+    }).catch(err => {
97
+     this.openNotificationWithIcon('error', err)
98
+    })
99
+  }
100
+
101
+  openNotificationWithIcon = (type, message) => {
102
+    notification[type]({
103
+      message,
104
+      description:
105
+        '',
106
+    });
107
+  };
108
+
109
+  // 提交
110
+  handleSubmit(e) {
111
+    e.preventDefault();
112
+    this.props.form.validateFields((err, values) => {
113
+      if (!err) {
114
+        this.submitData(values)
115
+      }
116
+    });
117
+  }
118
+
119
+  submitData(data) {
120
+    // TODO 这里应该是要支持多图,但是封装的控件没有
121
+    data.img = [{ imgType: 'aparment', url: data.img, orderNo: 1 }]
122
+    data.buildingId = this.props.visibleData.buildingId;
123
+    const api = data.apartmentId !== undefined ? apis.building.buildingApartmentUpdate : apis.building.buildingApartmentAdd;
124
+
125
+    // 网路请求
126
+    request({ ...api, data: { ...data } }).then(() => {
127
+      // eslint-disable-next-line no-unused-expressions
128
+      this.openNotificationWithIcon('success', '操作成功')
129
+
130
+      // 传递父组件事件
131
+      // onSuccess() 是自定义
132
+      this.props.onSuccess()
133
+
134
+      this.handleCancel()
135
+    }).catch(err => {
136
+      // eslint-disable-next-line no-unused-expressions
137
+      this.openNotificationWithIcon('error', err)
138
+    })
139
+  }
140
+
141
+  /**
142
+   * 取消按钮
143
+   *
144
+   * @memberof ModalImage
145
+   */
146
+  closeModal() {
147
+    this.setState({ visibleData: { visible: false, apartmentId: '', buildingId: '' } })
148
+  }
149
+
150
+  render() {
151
+    const { getFieldDecorator } = this.props.form;
152
+    return (
153
+      <>
154
+        <Modal
155
+            title="图片信息"
156
+            width={1100}
157
+            destroyOnClose="true"
158
+            footer={null}
159
+            visible={this.state.visibleData.visible}
160
+            onOk={() => this.handleOk()}
161
+            onCancel={e => this.handleCancel(e)}
162
+          >
163
+            <Form {...formItemLayout} onSubmit={e => this.handleSubmit(e)}>
164
+              <Form.Item label="编号" style={{ display: 'none' }}>
165
+                  {getFieldDecorator('apartmentId')(<Input />)}
166
+              </Form.Item>
167
+              <Form.Item label="名称">
168
+                {getFieldDecorator('apartmentName')(<Input />)}
169
+              </Form.Item>
170
+              <Form.Item label="类型">
171
+                {getFieldDecorator('apartmentType')(
172
+                  <Select placeholder="类型">
173
+                    <Option value="apart">户型</Option>
174
+                    <Option value="photo">相册</Option>
175
+                  </Select>,
176
+                )}
177
+              </Form.Item>
178
+              <Form.Item label="销售状态">
179
+                {getFieldDecorator('marketStatus')(
180
+                  <Select placeholder="销售状态">
181
+                    {
182
+                      saleType.map((item, _) => <Option value={item.id}>{item.name}</Option>)
183
+                    }
184
+                  </Select>,
185
+                )}
186
+              </Form.Item>
187
+              <Form.Item label="图片">
188
+              {getFieldDecorator('img')(
189
+                <ImageUpload />,
190
+              )}
191
+              </Form.Item>
192
+              <Form.Item label="面积">
193
+                {getFieldDecorator('buildingArea')(<Input />)}
194
+              </Form.Item>
195
+              <Form.Item label="套内面积">
196
+                {getFieldDecorator('insideArea')(<Input />)}
197
+              </Form.Item>
198
+              <Form.Item label="户型总价">
199
+                {getFieldDecorator('apartmentPrice')(<Input />)}
200
+              </Form.Item>
201
+              <Form.Item label="户型简介">
202
+                {getFieldDecorator('apartmentDescription')(
203
+                  <Wangedit />,
204
+                )}
205
+              </Form.Item>
206
+              <Form.Item label="备注">
207
+                {getFieldDecorator('remark')(<TextArea rows={10} />)}
208
+              </Form.Item>
209
+              <Form.Item style={{ width: '400px', margin: 'auto', display: 'flex', justifyContent: 'space-between' }}>
210
+                <Button type="primary" htmlType="submit">保存</Button>
211
+                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
212
+                <Button onClick={() => this.closeModal()}>取消</Button>
213
+              </Form.Item>
214
+            </Form>
215
+        </Modal>
216
+      </>
217
+    );
218
+  }
219
+}
220
+
221
+const WrappedModalImageForm = Form.create({ name: 'modalImage' })(ModalImage);
222
+
223
+export default WrappedModalImageForm

+ 1
- 1
src/pages/building/list/add/components/tags.jsx View File

45
         {tags.map((tag, index) => {
45
         {tags.map((tag, index) => {
46
           const isLongTag = tag.length > 20;
46
           const isLongTag = tag.length > 20;
47
           const tagElem = (
47
           const tagElem = (
48
-            <Tag key={tag} closable={index !== 0} onClose={() => this.handleClose(tag)}>
48
+            <Tag key={tag} closable onClose={() => this.handleClose(tag)}>
49
               {isLongTag ? `${tag.slice(0, 20)}...` : tag}
49
               {isLongTag ? `${tag.slice(0, 20)}...` : tag}
50
             </Tag>
50
             </Tag>
51
           );
51
           );

+ 2
- 2
src/pages/building/list/index.jsx View File

201
           )}
201
           )}
202
         </Form.Item>
202
         </Form.Item>
203
         <Form.Item>
203
         <Form.Item>
204
-          <Button type="primary" htmlType="submit" className={Styles.SubmitButton}>
204
+          <Button type="primary" htmlType="submit">
205
             搜索
205
             搜索
206
           </Button>
206
           </Button>
207
         </Form.Item>
207
         </Form.Item>
208
       </Form>
208
       </Form>
209
-      <Button type="primary" className={Styles.addButton} onClick={() => toAdd()}>
209
+      <Button type="danger" className={Styles.addButton} onClick={() => toAdd()}>
210
         新增楼盘
210
         新增楼盘
211
       </Button>
211
       </Button>
212
 
212
 

+ 0
- 1
src/pages/building/list/style.css View File

10
   border: 1px solid #dbdbdb;
10
   border: 1px solid #dbdbdb;
11
 }
11
 }
12
 .addButton {
12
 .addButton {
13
-  background: #50be00;
14
   border-radius: 4px;
13
   border-radius: 4px;
15
   border: 0px;
14
   border: 0px;
16
   margin: 10px 0px;
15
   margin: 10px 0px;

+ 0
- 1
src/pages/building/list/style.less View File

10
   border: 1px solid #dbdbdb;
10
   border: 1px solid #dbdbdb;
11
 }
11
 }
12
 .addButton {
12
 .addButton {
13
-  background: #50be00;
14
   border-radius: 4px;
13
   border-radius: 4px;
15
   border: 0px;
14
   border: 0px;
16
   margin: 10px 0px;
15
   margin: 10px 0px;

+ 0
- 1
src/pages/building/list/style.wxss View File

10
   border: 1px solid #dbdbdb;
10
   border: 1px solid #dbdbdb;
11
 }
11
 }
12
 .addButton {
12
 .addButton {
13
-  background: #50be00;
14
   border-radius: 4px;
13
   border-radius: 4px;
15
   border: 0px;
14
   border: 0px;
16
   margin: 10px 0px;
15
   margin: 10px 0px;

+ 16
- 0
src/services/apis.js View File

26
       method: 'GET',
26
       method: 'GET',
27
       url: `${prefix}/buildingApartment/buildingId/id`,
27
       url: `${prefix}/buildingApartment/buildingId/id`,
28
     },
28
     },
29
+    buildingApartmentGetById: {
30
+      method: 'GET',
31
+      url: `${prefix}/buildingApartment/id`,
32
+    },
33
+    buildingApartmentUpdate: {
34
+      method: 'PUT',
35
+      url: `${prefix}/buildingApartment/update`,
36
+    },
37
+    buildingApartmentAdd: {
38
+      method: 'POST',
39
+      url: `${prefix}/buildingApartment/add`,
40
+    },
41
+    buildingApartmentDelete: {
42
+      method: 'DELETE',
43
+      url: `${prefix}/apartment/deleted/id`,
44
+    },
29
   },
45
   },
30
   buildingType: {
46
   buildingType: {
31
     getList: {
47
     getList: {