知与行后台管理端

editGroupActivity.jsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 styles from '../../style/GoodsList.less';
  5. import apis from '../../../services/apis';
  6. import moment from 'moment';
  7. import router from 'umi/router';
  8. import BuildSelect from '../../../components/SelectButton/BuildSelect'
  9. import XForm, { FieldTypes } from '../../../components/XForm';
  10. import Wangedit from '../../../components/Wangedit/Wangedit'
  11. import request from '../../../utils/request'
  12. import yinhao from '../../../assets/yinhao.png'
  13. import ImageUploader from '../../../components/XForm/ImageUpload';
  14. import logo from '../../../assets/logo.png';
  15. import touxiang from '../../../assets/touxiang.jpg';
  16. import poster1 from '../../../assets/poster1.png';
  17. import poster2 from '../../../assets/poster2.png';
  18. import xiaochengxu from '../../../assets/xiaochengxu.png'
  19. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  20. const { TextArea } = Input;
  21. /**
  22. *
  23. *
  24. * @param {*} props
  25. * @returns
  26. */
  27. const Edit = props => {
  28. const [tab, changeTab] = useState('basic')
  29. // 判断是否展示助力次数的输入框
  30. // const [help, helpTab] = useState('1')
  31. const { groupActivityId } = props.location.query
  32. const [dynamicData, setDynamicData] = useState({ isEnlist: 1 })
  33. if (groupActivityId) {
  34. // eslint-disable-next-line react-hooks/rules-of-hooks
  35. useEffect(() => {
  36. // eslint-disable-next-line no-use-before-define
  37. getDynamicData(groupActivityId);
  38. }, [])
  39. // 详情
  40. const getDynamicData = (groupActivityId) => {
  41. request({ ...apis.groupActivity.details, urlData: { id: groupActivityId } }).then((data) => {
  42. console.log(data)
  43. setDynamicData(data)
  44. })
  45. }
  46. }
  47. const cancelPage = () => {
  48. router.push({
  49. pathname: '/activity/groupActivity/list',
  50. });
  51. }
  52. const radioOnChange = e => {
  53. console.log(e.target.value)
  54. setDynamicData({ ...dynamicData, isEnlist: e.target.value })
  55. }
  56. const Basic = props => {
  57. const fields = [
  58. {
  59. label: '选择项目',
  60. name: 'buildingId',
  61. render: <BuildSelect />,
  62. value: dynamicData.buildingId,
  63. rules: [
  64. { required: true, message: '请选择项目' },
  65. ],
  66. },
  67. {
  68. label: '活动标题',
  69. name: 'activityName',
  70. type: FieldTypes.Text,
  71. value: dynamicData.activityName,
  72. rules: [
  73. { required: true, message: '请输入活动标题' },
  74. ]
  75. },
  76. {
  77. label: '活动主图',
  78. name: 'mainImg',
  79. type: FieldTypes.ImageUploader,
  80. value: dynamicData.mainImg,
  81. help: '建议图片尺寸:750px*560px',
  82. },
  83. {
  84. label: '活动时间',
  85. name: 'activityTime',
  86. type: FieldTypes.RangePicker,
  87. value: dynamicData.startTime != null ? [moment(dynamicData.startTime, 'YYYY-MM-DD HH:mm'), moment(dynamicData.endTime, 'YYYY-MM-DD HH:mm')] : null,
  88. props: { showTime: { format: 'HH:mm' } },
  89. rules: [
  90. { required: true, message: '请选择活动时间' },
  91. ],
  92. },
  93. {
  94. label: '成团人数',
  95. name: 'groupBuyPeople',
  96. type: FieldTypes.Text,
  97. value: dynamicData.groupBuyPeople,
  98. rules: [
  99. { required: true, message: '请输入成团人数' },
  100. ]
  101. },
  102. {
  103. label: '所需积分',
  104. name: 'integral',
  105. type: FieldTypes.Text,
  106. value: dynamicData.integral,
  107. rules: [
  108. { required: true, message: '请输入所需积分' },
  109. ]
  110. },
  111. {
  112. label: '活动说明',
  113. name: 'descImg',
  114. type: FieldTypes.ImageUploader,
  115. value: dynamicData.descImg,
  116. help: '建议图片尺寸:750px*560px',
  117. },
  118. ]
  119. const handleSubmit = val => {
  120. const { activityTime, signupTime, ...submitValue } = val
  121. console.log('val', val)
  122. const [startTime, endTime] = activityTime
  123. submitValue.startTime = moment(startTime).format('YYYY-MM-DD HH:mm');
  124. submitValue.endTime = moment(endTime).format('YYYY-MM-DD HH:mm');
  125. console.log('submit data --->', submitValue)
  126. if (groupActivityId) {
  127. submitValue.groupActicityId = groupActivityId
  128. request({ ...apis.groupActivity.update, data: submitValue }).then((data) => {
  129. message.info("保存成功")
  130. cancelPage()
  131. }).catch((err) => {
  132. message.info(err.msg || err.message)
  133. })
  134. } else {
  135. request({ ...apis.groupActivity.add, data: submitValue }).then((data) => {
  136. message.info("保存成功")
  137. cancelPage()
  138. }).catch((err) => {
  139. message.info(err.msg || err.message)
  140. })
  141. }
  142. }
  143. return <XForm onSubmit={handleSubmit} onCancel={cancelPage} fields={fields}></XForm>
  144. }
  145. const Poster = (props) => {
  146. const [inputValue, changeInput] = useState('')
  147. const [textAreaValue, changeTextArea] = useState('')
  148. const [imgValue, changeImg] = useState('')
  149. const [posterId, setPosterId] = useState('')
  150. if (groupActivityId) {
  151. console.log(groupActivityId, 'groupActivityId')
  152. useEffect(() => {
  153. request({ ...apis.activity.poster, params: { targetId: groupActivityId, targetType: 'groupActivity' } }).then((data) => {
  154. console.log(data, "2222")
  155. if (data.length > 0) {
  156. setPosterId(data[0].posterId)
  157. changeImg(data[0].posterImg)
  158. changeTextArea(data[0].posterDescription)
  159. changeInput(data[0].posterTitle)
  160. }
  161. }).catch((err) => {
  162. message.info(err.msg || err.message)
  163. })
  164. getMiniappName()
  165. }, [])
  166. }else{
  167. getMiniappName()
  168. }
  169. // 获取小程序名称
  170. const [miniappName, setMiniappName] = useState('')
  171. function getMiniappName() {
  172. request({ ...apis.building.getMiniappName }).then(res => {
  173. console.log(res, "0000000000000")
  174. setMiniappName(res)
  175. })
  176. }
  177. const submitPoster = () => {
  178. if (groupActivityId) {
  179. if (posterId) {
  180. request({ ...apis.activity.updatePoster, urlData: { id: posterId }, data: { targetId: groupActivityId, targetType: 'activity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue }, }).then((data) => {
  181. message.info("保存成功")
  182. }).catch((err) => {
  183. message.info(err.msg || err.message)
  184. })
  185. } else {
  186. request({ ...apis.activity.addPoster, data: { targetId: groupActivityId, targetType: 'groupActivity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue }, }).then((data) => {
  187. setPosterId(data.posterId)
  188. message.info("保存成功")
  189. }).catch((err) => {
  190. message.info(err.msg || err.message)
  191. })
  192. }
  193. } else {
  194. message.warn("请先保存基本信息数据")
  195. }
  196. }
  197. return <div>
  198. <div style={{ display: 'flex' }}>
  199. <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
  200. <div style={{ width: '375px', height: '700px', backgroundColor: '#fff', boxShadow: '0px 0px 16px 6px rgba(0,0,0,0.15)', position: 'relative', margin: '0 auto' }}>
  201. <img style={{ width: '100%', height: '300px' }} src={imgValue ? imgValue : poster1} alt="" />
  202. <div style={{ display: 'flex', alignItems: 'center', marginTop: '-24px' }}>
  203. <img style={{ width: '70px', height: '70px', border: '4px solid #fff', borderRadius: '35px', marginLeft: '16px' }} src={touxiang} alt="" />
  204. <span style={{ color: '#222', fontWeight: '600', margin: '24px 10px 0 14px', fontSize: '17px' }}>喵喵</span>
  205. <span style={{ color: '#999', marginTop: '25px', fontSize: '17px' }}>邀您阅读</span>
  206. <span style={{ color: '#999', margin: '25px 0 0 60px', fontSize: '17px' }}>2019.09.21</span>
  207. </div>
  208. <p style={{
  209. margin: '10px 20px', fontSize: '20px', color: '#222', fontWeight: '600',
  210. display: '-webkit-box', lineClamp: '3', height: '60px',
  211. WebkitLineClamp: '2',
  212. WebkitBoxOrient: 'vertical',
  213. overflow: 'hidden',
  214. textOverflow: 'ellipsis'
  215. }}>{inputValue ? inputValue : '海报标题'}</p>
  216. <img src={yinhao} style={{ width: '30px', marginLeft: '20px' }} alt="" />
  217. <p style={{
  218. margin: '16px 20px 28px 20px', fontSize: '17px', color: '#999',
  219. display: '-webkit-box', lineClamp: '3', height: '72px',
  220. WebkitLineClamp: '3',
  221. WebkitBoxOrient: 'vertical',
  222. overflow: 'hidden',
  223. textOverflow: 'ellipsis'
  224. }}>{textAreaValue ? textAreaValue : '海报描述'}</p>
  225. <div style={{ backgroundColor: '#f1f1f1', padding: '22px 30px', boxShadow: '0px 6px 12px -4px #dcdcdc', position: 'relative' }}>
  226. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>长按识别小程序码</p>
  227. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>进入<span style={{ margin: '0 5px', fontSize: '18px', color: '#333', fontWeight: '600' }}>{miniappName || '置业V顾问'}</span>报名活动</p>
  228. <img style={{ width: '80px', position: 'absolute', right: '30px', top: '10px' }} src={xiaochengxu} alt="" />
  229. </div>
  230. </div>
  231. <p style={{ textAlign: 'center', fontSize: '19px', color: '#666', marginTop: '30px' }}>海报模板</p>
  232. </div>
  233. <div >
  234. <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
  235. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报图片1</p>
  236. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  237. </div>
  238. <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
  239. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题1</p>
  240. <Input style={{ width: '20vw' }} value={inputValue} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
  241. </div>
  242. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  243. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述1</p>
  244. <TextArea rows={5} value={textAreaValue} onChange={e => changeTextArea(e.target.value)} />
  245. </div>
  246. </div>
  247. </div>
  248. <Button type="primary" onClick={submitPoster} style={{ margin: '40px 40px 40px 30vw' }}> 确定</Button>
  249. <Button onClick={() => router.go(-1)}>取消</Button>
  250. </div>
  251. }
  252. const Share = (props) => {
  253. const [inputValue, changeInput] = useState('')
  254. const [imgValue, changeImg] = useState('')
  255. const [shareContentId, setShareContentId] = useState('')
  256. if (groupActivityId) {
  257. useEffect(() => {
  258. request({ ...apis.activity.shareContent, params: { targetId: groupActivityId, targetType: 'groupActivity' }, }).then((data) => {
  259. console.log(data, "2222")
  260. if (data.length > 0) {
  261. setShareContentId(data[0].shareContentId)
  262. changeImg(data[0].shareContentImg)
  263. changeInput(data[0].shareContentTitle)
  264. }
  265. }).catch((err) => {
  266. message.info(err.msg || err.message)
  267. })
  268. }, [])
  269. }
  270. const submitShare = () => {
  271. if (groupActivityId) {
  272. if (shareContentId) {
  273. request({ ...apis.activity.updateShareContent, urlData: { id: shareContentId }, data: { targetId: groupActivityId, shareContentType: 'groupActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
  274. message.info("保存成功")
  275. }).catch((err) => {
  276. message.info(err.msg || err.message)
  277. })
  278. } else {
  279. request({ ...apis.activity.addShareContent, data: { targetId: groupActivityId, shareContentType: 'groupActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
  280. setShareContentId(data.shareContentId)
  281. message.info("保存成功")
  282. }).catch((err) => {
  283. message.info(err.msg || err.message)
  284. })
  285. }
  286. } else {
  287. message.warn("请先保存基本信息数据")
  288. }
  289. }
  290. return <div style={{ padding: '20px' }}>
  291. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  292. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板1</p>
  293. <div>
  294. <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}><img src={logo} style={{ width: '22px', marginRight: '10px' }} />知与行互动</p>
  295. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue ? inputValue : '置业V客厅 精准获客平台'}</p>
  296. <img style={{ width: '200px', height: '140px' }} src={imgValue ? imgValue : poster2} alt="" />
  297. </div>
  298. </div>
  299. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  300. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享标题1</p>
  301. <Input placeholder="请输入分享标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
  302. </div>
  303. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  304. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享图片1</p>
  305. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  306. </div>
  307. <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
  308. <Button onClick={() => router.go(-1)}>取消</Button>
  309. </div>
  310. }
  311. return (
  312. <div>
  313. <div>
  314. <Radio.Group value={tab} buttonStyle="solid" onChange={e => changeTab(e.target.value)}>
  315. <Radio.Button value="basic">基本信息1</Radio.Button>
  316. <Radio.Button value="poster">海报图片1</Radio.Button>
  317. <Radio.Button value="share">分享设置1</Radio.Button>
  318. </Radio.Group>
  319. </div>
  320. <div>
  321. {tab === 'basic' && <Basic />}
  322. {tab === 'poster' && <Poster />}
  323. {tab === 'share' && <Share />}
  324. </div>
  325. </div>
  326. );
  327. }
  328. export default Edit