share.jsx 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker, message, Upload } from 'antd';
  3. import { FormattedMessage } from 'umi-plugin-react/locale';
  4. import moment from 'moment';
  5. import router from 'umi/router';
  6. import BuildSelect from '../../../../../components/SelectButton/BuildSelect'
  7. import XForm, { FieldTypes } from '../../../../../components/XForm';
  8. import Wangedit from '../../../../../components/Wangedit/Wangedit'
  9. import request from '../../../../../utils/request'
  10. import yinhao from '../../../../../assets/yinhao.png'
  11. import ImageUploader from '../../../../../components/XForm/ImageUpload';
  12. import logo from '../../../../../assets/logo.png';
  13. import touxiang from '../../../../../assets/touxiang.jpg';
  14. import poster1 from '../../../../../assets/poster1.png';
  15. import poster2 from '../../../../../assets/poster2.png';
  16. import apis from '../../../../../services/apis';
  17. const Share = props => {
  18. const [inputValue, changeInput] = useState('')
  19. const [imgValue, changeImg] = useState('')
  20. const [shareContentId, setShareContentId] = useState('')
  21. const { buildingId } = props.building
  22. if (buildingId) {
  23. // eslint-disable-next-line react-hooks/rules-of-hooks
  24. useEffect(() => {
  25. request({
  26. ...apis.activity.shareContent,
  27. params: { targetId: buildingId, targetType: 'building' },
  28. }).then(data => {
  29. if (data.length > 0) {
  30. setShareContentId(data[0].shareContentId)
  31. changeImg(data[0].shareContentImg)
  32. changeInput(data[0].shareContentTitle)
  33. }
  34. }).catch(err => {
  35. message.info(err.msg || err.message)
  36. })
  37. }, [])
  38. }
  39. const submitShare = () => {
  40. if (buildingId) {
  41. if (shareContentId) {
  42. request({
  43. ...apis.activity.updateShareContent,
  44. urlData: { id: shareContentId },
  45. data: { targetId: buildingId, shareContentType: 'building', shareContentImg: imgValue,shareContentTitle: inputValue },
  46. }).then(data => {
  47. message.info('保存成功')
  48. }).catch(err => {
  49. message.info(err.msg || err.message)
  50. })
  51. } else {
  52. request({
  53. ...apis.activity.addShareContent,
  54. data: { targetId: buildingId, shareContentType: 'building', shareContentImg: imgValue,shareContentTitle: inputValue },
  55. }).then(data => {
  56. setShareContentId(data.shareContentId)
  57. message.info('保存成功')
  58. }).catch(err => {
  59. message.info(err.msg || err.message)
  60. })
  61. }
  62. } else {
  63. message.warn('请先保存基本信息数据')
  64. }
  65. }
  66. return <div style={{ padding: '20px' }}>
  67. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  68. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板</p>
  69. <div>
  70. {/* <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}>
  71. <img src={logo} style={{ width: '22px', marginRight: '10px' }} />
  72. 南京云致
  73. </p> */}
  74. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue ? inputValue : ''}</p>
  75. <img style={{ width: '200px', height: '160px' }} src={imgValue ? imgValue : poster2} alt="" />
  76. </div>
  77. </div>
  78. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  79. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享标题</p>
  80. <Input placeholder="请输入分享标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
  81. </div>
  82. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  83. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>楼盘分享图</p>
  84. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  85. </div>
  86. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginTop: '20px' }}>建议图片尺寸:750*600px,比例5:4,格式:jpg,用于楼盘分享好友</p>
  87. <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
  88. <Button onClick={() => router.go(-1)}>取消</Button>
  89. </div>
  90. }
  91. export default Share