知与行后台管理端

base.jsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. import FileUpload from '@/components/XForm/FileUpload';
  16. const { Option } = Select
  17. const { TabPane } = Tabs;
  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. function openNotificationWithIcon(type, message) {
  29. notification[type]({
  30. message,
  31. description:
  32. '',
  33. });
  34. }
  35. function AddBuilding(props) {
  36. const { getFieldDecorator } = props.form;
  37. console.log('props.building: ', props.building)
  38. if (props.building.buildingId !== undefined) {
  39. const { buildingId } = props.building
  40. // eslint-disable-next-line react-hooks/rules-of-hooks
  41. useEffect(() => {
  42. if (buildingId !== '') {
  43. getById(buildingId)
  44. }
  45. }, [])
  46. }
  47. // 获取详情信息
  48. function getById(currentId) {
  49. request({ ...apis.building.buildingGetById, urlData: { id: currentId } }).then(res => {
  50. if (res.openingDate !== null) {
  51. res.openingDate = moment(res.openingDate)
  52. }
  53. if (res.receivedDate !== null) {
  54. res.receivedDate = moment(res.receivedDate)
  55. }
  56. if (res.buildingTag !== null) {
  57. res.tag = res.buildingTag.map((item, _) => item.tagName)
  58. }
  59. res.avatarImage = res.buildingImg.map(item => item.url)
  60. res.listImage = res.buildingListImg.map(item => item.url)
  61. res.mapCoordinate = res.coordinate
  62. if (res.videoUrl) {
  63. res.videoUrl = [].concat(res.videoUrl)
  64. }
  65. props.form.setFieldsValue(res)
  66. props.onSuccess(res)
  67. })
  68. }
  69. function handleSubmit(e) {
  70. e.preventDefault();
  71. props.form.validateFieldsAndScroll((err, values) => {
  72. if (!err) {
  73. addBuilding(values)
  74. }
  75. });
  76. }
  77. function addBuilding(data) {
  78. data.openingDate = moment(data.openingDate, 'yyyy-MM-dd HH:mm:ss')
  79. data.receivedDate = moment(data.receivedDate, 'yyyy-MM-dd HH:mm:ss')
  80. // 项目主图
  81. data.img = data.avatarImage && data.avatarImage.map((item, index) => ({ imgType: 'banner', url: item, orderNo: index + 1 }))
  82. // 列表图
  83. data.listImg = data.listImage && data.listImage.map((item, index) => ({ imgType: 'list', url: item, orderNo: index + 1 }))
  84. data.videoUrl = data.videoUrl[0]
  85. if (data.tag) {
  86. data.tag = data.tag.map((item, _) => ({ tagName: item }))
  87. }
  88. const api = data.buildingId === undefined ? apis.building.addBuilding : apis.building.updateBuilding
  89. request({ ...api, data: { ...data } }).then(res => {
  90. openNotificationWithIcon('success', '操作成功')
  91. // router.go(-1)
  92. getById(res.buildingId)
  93. }).catch(err => {
  94. openNotificationWithIcon('error', err.message)
  95. })
  96. }
  97. // 视频文件上传前 回调
  98. function fileUploadBeforeUpload(file, fileList) {
  99. console.log(file, fileList)
  100. return new Promise((resolve, reject) => {
  101. if (file.type === 'video/mp4' || file.type === '.mp4') {
  102. resolve(file)
  103. } else {
  104. openNotificationWithIcon('error', '项目视频,仅支持MP4格式')
  105. reject()
  106. }
  107. })
  108. }
  109. return (
  110. <Form {...formItemLayout} onSubmit={handleSubmit}>
  111. <Form.Item label="项目Id" style={{ display: 'none' }}>
  112. {getFieldDecorator('buildingId')(<Input disabled />)}
  113. </Form.Item>
  114. <Form.Item label="楼盘编号" >
  115. {getFieldDecorator('code', {
  116. rules: [{ required: true, message: '请输入楼盘编号' }],
  117. })(<Input />)}
  118. </Form.Item>
  119. <Form.Item label="楼盘名称" >
  120. {getFieldDecorator('buildingName', {
  121. rules: [{ required: true, message: '请输入楼盘名' }],
  122. })(<Input />)}
  123. </Form.Item>
  124. {/* <Form.Item label="别名" >
  125. {getFieldDecorator('name')(<Input />)}
  126. </Form.Item> */}
  127. <Form.Item label="项目类型">
  128. {getFieldDecorator('buildingProjectType', {
  129. rules: [{ required: true, message: '请选择项目类型' }],
  130. })(<BudildingProjectType />)}
  131. </Form.Item>
  132. <Form.Item label="均价" >
  133. {getFieldDecorator('price')(<Input type="number" style={{ width: '210px' }}/>)}元/m²
  134. </Form.Item>
  135. <Form.Item label="开盘时间" >
  136. {getFieldDecorator('openingDate')(<DatePicker format="YYYY/MM/DD" />)}
  137. </Form.Item>
  138. <Form.Item label="电话" >
  139. {getFieldDecorator('tel', {
  140. initialValue: '',
  141. rules: [
  142. {
  143. pattern: new RegExp('^[0-9]*$'),
  144. message: '请输入正确的电话号码',
  145. },
  146. ],
  147. })(<Input />)}
  148. </Form.Item>
  149. <Form.Item label="项目动态" >
  150. {getFieldDecorator('dynamic')(<Input />)}
  151. </Form.Item>
  152. <Form.Item label="物业类型" >
  153. {getFieldDecorator('propertyType')(
  154. // <Select mode="multiple" placeholder="物业类型" style={{ width: '1016px' }}>
  155. // <Option value="未知">未知</Option>
  156. // </Select>,
  157. <Input />,
  158. )}
  159. </Form.Item>
  160. <Form.Item label="销售状态" >
  161. {getFieldDecorator('marketStatus', {
  162. rules: [{ required: true, message: '请选择销售状态' }],
  163. })(
  164. <Select placeholder="销售状态" style={{ width: '1016px' }}>
  165. <Option value="待定">待定</Option>
  166. <Option value="在售">在售</Option>
  167. <Option value="售完">售完</Option>
  168. </Select>,
  169. )}
  170. </Form.Item>
  171. <Form.Item label="项目标签" >
  172. {getFieldDecorator('tag')(
  173. <Select mode="tags" placeholder="输入后选中" style={{ width: '1016px' }}>
  174. </Select>,
  175. )}
  176. </Form.Item>
  177. <Form.Item label="项目视频" help="视频仅支持mp4格式,建议尺寸:1920*1080,比例16:9">
  178. {getFieldDecorator('videoUrl')(
  179. <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频"/>,
  180. )}
  181. </Form.Item>
  182. <Form.Item label="项目主图" help="建议图片尺寸:640px*360px">
  183. {getFieldDecorator('avatarImage', {
  184. rules: [{ required: true, message: '请选择项目主图' }],
  185. })(
  186. <ImageListUpload />,
  187. )}
  188. </Form.Item>
  189. <Form.Item label="列表图" help="建议图片尺寸:640px*360px">
  190. {getFieldDecorator('listImage', {
  191. rules: [{ required: true, message: '请选择列表图' }],
  192. })(
  193. <ImageListUpload />,
  194. )}
  195. </Form.Item>
  196. {/* <Form.Item label="地址图片" help="建议图片尺寸:750px*455px">
  197. {getFieldDecorator('mapImg')(
  198. <ImageUpload />,
  199. )}
  200. </Form.Item> */}
  201. {/* <Form.Item label="海报底图" help="建议图片尺寸:640px*1136px" >
  202. {getFieldDecorator('poster')(
  203. <ImageUpload />,
  204. )}
  205. </Form.Item> */}
  206. <Form.Item label="排序" >
  207. {getFieldDecorator('orderNo')(<Input />)}
  208. </Form.Item>
  209. <Form.Item label="优惠信息" >
  210. {getFieldDecorator('discount')(<Input />)}
  211. </Form.Item>
  212. <Form.Item label="首页推荐" >
  213. {getFieldDecorator('isMain',{
  214. initialValue: 1,
  215. })(
  216. <Radio.Group>
  217. <Radio value={1}>是</Radio>
  218. <Radio value={2}>否</Radio>
  219. </Radio.Group>,
  220. )}
  221. </Form.Item>
  222. <Form.Item label="所在城市" >
  223. {getFieldDecorator('cityId', {
  224. rules: [{ required: true, message: '请选择城市' }],
  225. })(
  226. <SelectCity />,
  227. )}
  228. </Form.Item>
  229. <Form.Item label="楼盘区域" >
  230. {getFieldDecorator('buildingArea', {
  231. rules: [{ required: true, message: '请输入楼盘区域' }],
  232. })(<Input />)}
  233. </Form.Item>
  234. <Form.Item label="项目地址" >
  235. {getFieldDecorator('address', {
  236. rules: [{ required: true, message: '请输入项目地址' }],
  237. })(<Input />)}
  238. </Form.Item>
  239. <Form.Item label="项目坐标" >
  240. {getFieldDecorator('coordinate', {
  241. rules: [{ required: true, message: '请输入项目坐标' }],
  242. })(<Input disabled />)}
  243. </Form.Item>
  244. <Form.Item label="地图位置" >
  245. {getFieldDecorator('mapCoordinate')(<Amap onChange={e => props.form.setFieldsValue({ coordinate: e })}/>)}
  246. </Form.Item>
  247. <Form.Item label="周边设施搜索范围" style={{ width: '2000px' }}>
  248. {getFieldDecorator('mapScope', {
  249. rules: [{ required: true, message: '请选择周边设施搜索范围' }],
  250. })(
  251. <Select placeholder="请选择周边设施搜索范围" style={{ width: '970px' }}>
  252. <Option value={1000}>1公里</Option>
  253. <Option value={3000}>3公里</Option>
  254. <Option value={5000}>5公里</Option>
  255. <Option value={10000}>10公里</Option>
  256. </Select>,
  257. )}
  258. </Form.Item>
  259. <Form.Item label="周边交通" >
  260. {getFieldDecorator('buildingTransport')(
  261. <TagGroup />,
  262. )}
  263. </Form.Item>
  264. <Form.Item label="周边商业" >
  265. {getFieldDecorator('buildingMall')(
  266. <TagGroup />,
  267. )}
  268. </Form.Item>
  269. <Form.Item label="周边学校" >
  270. {getFieldDecorator('buildingEdu')(
  271. <TagGroup />,
  272. )}
  273. </Form.Item>
  274. <Form.Item label="周边医院" >
  275. {getFieldDecorator('buildingHospital')(
  276. <TagGroup />,
  277. )}
  278. </Form.Item>
  279. <Form.Item label="周边银行" >
  280. {getFieldDecorator('buildingBank')(
  281. <TagGroup />,
  282. )}
  283. </Form.Item>
  284. <Form.Item label="周边餐饮" >
  285. {getFieldDecorator('buildingRestaurant')(
  286. <TagGroup />,
  287. )}
  288. </Form.Item>
  289. <Form.Item label="绿化率" >
  290. {getFieldDecorator('greeningRate')(<Input />)}
  291. </Form.Item>
  292. <Form.Item label="容积率" >
  293. {getFieldDecorator('volumeRate')(<Input />)}
  294. </Form.Item>
  295. <Form.Item label="车位比" >
  296. {getFieldDecorator('parkingRate')(<Input />)}
  297. </Form.Item>
  298. <Form.Item label="规划户数" >
  299. {getFieldDecorator('familyNum')(<InputNumber />)}
  300. </Form.Item>
  301. <Form.Item label="物业公司" >
  302. {getFieldDecorator('serviceCompany')(<Input />)}
  303. </Form.Item>
  304. <Form.Item label="物业费" >
  305. {getFieldDecorator('serviceFee')(<Input />)}
  306. </Form.Item>
  307. <Form.Item label="装修标准" >
  308. {getFieldDecorator('decoration')(<Input />)}
  309. </Form.Item>
  310. <Form.Item label="交房时间" >
  311. {getFieldDecorator('receivedDate')(<DatePicker />)}
  312. </Form.Item>
  313. <Form.Item label="产权年限" >
  314. {getFieldDecorator('rightsYear')(<InputNumber />)}
  315. </Form.Item>
  316. <Form.Item label="预售许可证" >
  317. {getFieldDecorator('preSalePermit')(
  318. <ImageUpload />,
  319. )}
  320. </Form.Item>
  321. <Form.Item label="项目备注" >
  322. {getFieldDecorator('remark')(
  323. <Wangedit />,
  324. )}
  325. </Form.Item>
  326. <Form.Item style={{ width: '400px', margin: 'auto', display: 'flex', justifyContent: 'space-between' }}>
  327. <Button type="primary" htmlType="submit">
  328. 确定
  329. </Button>
  330. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  331. <Button onClick={() => router.go(-1)}>
  332. 取消
  333. </Button>
  334. </Form.Item>
  335. </Form>
  336. )
  337. }
  338. const WrappedAddBuildingForm = Form.create({ name: 'addBuilding' })(AddBuilding);
  339. export default WrappedAddBuildingForm