知与行后台管理端

base.jsx 9.8KB

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