知与行后台管理端

base.jsx 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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 { router } from 'umi';
  5. import request from '../../../../../utils/request';
  6. import apis from '../../../../../services/apis';
  7. import Styles from '../style.less';
  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. import { POI_TYPES_KETY, getAroundData, getPOIType, POI_TYPES } from './amapAroundData'
  17. import { ifError } from 'assert';
  18. const { Option } = Select
  19. const { TabPane } = Tabs;
  20. const formItemLayout = {
  21. labelCol: {
  22. xs: { span: 24 },
  23. sm: { span: 2 },
  24. },
  25. wrapperCol: {
  26. xs: { span: 24 },
  27. sm: { span: 16 },
  28. },
  29. };
  30. function openNotificationWithIcon(type, message) {
  31. notification[type]({
  32. message,
  33. description:
  34. '',
  35. });
  36. }
  37. function AddBuilding(props) {
  38. const { getFieldDecorator } = props.form;
  39. const [poi, setPoi] = useState([])
  40. const [videoImage, setVideoImage] = useState(false)
  41. // console.log('props.building: ', props.building)
  42. const { buildingId } = props.building
  43. // eslint-disable-next-line react-hooks/rules-of-hooks
  44. useEffect(() => {
  45. if (buildingId && buildingId !== '') {
  46. getById(buildingId)
  47. }
  48. }, [buildingId])
  49. // 获取详情信息
  50. function getById(currentId) {
  51. request({ ...apis.building.buildingGetById, urlData: { id: currentId } }).then(res => {
  52. if (res.openingDate !== null) {
  53. res.openingDate = moment(res.openingDate)
  54. }
  55. if (res.receivedDate !== null) {
  56. res.receivedDate = moment(res.receivedDate)
  57. }
  58. if (res.buildingTag !== null) {
  59. res.tag = res.buildingTag.map((item, _) => item.tagName)
  60. }
  61. res.avatarImage = res.buildingImg.map(item => item.url)
  62. if (res.buildingListImg) {
  63. res.listImage = res.buildingListImg.map(item => item.url)
  64. }
  65. res.mapCoordinate = res.coordinate
  66. if (res.videoUrl) {
  67. res.videoUrl = [].concat(res.videoUrl)
  68. setVideoImage(true)
  69. }
  70. if (res.videoImage) {
  71. res.videoImage = res.videoImage[0].url
  72. }
  73. // setPoi(res.mapJson || [])
  74. props.form.setFieldsValue(res)
  75. props.onSuccess(res)
  76. })
  77. }
  78. function handleSubmit(e) {
  79. e.preventDefault();
  80. props.form.validateFieldsAndScroll((err, values) => {
  81. if (!err) {
  82. addBuilding(values)
  83. }
  84. });
  85. }
  86. function addBuilding(data) {
  87. // console.log('poi: ', poi)
  88. if (poi.length !== 0) {
  89. data.mapJson = poi
  90. }
  91. data.openingDate = moment(data.openingDate, 'yyyy-MM-dd HH:mm:ss')
  92. data.receivedDate = moment(data.receivedDate, 'yyyy-MM-dd HH:mm:ss')
  93. // 项目主图
  94. data.img = data.avatarImage && data.avatarImage.map((item, index) => ({ imgType: 'banner', url: item, orderNo: index + 1 }))
  95. // 列表图
  96. data.listImg = data.listImage && data.listImage.map((item, index) => ({ imgType: 'list', url: item, orderNo: index + 1 }))
  97. if (data.videoUrl) {
  98. // console.log(data.videoUrl[0])
  99. data.videoUrl = data.videoUrl[0]
  100. }
  101. if (data.tag) {
  102. data.tag = data.tag.map((item, _) => ({ tagName: item }))
  103. }
  104. if (data.videoImage) {
  105. data.videoImage = [{ imgType: 'videoImage', url: data.videoImage, orderNo: 1 }]
  106. }
  107. const api = data.buildingId === undefined ? apis.building.addBuilding : apis.building.updateBuilding
  108. request({ ...api, data: { ...data } }).then(res => {
  109. openNotificationWithIcon('success', '操作成功')
  110. // router.go(-1)
  111. getById(res.buildingId)
  112. }).catch(err => {
  113. // openNotificationWithIcon('error', err.message)
  114. })
  115. }
  116. // 视频文件上传前 回调
  117. function fileUploadBeforeUpload(file, fileList) {
  118. // console.log('视频文件上传前 回调: ', file, fileList)
  119. return new Promise((resolve, reject) => {
  120. if (file.type === 'video/mp4' || file.type === '.mp4') {
  121. setVideoImage(true)
  122. resolve(file)
  123. } else {
  124. openNotificationWithIcon('error', '项目视频,仅支持MP4格式')
  125. reject()
  126. }
  127. })
  128. }
  129. // 周边设施 回调
  130. function getMapScope(e) {
  131. const coordinateValue = props.form.getFieldValue('coordinate')
  132. if (!coordinateValue) {
  133. openNotificationWithIcon('error', '请先选择项目坐标位置')
  134. return
  135. }
  136. const coordinate = props.form.getFieldValue('coordinate').split(',')
  137. const poiData = [].concat(POI_TYPES)
  138. poiData.map(item => {
  139. getAroundData({ types: item.key, location: `${coordinate[1]},${coordinate[0]}`, radius: e }).then(res => {
  140. const { pois } = res
  141. setFormMapScopeValue(item.key, pois)
  142. }).catch(err => {
  143. console.log(err.message)
  144. openNotificationWithIcon('error', '周边数据获取失败')
  145. })
  146. })
  147. }
  148. function setFormMapScopeValue(key, pois) {
  149. const poiArray = pois.map(p => {
  150. return {
  151. address: p.address,
  152. adname: p.adname,
  153. cityname: p.cityname,
  154. distance: p.distance,
  155. id: p.id,
  156. location: p.location,
  157. name: p.name,
  158. pname: p.pname,
  159. shopinfo: p.shopinfo,
  160. type: p.type,
  161. typecode: p.typecode,
  162. }
  163. })
  164. // 设置表单值
  165. getFormMapScopeName(key, { data: poiArray })
  166. const poiData = [].concat(POI_TYPES)
  167. const newPoi = poiData.map(m => {
  168. if (m.key === key) {
  169. m.data = poiArray
  170. }
  171. return m
  172. })
  173. setPoi(newPoi)
  174. }
  175. function getFormMapScopeName(keyType, item) {
  176. switch (keyType) {
  177. case POI_TYPES_KETY.Transport:
  178. props.form.setFieldsValue({ buildingTransport: item.data.map(t => t.name).join(',') })
  179. return 'buildingTransport';
  180. case POI_TYPES_KETY.Bank:
  181. props.form.setFieldsValue({ buildingBank: item.data.map(t => t.name).join(',') })
  182. return 'buildingBank';
  183. case POI_TYPES_KETY.Edu:
  184. props.form.setFieldsValue({ buildingEdu: item.data.map(t => t.name).join(',') })
  185. return 'buildingEdu';
  186. case POI_TYPES_KETY.Hospital:
  187. props.form.setFieldsValue({ buildingHospital: item.data.map(t => t.name).join(',') })
  188. return 'buildingHospital';
  189. case POI_TYPES_KETY.Restaurant:
  190. props.form.setFieldsValue({ buildingRestaurant: item.data.map(t => t.name).join(',') })
  191. return 'buildingRestaurant';
  192. case POI_TYPES_KETY.Mall:
  193. props.form.setFieldsValue({ buildingMall: item.data.map(t => t.name).join(',') })
  194. return 'buildingMall';
  195. default:
  196. }
  197. }
  198. return (
  199. <Form {...formItemLayout} onSubmit={handleSubmit}>
  200. <Form.Item label="项目Id" style={{ display: 'none' }}>
  201. {getFieldDecorator('buildingId')(<Input disabled />)}
  202. </Form.Item>
  203. <Form.Item label="楼盘编号" >
  204. {getFieldDecorator('code', {
  205. rules: [{ required: true, message: '请输入楼盘编号' }],
  206. })(<Input />)}
  207. </Form.Item>
  208. <Form.Item label="楼盘名称" >
  209. {getFieldDecorator('buildingName', {
  210. rules: [{ required: true, message: '请输入楼盘名' }],
  211. })(<Input />)}
  212. </Form.Item>
  213. {/* <Form.Item label="别名" >
  214. {getFieldDecorator('name')(<Input />)}
  215. </Form.Item> */}
  216. <Form.Item label="项目类型">
  217. {getFieldDecorator('buildingProjectType', {
  218. rules: [{ required: true, message: '请选择项目类型' }],
  219. })(<BudildingProjectType />)}
  220. </Form.Item>
  221. <Form.Item label="均价" >
  222. {getFieldDecorator('price')(<Input type="number" style={{ width: '210px' }}/>)}元/m²
  223. </Form.Item>
  224. <Form.Item label="开盘时间" >
  225. {getFieldDecorator('openingDate')(<DatePicker format="YYYY/MM/DD" />)}
  226. </Form.Item>
  227. <Form.Item label="电话" >
  228. {getFieldDecorator('tel', {
  229. initialValue: '',
  230. rules: [
  231. {
  232. pattern: new RegExp('^[0-9]*$'),
  233. message: '请输入正确的电话号码',
  234. },
  235. ],
  236. })(<Input />)}
  237. </Form.Item>
  238. <Form.Item label="项目动态" >
  239. {getFieldDecorator('dynamic')(<Input />)}
  240. </Form.Item>
  241. <Form.Item label="物业类型" >
  242. {getFieldDecorator('propertyType')(
  243. // <Select mode="multiple" placeholder="物业类型" style={{ width: '1016px' }}>
  244. // <Option value="未知">未知</Option>
  245. // </Select>,
  246. <Input />,
  247. )}
  248. </Form.Item>
  249. <Form.Item label="销售状态" >
  250. {getFieldDecorator('marketStatus', {
  251. rules: [{ required: true, message: '请选择销售状态' }],
  252. })(
  253. <Select placeholder="销售状态" style={{ width: '1016px' }}>
  254. <Option value="待定">待定</Option>
  255. <Option value="在售">在售</Option>
  256. <Option value="售完">售完</Option>
  257. </Select>,
  258. )}
  259. </Form.Item>
  260. <Form.Item label="项目标签" >
  261. {getFieldDecorator('tag')(
  262. <Select mode="tags" placeholder="输入后选中" style={{ width: '1016px' }}>
  263. </Select>,
  264. )}
  265. </Form.Item>
  266. <Form.Item label="项目视频" help="视频仅支持mp4格式,建议尺寸:1920*1080,比例16:9">
  267. {getFieldDecorator('videoUrl')(
  268. // disabled={fileUploadDisabled}
  269. <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" size={1} />,
  270. )}
  271. </Form.Item>
  272. <Form.Item label="视频封面图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于视频封面" >
  273. {getFieldDecorator('videoImage', {
  274. rules: [{ required: videoImage, message: '请选择视频封面图' }],
  275. })(
  276. <ImageUpload />,
  277. )}
  278. </Form.Item>
  279. <Form.Item label="楼盘主图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于楼盘详情">
  280. {getFieldDecorator('avatarImage', {
  281. rules: [{ required: true, message: '请选择项目主图' }],
  282. })(
  283. <ImageListUpload />,
  284. )}
  285. </Form.Item>
  286. <Form.Item label="楼盘封面图" help="建议图片尺寸:750*420px,比例16:9,格式:jpg,用于楼盘列表">
  287. {getFieldDecorator('listImage', {
  288. rules: [{ required: true, message: '请选择列表图' }],
  289. })(
  290. <ImageListUpload />,
  291. )}
  292. </Form.Item>
  293. {/* <Form.Item label="地址图片" help="建议图片尺寸:750px*455px">
  294. {getFieldDecorator('mapImg')(
  295. <ImageUpload />,
  296. )}
  297. </Form.Item> */}
  298. {/* <Form.Item label="海报底图" help="建议图片尺寸:640px*1136px" >
  299. {getFieldDecorator('poster')(
  300. <ImageUpload />,
  301. )}
  302. </Form.Item> */}
  303. <Form.Item label="排序" >
  304. {getFieldDecorator('orderNo')(<Input />)}
  305. </Form.Item>
  306. <Form.Item label="优惠信息" >
  307. {getFieldDecorator('discount')(<Input />)}
  308. </Form.Item>
  309. <Form.Item label="首页推荐" >
  310. {getFieldDecorator('isMain', {
  311. initialValue: 1,
  312. })(
  313. <Radio.Group>
  314. <Radio value={1}>是</Radio>
  315. <Radio value={2}>否</Radio>
  316. </Radio.Group>,
  317. )}
  318. </Form.Item>
  319. <Form.Item label="所在城市" >
  320. {getFieldDecorator('cityId', {
  321. rules: [{ required: true, message: '请选择城市' }],
  322. })(
  323. <SelectCity />,
  324. )}
  325. </Form.Item>
  326. <Form.Item label="楼盘区域" >
  327. {getFieldDecorator('buildingArea', {
  328. rules: [{ required: true, message: '请输入楼盘区域' }],
  329. })(<Input />)}
  330. </Form.Item>
  331. <Form.Item label="项目地址" >
  332. {getFieldDecorator('address', {
  333. rules: [{ required: true, message: '请输入项目地址' }],
  334. })(<Input />)}
  335. </Form.Item>
  336. <Form.Item label="项目坐标" >
  337. {getFieldDecorator('coordinate', {
  338. rules: [{ required: true, message: '请输入项目坐标' }],
  339. })(<Input disabled />)}
  340. </Form.Item>
  341. <Form.Item label="地图位置" >
  342. {getFieldDecorator('mapCoordinate')(<Amap onChange={e => props.form.setFieldsValue({ coordinate: e })}/>)}
  343. </Form.Item>
  344. <Form.Item label="周边设施搜索范围" style={{ width: '2000px' }}>
  345. {getFieldDecorator('mapScope', {
  346. rules: [{ required: true, message: '请选择周边设施搜索范围' }],
  347. })(
  348. <Select placeholder="请选择周边设施搜索范围" style={{ width: '970px' }} onChange={e => getMapScope(e)}>
  349. <Option value={1000}>1公里</Option>
  350. <Option value={3000}>3公里</Option>
  351. <Option value={5000}>5公里</Option>
  352. <Option value={10000}>10公里</Option>
  353. </Select>,
  354. )}
  355. </Form.Item>
  356. <Form.Item label="周边交通" >
  357. {getFieldDecorator('buildingTransport')(
  358. <TagGroup />,
  359. )}
  360. </Form.Item>
  361. <Form.Item label="周边商业" >
  362. {getFieldDecorator('buildingMall')(
  363. <TagGroup />,
  364. )}
  365. </Form.Item>
  366. <Form.Item label="周边学校" >
  367. {getFieldDecorator('buildingEdu')(
  368. <TagGroup />,
  369. )}
  370. </Form.Item>
  371. <Form.Item label="周边医院" >
  372. {getFieldDecorator('buildingHospital')(
  373. <TagGroup />,
  374. )}
  375. </Form.Item>
  376. <Form.Item label="周边银行" >
  377. {getFieldDecorator('buildingBank')(
  378. <TagGroup />,
  379. )}
  380. </Form.Item>
  381. <Form.Item label="周边餐饮" >
  382. {getFieldDecorator('buildingRestaurant')(
  383. <TagGroup />,
  384. )}
  385. </Form.Item>
  386. <Form.Item label="绿化率" >
  387. {getFieldDecorator('greeningRate')(<Input />)}
  388. </Form.Item>
  389. <Form.Item label="容积率" >
  390. {getFieldDecorator('volumeRate')(<Input />)}
  391. </Form.Item>
  392. <Form.Item label="车位比" >
  393. {getFieldDecorator('parkingRate')(<Input />)}
  394. </Form.Item>
  395. <Form.Item label="规划户数" >
  396. {getFieldDecorator('familyNum')(<InputNumber />)}
  397. </Form.Item>
  398. <Form.Item label="物业公司" >
  399. {getFieldDecorator('serviceCompany')(<Input />)}
  400. </Form.Item>
  401. <Form.Item label="物业费" >
  402. {getFieldDecorator('serviceFee')(<Input />)}
  403. </Form.Item>
  404. <Form.Item label="装修标准" >
  405. {getFieldDecorator('decoration')(<Input />)}
  406. </Form.Item>
  407. <Form.Item label="交房时间" >
  408. {getFieldDecorator('receivedDate')(<DatePicker />)}
  409. </Form.Item>
  410. <Form.Item label="产权年限" >
  411. {getFieldDecorator('rightsYear')(<InputNumber />)}
  412. </Form.Item>
  413. <Form.Item label="预售许可证" >
  414. {getFieldDecorator('preSalePermit')(
  415. <ImageUpload />,
  416. )}
  417. </Form.Item>
  418. <Form.Item label="项目备注" >
  419. {getFieldDecorator('remark')(
  420. <Wangedit />,
  421. )}
  422. </Form.Item>
  423. <Form.Item style={{ width: '400px', margin: 'auto', display: 'flex', justifyContent: 'space-between' }}>
  424. <Button type="primary" htmlType="submit">
  425. 确定
  426. </Button>
  427. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  428. <Button onClick={() => router.go(-1)}>
  429. 取消
  430. </Button>
  431. </Form.Item>
  432. </Form>
  433. )
  434. }
  435. const WrappedAddBuildingForm = Form.create({ name: 'addBuilding' })(AddBuilding);
  436. export default WrappedAddBuildingForm