Share.jsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker, message, Card } from 'antd';
  3. import router from 'umi/router';
  4. import apis from '@/services/apis';
  5. import moment from 'moment';
  6. import BuildSelect from '@/components/SelectButton/BuildSelect2';
  7. import Wangedit from '@/components/Wangedit/Wangedit';
  8. import request from '@/utils/request';
  9. import yinhao from '@/assets/yinhao.png';
  10. import ImageUploader from '@/components/XForm/ImageUpload';
  11. import logo from '@/assets/logo.svg';
  12. import touxiang from '@/assets/touxiang.jpg';
  13. import poster1 from '@/assets/poster1.png';
  14. import poster2 from '@/assets/poster2.png';
  15. import xiaochengxu from '@/assets/xiaochengxu.png';
  16. const { TextArea } = Input;
  17. const cancelPage = () => {
  18. router.go('-1');
  19. };
  20. const Share = props => {
  21. const { dynamicId } = props;
  22. const [inputValue, changeInput] = useState('');
  23. const [imgValue, changeImg] = useState('');
  24. const [shareContentId, setShareContentId] = useState('');
  25. useEffect(() => {
  26. if (dynamicId) {
  27. request({
  28. ...apis.activity.shareContent,
  29. params: { targetId: dynamicId, targetType: 'activity' },
  30. })
  31. .then(data => {
  32. if (data.length > 0) {
  33. setShareContentId(data[0].shareContentId);
  34. changeImg(data[0].shareContentImg);
  35. changeInput(data[0].shareContentTitle);
  36. }
  37. })
  38. .catch(err => {
  39. message.info(err.msg || err.message);
  40. });
  41. }
  42. }, [dynamicId]);
  43. const submitShare = () => {
  44. if (dynamicId) {
  45. if (shareContentId) {
  46. request({
  47. ...apis.activity.updateShareContent,
  48. urlData: { id: shareContentId },
  49. data: {
  50. targetId: dynamicId,
  51. shareContentType: 'activity',
  52. shareContentImg: imgValue,
  53. shareContentTitle: inputValue,
  54. },
  55. })
  56. .then(data => {
  57. message.info('保存成功');
  58. })
  59. .catch(err => {
  60. message.info(err.msg || err.message);
  61. });
  62. } else {
  63. request({
  64. ...apis.activity.addShareContent,
  65. data: {
  66. targetId: dynamicId,
  67. shareContentType: 'activity',
  68. shareContentImg: imgValue,
  69. shareContentTitle: inputValue,
  70. },
  71. })
  72. .then(data => {
  73. setShareContentId(data.shareContentId);
  74. message.info('保存成功');
  75. })
  76. .catch(err => {
  77. message.info(err.msg || err.message);
  78. });
  79. }
  80. } else {
  81. message.warn('请先保存基本信息数据');
  82. }
  83. };
  84. return (
  85. <div style={{ padding: '20px' }}>
  86. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  87. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>
  88. 分享模板
  89. </p>
  90. <div>
  91. <p
  92. style={{
  93. display: 'flex',
  94. alignItems: 'center',
  95. fontSize: '14px',
  96. color: '#999',
  97. margin: '0',
  98. lineHeight: '0',
  99. }}
  100. >
  101. <img src={logo} style={{ width: '22px', marginRight: '10px' }} alt="" />
  102. 橙蕉互动
  103. </p>
  104. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>
  105. {inputValue || '置业V客厅 精准获客平台'}
  106. </p>
  107. <img style={{ width: '200px', height: '160px' }} src={imgValue || poster2} alt="" />
  108. </div>
  109. </div>
  110. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  111. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>
  112. 分享标题
  113. </p>
  114. <Input
  115. placeholder="请输入分享标题"
  116. value={inputValue}
  117. onChange={e => changeInput(e.target.value)}
  118. />
  119. </div>
  120. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  121. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>
  122. 活动分享图
  123. </p>
  124. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  125. </div>
  126. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginTop: '20px' }}>
  127. 建议图片尺寸:750*600px,比例5:4,格式:jpg,用于活动分享好友
  128. </p>
  129. <Button
  130. type="primary"
  131. htmlType="submit"
  132. onClick={submitShare}
  133. style={{ margin: '40px 40px 40px 220px' }}
  134. >
  135. {' '}
  136. 确定
  137. </Button>
  138. <Button onClick={() => cancelPage()}>取消</Button>
  139. </div>
  140. );
  141. };
  142. export default Share;