知与行后台管理端

base.jsx 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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, 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 { router } from 'umi';
  8. import ImageUpload from '../../../../../components/XForm/ImageUpload'
  9. import ImageListUpload from '../../../../../components/XForm/ImageListUpload'
  10. import Wangedit from '../../../../../components/Wangedit/Wangedit'
  11. import TagGroup from './tags'
  12. import Amap from './amap'
  13. import BudildingProjectType from './buildingProjectType'
  14. import SelectCity from '../../../../../components/SelectButton/CitySelect'
  15. const { Option } = Select
  16. const { TabPane } = Tabs;
  17. const formItemLayout = {
  18. labelCol: {
  19. xs: { span: 24 },
  20. sm: { span: 2 },
  21. },
  22. wrapperCol: {
  23. xs: { span: 24 },
  24. sm: { span: 16 },
  25. },
  26. };
  27. function openNotificationWithIcon(type, message) {
  28. notification[type]({
  29. message,
  30. description:
  31. '',
  32. });
  33. }
  34. function AddBuilding(props) {
  35. const { getFieldDecorator } = props.form;
  36. if (props.building.buildingId !== undefined) {
  37. const { buildingId } = props.building
  38. if (buildingId !== '') {
  39. // eslint-disable-next-line react-hooks/rules-of-hooks
  40. useEffect(() => {
  41. getById(buildingId)
  42. }, [])
  43. }
  44. }
  45. // 获取详情信息
  46. function getById(currentId) {
  47. request({ ...apis.building.buildingGetById, urlData: { id: currentId } }).then(res => {
  48. if (res.openingDate !== null) {
  49. res.openingDate = moment(res.openingDate)
  50. }
  51. if (res.receivedDate !== null) {
  52. res.receivedDate = moment(res.receivedDate)
  53. }
  54. if (res.buildingTag !== null) {
  55. res.tag = res.buildingTag.map((item, _) => item.tagName)
  56. }
  57. res.avatarImage = res.buildingImg.map(item => item.url)
  58. props.form.setFieldsValue(res)
  59. })
  60. }
  61. function handleSubmit(e) {
  62. e.preventDefault();
  63. props.form.validateFieldsAndScroll((err, values) => {
  64. if (!err) {
  65. addBuilding(values)
  66. }
  67. });
  68. }
  69. function addBuilding(data) {
  70. data.openingDate = moment(data.openingDate, 'yyyy-MM-dd HH:mm:ss')
  71. data.receivedDate = moment(data.receivedDate, 'yyyy-MM-dd HH:mm:ss')
  72. // 项目主图
  73. data.img = data.avatarImage && data.avatarImage.map((item, index) => ({ imgType: 'banner', url: item, orderNo: index + 1 }))
  74. if (data.tag) {
  75. data.tag = data.tag.map((item, _) => ({ tagName: item }))
  76. }
  77. const api = data.buildingId === undefined ? apis.building.addBuilding : apis.building.updateBuilding
  78. request({ ...api, data: { ...data } }).then(() => {
  79. openNotificationWithIcon('success', '操作成功')
  80. router.go(-1)
  81. }).catch(err => {
  82. openNotificationWithIcon('error', err.message)
  83. })
  84. }
  85. return (
  86. <Form {...formItemLayout} onSubmit={handleSubmit}>
  87. <Form.Item label="项目Id" hasFeedback style={{ display: 'none' }}>
  88. {getFieldDecorator('buildingId')(<Input disabled />)}
  89. </Form.Item>
  90. <Form.Item label="楼盘编号" hasFeedback>
  91. {getFieldDecorator('code')(<Input />)}
  92. </Form.Item>
  93. <Form.Item label="楼盘名称" hasFeedback>
  94. {getFieldDecorator('buildingName')(<Input />)}
  95. </Form.Item>
  96. <Form.Item label="别名" hasFeedback>
  97. {getFieldDecorator('name')(<Input />)}
  98. </Form.Item>
  99. <Form.Item label="项目类型">
  100. {getFieldDecorator('buildingProjectType')(<BudildingProjectType />)}
  101. </Form.Item>
  102. <Form.Item label="均价" hasFeedback>
  103. {getFieldDecorator('price')(<Input type="number" style={{ width: '210px' }}/>)}m²/元
  104. </Form.Item>
  105. <Form.Item label="开盘时间" hasFeedback>
  106. {getFieldDecorator('openingDate')(<DatePicker format="YYYY/MM/DD" />)}
  107. </Form.Item>
  108. <Form.Item label="电话" hasFeedback>
  109. {getFieldDecorator('tel')(<Input />)}
  110. </Form.Item>
  111. <Form.Item label="项目动态" hasFeedback>
  112. {getFieldDecorator('dynamic')(<Input />)}
  113. </Form.Item>
  114. <Form.Item label="物业类型" hasFeedback>
  115. {getFieldDecorator('propertyType')(
  116. // <Select mode="multiple" placeholder="物业类型" style={{ width: '1016px' }}>
  117. // <Option value="未知">未知</Option>
  118. // </Select>,
  119. <Input />,
  120. )}
  121. </Form.Item>
  122. <Form.Item label="销售状态" hasFeedback>
  123. {getFieldDecorator('marketStatus')(
  124. <Select placeholder="销售状态" style={{ width: '1016px' }}>
  125. <Option value="待定">待定</Option>
  126. <Option value="在售">在售</Option>
  127. <Option value="售完">售完</Option>
  128. </Select>,
  129. )}
  130. </Form.Item>
  131. <Form.Item label="项目标签" hasFeedback>
  132. {getFieldDecorator('tag')(
  133. <Select mode="tags" placeholder="输入后选中" style={{ width: '1016px' }}>
  134. </Select>,
  135. )}
  136. </Form.Item>
  137. <Form.Item label="项目主图" hasFeedback>
  138. {getFieldDecorator('avatarImage')(
  139. <ImageListUpload />,
  140. )}
  141. </Form.Item>
  142. <Form.Item label="地址图片" hasFeedback>
  143. {getFieldDecorator('mapImg')(
  144. <ImageUpload />,
  145. )}
  146. </Form.Item>
  147. <Form.Item label="海报底图" hasFeedback>
  148. {getFieldDecorator('poster')(
  149. <ImageUpload />,
  150. )}
  151. </Form.Item>
  152. <Form.Item label="排序" hasFeedback>
  153. {getFieldDecorator('orderNo')(<Input />)}
  154. </Form.Item>
  155. <Form.Item label="优惠信息" hasFeedback>
  156. {getFieldDecorator('discount')(<Input />)}
  157. </Form.Item>
  158. <Form.Item label="首页推荐" hasFeedback>
  159. {getFieldDecorator('isMain')(
  160. <Radio.Group>
  161. <Radio value={1}>是</Radio>
  162. <Radio value={2}>否</Radio>
  163. </Radio.Group>,
  164. )}
  165. </Form.Item>
  166. <Form.Item label="所在城市" hasFeedback>
  167. {getFieldDecorator('cityId')(
  168. <SelectCity />,
  169. )}
  170. </Form.Item>
  171. <Form.Item label="楼盘区域" hasFeedback>
  172. {getFieldDecorator('buildingArea')(<Input />)}
  173. </Form.Item>
  174. <Form.Item label="项目地址" hasFeedback>
  175. {getFieldDecorator('address')(<Input />)}
  176. </Form.Item>
  177. <Form.Item label="项目坐标" hasFeedback>
  178. {getFieldDecorator('coordinate')(<Input disabled />)}
  179. </Form.Item>
  180. <Form.Item label="地图位置" hasFeedback>
  181. {getFieldDecorator('coordinate')(<Amap />)}
  182. </Form.Item>
  183. <Form.Item label="周边交通" hasFeedback>
  184. {getFieldDecorator('buildingTransport')(
  185. <TagGroup />,
  186. )}
  187. </Form.Item>
  188. <Form.Item label="周边商业" hasFeedback>
  189. {getFieldDecorator('buildingMall')(
  190. <TagGroup />,
  191. )}
  192. </Form.Item>
  193. <Form.Item label="周边学校" hasFeedback>
  194. {getFieldDecorator('buildingEdu')(
  195. <TagGroup />,
  196. )}
  197. </Form.Item>
  198. <Form.Item label="周边医院" hasFeedback>
  199. {getFieldDecorator('buildingHospital')(
  200. <TagGroup />,
  201. )}
  202. </Form.Item>
  203. <Form.Item label="周边银行" hasFeedback>
  204. {getFieldDecorator('buildingBank')(
  205. <TagGroup />,
  206. )}
  207. </Form.Item>
  208. <Form.Item label="周边餐饮" hasFeedback>
  209. {getFieldDecorator('buildingRestaurant')(
  210. <TagGroup />,
  211. )}
  212. </Form.Item>
  213. <Form.Item label="绿化率" hasFeedback>
  214. {getFieldDecorator('greeningRate')(<Input />)}
  215. </Form.Item>
  216. <Form.Item label="容积率" hasFeedback>
  217. {getFieldDecorator('volumeRate')(<Input />)}
  218. </Form.Item>
  219. <Form.Item label="车位比" hasFeedback>
  220. {getFieldDecorator('parkingRate')(<Input />)}
  221. </Form.Item>
  222. <Form.Item label="规划户数" hasFeedback>
  223. {getFieldDecorator('familyNum')(<InputNumber />)}
  224. </Form.Item>
  225. <Form.Item label="物业公司" hasFeedback>
  226. {getFieldDecorator('serviceCompany')(<Input />)}
  227. </Form.Item>
  228. <Form.Item label="物业费" hasFeedback>
  229. {getFieldDecorator('serviceFee')(<Input />)}
  230. </Form.Item>
  231. <Form.Item label="装修标准" hasFeedback>
  232. {getFieldDecorator('decoration')(<Input />)}
  233. </Form.Item>
  234. <Form.Item label="交房时间" hasFeedback>
  235. {getFieldDecorator('receivedDate')(<DatePicker />)}
  236. </Form.Item>
  237. <Form.Item label="产权年限" hasFeedback>
  238. {getFieldDecorator('rightsYear')(<InputNumber />)}
  239. </Form.Item>
  240. <Form.Item label="预售许可证" hasFeedback>
  241. {getFieldDecorator('preSalePermit')(
  242. <ImageUpload />,
  243. )}
  244. </Form.Item>
  245. <Form.Item label="项目备注" hasFeedback>
  246. {getFieldDecorator('remark')(
  247. <Wangedit />,
  248. )}
  249. </Form.Item>
  250. <Form.Item style={{ width: '400px', margin: 'auto', display: 'flex', justifyContent: 'space-between' }}>
  251. <Button type="primary" htmlType="submit">
  252. 确定
  253. </Button>
  254. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  255. <Button onClick={() => router.go(-1)}>
  256. 取消
  257. </Button>
  258. </Form.Item>
  259. </Form>
  260. )
  261. }
  262. const WrappedAddBuildingForm = Form.create({ name: 'addBuilding' })(AddBuilding);
  263. export default WrappedAddBuildingForm