Kaynağa Gözat

项目图片设置

魏熙美 5 yıl önce
ebeveyn
işleme
659104b8c6

+ 39
- 5
src/pages/building/list/add/components/imageSet.jsx Dosyayı Görüntüle

@@ -5,6 +5,7 @@ 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
+import ModalImage from './modalImage';
8 9
 
9 10
 
10 11
 const saleType = [
@@ -32,6 +33,9 @@ function imageSet(props) {
32 33
   // eslint-disable-next-line react-hooks/rules-of-hooks
33 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 39
   // eslint-disable-next-line react-hooks/rules-of-hooks
36 40
   useEffect(() => {
37 41
     getList()
@@ -46,7 +50,6 @@ function imageSet(props) {
46 50
   }
47 51
 
48 52
   function getList(params) {
49
-    console.log(props)
50 53
     // 网路请求
51 54
     const { url, method } = apis.building.buildingApartment
52 55
     const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(props.building.buildingId)
@@ -54,7 +57,34 @@ function imageSet(props) {
54 57
     request({ url: tempUrl, method, params: { ...params } }).then(res => {
55 58
       setData(res)
56 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,8 +124,8 @@ function imageSet(props) {
94 124
       key: 'apartmentId',
95 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,8 +133,12 @@ function imageSet(props) {
103 133
 
104 134
   return (
105 135
     <>
106
-      <Button type="primary">新增图片库</Button>
136
+      <Button type="primary" onClick={() => showEdi()}>新增图片库</Button>
107 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 Dosyayı Görüntüle

@@ -0,0 +1,223 @@
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 Dosyayı Görüntüle

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

+ 2
- 2
src/pages/building/list/index.jsx Dosyayı Görüntüle

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

+ 0
- 1
src/pages/building/list/style.css Dosyayı Görüntüle

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

+ 0
- 1
src/pages/building/list/style.less Dosyayı Görüntüle

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

+ 0
- 1
src/pages/building/list/style.wxss Dosyayı Görüntüle

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

+ 16
- 0
src/services/apis.js Dosyayı Görüntüle

@@ -26,6 +26,22 @@ export default {
26 26
       method: 'GET',
27 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 46
   buildingType: {
31 47
     getList: {