知与行后台管理端

edithelpActivity.jsx 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. const header = props => {
  22. const [isEnlist, setIsEnlist] = useState(1)
  23. const radioOnChange = e => {
  24. // console.log(e.target.value)
  25. setIsEnlist(e.target.value)
  26. }
  27. // eslint-disable-next-line react-hooks/rules-of-hooks
  28. const [data, setData] = useState({ channelNmae: [], result: [] })
  29. // eslint-disable-next-line react-hooks/rules-of-hooks
  30. const { helpActivityId } = props
  31. const [dynamicData, setDynamicData] = useState({ isEnlist: 1 })
  32. // 详情
  33. const getDynamicData = helpActivityId => {
  34. request({ ...apis.helpActivity.details, params: { helpActivityId } }).then((data) => {
  35. data.activityTime = [moment(data.startDate), moment(data.endDate)]
  36. const num = data.helpNum > 0 ? 1 : 0
  37. setIsEnlist(num)
  38. data.isEnlist = num
  39. props.form.setFieldsValue(data)
  40. setDynamicData(data)
  41. })
  42. }
  43. // eslint-disable-next-line react-hooks/rules-of-hooks
  44. useEffect(() => {
  45. // eslint-disable-next-line no-use-before-define
  46. if (helpActivityId) {
  47. getDynamicData(helpActivityId)
  48. }
  49. }, [])
  50. // function addChannel(params) {
  51. // request({ ...apis.channelList.addChannel, data: { ...params } }).then((data) => {
  52. // setData(data)
  53. // }).catch((err) => {
  54. // console.log(err)
  55. // message.info(err.msg || err.message)
  56. // })
  57. // }
  58. const cancelPage = () => {
  59. router.push({
  60. pathname: '/activity/helpActivity/list',
  61. });
  62. }
  63. function handleSubmit(e) {
  64. e.preventDefault();
  65. props.form.validateFields((err, values) => {
  66. if (!err) {
  67. if (values.isEnlist === 0) {
  68. values.helpNum = 0
  69. }
  70. // 判断助力人数不得超过200
  71. if (values.personNum > 200) {
  72. message.error('助力邀请人数不能超过200')
  73. return
  74. }
  75. // 助力邀请人数>0
  76. if (values.personNum <= 0) {
  77. message.error('助力邀请人数大于0')
  78. return
  79. }
  80. // 判断助力人数必须大于0
  81. if (values.isEnlist === 1) {
  82. if (values.helpNum <= 0) {
  83. message.error('限制助力次数必须大于0')
  84. return
  85. }
  86. }
  87. const { activityTime, signupTime, ...submitValue } = values
  88. const [startDate, endDate] = activityTime
  89. console.log('startDate', activityTime)
  90. submitValue.startDate = moment(startDate).format('YYYY-MM-DD HH:mm:ss');
  91. submitValue.endDate = moment(endDate).format('YYYY-MM-DD HH:mm:ss');
  92. // const [enlistStart, enlistEnd] = signupTime
  93. // submitValue.enlistStart = moment(enlistStart).format('YYYY-MM-DD HH:mm');
  94. // submitValue.enlistEnd = moment(enlistEnd).format('YYYY-MM-DD HH:mm');
  95. console.log('submit data --->', submitValue)
  96. if (helpActivityId) {
  97. submitValue.helpActivityId = helpActivityId
  98. request({ ...apis.helpActivity.update, data: submitValue }).then((data) => {
  99. message.info("保存成功")
  100. cancelPage()
  101. }).catch((err) => {
  102. message.info(err.msg || err.message)
  103. })
  104. } else {
  105. request({ ...apis.helpActivity.add, data: submitValue }).then((data) => {
  106. message.info("保存成功")
  107. cancelPage()
  108. }).catch((err) => {
  109. message.info(err.msg || err.message)
  110. })
  111. }
  112. }
  113. });
  114. }
  115. const { getFieldDecorator } = props.form;
  116. return (
  117. <>
  118. <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={handleSubmit}>
  119. <Form.Item label="所属项目">
  120. {getFieldDecorator('buildingId', {
  121. rules: [
  122. {
  123. required: true,
  124. message: '请选择所属项目',
  125. },
  126. ],
  127. })(<BuildSelect />)}
  128. </Form.Item>
  129. <Form.Item label="活动标题">
  130. {getFieldDecorator('title', {
  131. rules: [
  132. {
  133. required: true,
  134. message: '请输入活动标题',
  135. },
  136. ],
  137. })(<Input />)}
  138. </Form.Item>
  139. <Form.Item label="助力详情主图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于助力活动详情">
  140. {getFieldDecorator('img', {
  141. rules: [
  142. {
  143. required: true,
  144. message: '助力详情主图不能为空',
  145. },
  146. ],
  147. })(<ImageUploader />)}
  148. </Form.Item>
  149. <Form.Item label="助力封面图1" help="建议图片尺寸:750*420px,比例16:9,格式:jpg,用于活动列表">
  150. {getFieldDecorator('listImg', {
  151. rules: [
  152. {
  153. required: true,
  154. message: '助力封面图1不能为空',
  155. },
  156. ],
  157. })(<ImageUploader />)}
  158. </Form.Item>
  159. <Form.Item label="助力封面图2" help="建议图片尺寸:670*224px,比例3:1,格式:jpg,用于首页底部活动轮播">
  160. {getFieldDecorator('bannerListImg', {
  161. rules: [
  162. {
  163. required: true,
  164. message: '助力封面图2不能为空',
  165. },
  166. ],
  167. })(<ImageUploader />)}
  168. </Form.Item>
  169. <Form.Item label="活动时间">
  170. {getFieldDecorator('activityTime', {
  171. rules: [
  172. {
  173. required: true,
  174. message: '请选择活动时间',
  175. },
  176. ],
  177. })(<RangePicker format="YYYY-MM-DD HH:mm:ss" showTime={{ format: 'HH:mm:ss' }}/>)}
  178. </Form.Item>
  179. <Form.Item label="助力邀请人数" min={1} max={10}>
  180. {getFieldDecorator('personNum', {
  181. rules: [
  182. {
  183. required: true,
  184. message: '请输入活动人数',
  185. },
  186. ],
  187. })(<Input type="number" />)}
  188. </Form.Item>
  189. <Form.Item label="助力次数">
  190. {getFieldDecorator('isEnlist', {
  191. rules: [
  192. {
  193. required: true,
  194. message: '请选择助力次数',
  195. },
  196. ],
  197. })(
  198. <Radio.Group onChange={(e) => radioOnChange(e)}>
  199. <Radio value={0}>不限制</Radio>
  200. <Radio value={1}>限制</Radio>
  201. </Radio.Group>,
  202. )}
  203. </Form.Item>
  204. {
  205. isEnlist === 1 && <Form.Item label=" " min={1} max={10}>
  206. {getFieldDecorator('helpNum', {
  207. rules: [
  208. {
  209. required: true,
  210. message: '请输入助力人数',
  211. },
  212. ],
  213. })(<Input type="number" placeholder="助力人数限制"/>)}
  214. </Form.Item>
  215. }
  216. <Form.Item label="活动说明" help="建议宽度:335px,高度不限">
  217. {getFieldDecorator('activityInstructions', {
  218. rules: [
  219. {
  220. required: true,
  221. message: '活动说明不能为空',
  222. },
  223. ],
  224. })(<ImageUploader />)}
  225. </Form.Item>
  226. <Form.Item wrapperCol={{ span: 12, offset: 8 }}>
  227. <Button type="primary" htmlType="submit">
  228. 确认
  229. </Button>
  230. &nbsp;&nbsp;&nbsp;&nbsp;
  231. <Button onClick={() => router.go(-1)}>
  232. 取消
  233. </Button>
  234. </Form.Item>
  235. </Form>
  236. </>
  237. )
  238. }
  239. const Basic = Form.create({ name: 'header' })(header);
  240. /**
  241. *
  242. *
  243. * @param {*} props
  244. * @returns
  245. */
  246. const Edit = props => {
  247. const [tab, changeTab] = useState('basic')
  248. // 判断是否展示助力次数的输入框
  249. // const [help, helpTab] = useState('1')
  250. const { helpActivityId } = props.location.query
  251. const [dynamicData, setDynamicData] = useState({ isEnlist: 1 })
  252. if (helpActivityId) {
  253. // eslint-disable-next-line react-hooks/rules-of-hooks
  254. useEffect(() => {
  255. // eslint-disable-next-line no-use-before-define
  256. getDynamicData(helpActivityId);
  257. }, [])
  258. // 详情
  259. const getDynamicData = (helpActivityId) => {
  260. request({ ...apis.helpActivity.details, params: { helpActivityId } }).then((data) => {
  261. console.log(data)
  262. setDynamicData(data)
  263. })
  264. }
  265. }
  266. const cancelPage = () => {
  267. router.push({
  268. pathname: '/activity/helpActivity/list',
  269. });
  270. }
  271. const radioOnChange = e => {
  272. console.log(e.target.value)
  273. setDynamicData({ ...dynamicData, isEnlist: e.target.value })
  274. }
  275. const Poster = (props) => {
  276. const [inputValue, changeInput] = useState('')
  277. const [textAreaValue, changeTextArea] = useState('')
  278. const [imgValue, changeImg] = useState('')
  279. const [posterId, setPosterId] = useState('')
  280. if (helpActivityId) {
  281. console.log(helpActivityId, 'helpActivityId')
  282. useEffect(() => {
  283. request({ ...apis.activity.poster, params: { targetId: helpActivityId, targetType: 'helpActivity' } }).then((data) => {
  284. console.log(data, "2222")
  285. if (data.length > 0) {
  286. setPosterId(data[0].posterId)
  287. changeImg(data[0].posterImg)
  288. changeTextArea(data[0].posterDescription)
  289. changeInput(data[0].posterTitle)
  290. }
  291. }).catch((err) => {
  292. message.info(err.msg || err.message)
  293. })
  294. getMiniappName()
  295. }, [])
  296. }else{
  297. getMiniappName()
  298. }
  299. // 获取小程序名称
  300. const [miniappName, setMiniappName] = useState('')
  301. function getMiniappName() {
  302. request({ ...apis.building.getMiniappName }).then(res => {
  303. console.log(res, "0000000000000")
  304. setMiniappName(res)
  305. })
  306. }
  307. const submitPoster = () => {
  308. if (helpActivityId) {
  309. if (posterId) {
  310. request({ ...apis.activity.updatePoster, urlData: { id: posterId }, data: { targetId: helpActivityId, targetType: 'helpActivity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue }, }).then((data) => {
  311. message.info("保存成功")
  312. }).catch((err) => {
  313. message.info(err.msg || err.message)
  314. })
  315. } else {
  316. request({ ...apis.activity.addPoster, data: { targetId: helpActivityId, targetType: 'helpActivity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue }, }).then((data) => {
  317. setPosterId(data.posterId)
  318. message.info("保存成功")
  319. }).catch((err) => {
  320. message.info(err.msg || err.message)
  321. })
  322. }
  323. } else {
  324. message.warn("请先保存基本信息数据")
  325. }
  326. }
  327. return <div>
  328. <div style={{ display: 'flex' }}>
  329. <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
  330. <div style={{ width: '375px', height: '700px', backgroundColor: '#fff', boxShadow: '0px 0px 16px 6px rgba(0,0,0,0.15)', position: 'relative', margin: '0 auto' }}>
  331. <img style={{ width: '100%', height: '300px' }} src={imgValue ? imgValue : poster1} alt="" />
  332. <div style={{ display: 'flex', alignItems: 'center', marginTop: '-24px' }}>
  333. <img style={{ width: '70px', height: '70px', border: '4px solid #fff', borderRadius: '35px', marginLeft: '16px' }} src={touxiang} alt="" />
  334. <span style={{ color: '#222', fontWeight: '600', margin: '24px 10px 0 14px', fontSize: '17px' }}>喵喵</span>
  335. <span style={{ color: '#999', marginTop: '25px', fontSize: '17px' }}>邀您参与</span>
  336. <span style={{ color: '#999', margin: '25px 0 0 60px', fontSize: '17px' }}>2019.09.21</span>
  337. </div>
  338. <p style={{
  339. margin: '10px 20px', fontSize: '20px', color: '#222', fontWeight: '600',
  340. display: '-webkit-box', lineClamp: '3', height: '60px',
  341. WebkitLineClamp: '2',
  342. WebkitBoxOrient: 'vertical',
  343. overflow: 'hidden',
  344. textOverflow: 'ellipsis'
  345. }}>{inputValue ? inputValue : '海报标题'}</p>
  346. <img src={yinhao} style={{ width: '30px', marginLeft: '20px' }} alt="" />
  347. <p style={{
  348. margin: '16px 20px 28px 20px', fontSize: '17px', color: '#999',
  349. display: '-webkit-box', lineClamp: '3', height: '72px',
  350. WebkitLineClamp: '3',
  351. WebkitBoxOrient: 'vertical',
  352. overflow: 'hidden',
  353. textOverflow: 'ellipsis'
  354. }}>{textAreaValue ? textAreaValue : '海报描述'}</p>
  355. <div style={{ backgroundColor: '#f1f1f1', padding: '22px 30px', boxShadow: '0px 6px 12px -4px #dcdcdc', position: 'relative' }}>
  356. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>长按识别小程序码</p>
  357. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>进入<span style={{ margin: '0 5px', fontSize: '18px', color: '#333', fontWeight: '600' }}>{miniappName || '置业V顾问'}</span>报名活动</p>
  358. <img style={{ width: '80px', position: 'absolute', right: '30px', top: '10px' }} src={xiaochengxu} alt="" />
  359. </div>
  360. </div>
  361. <p style={{ textAlign: 'center', fontSize: '19px', color: '#666', marginTop: '30px' }}>海报模板</p>
  362. </div>
  363. <div >
  364. <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
  365. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>助力海报图</p>
  366. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  367. </div>
  368. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginBottom: '30px'}}>建议图片尺寸:750*600px,比例5:4,格式:jpg,用于助力活动海报</p>
  369. <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
  370. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
  371. <Input style={{ width: '20vw' }} value={inputValue} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
  372. </div>
  373. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  374. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述</p>
  375. <TextArea rows={5} value={textAreaValue} onChange={e => changeTextArea(e.target.value)} />
  376. </div>
  377. </div>
  378. </div>
  379. <Button type="primary" onClick={submitPoster} style={{ margin: '40px 40px 40px 30vw' }}> 确定</Button>
  380. <Button onClick={() => router.go(-1)}>取消</Button>
  381. </div>
  382. }
  383. const Share = (props) => {
  384. const [inputValue, changeInput] = useState('')
  385. const [imgValue, changeImg] = useState('')
  386. const [shareContentId, setShareContentId] = useState('')
  387. if (helpActivityId) {
  388. useEffect(() => {
  389. request({ ...apis.activity.shareContent, params: { targetId: helpActivityId, targetType: 'helpActivity' }, }).then((data) => {
  390. console.log(data, "2222")
  391. if (data.length > 0) {
  392. setShareContentId(data[0].shareContentId)
  393. changeImg(data[0].shareContentImg)
  394. changeInput(data[0].shareContentTitle)
  395. }
  396. }).catch((err) => {
  397. message.info(err.msg || err.message)
  398. })
  399. }, [])
  400. }
  401. const submitShare = () => {
  402. if (helpActivityId) {
  403. if (shareContentId) {
  404. request({ ...apis.activity.updateShareContent, urlData: { id: shareContentId }, data: { targetId: helpActivityId, shareContentType: 'helpActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
  405. message.info("保存成功")
  406. }).catch((err) => {
  407. message.info(err.msg || err.message)
  408. })
  409. } else {
  410. request({ ...apis.activity.addShareContent, data: { targetId: helpActivityId, shareContentType: 'helpActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
  411. setShareContentId(data.shareContentId)
  412. message.info("保存成功")
  413. }).catch((err) => {
  414. message.info(err.msg || err.message)
  415. })
  416. }
  417. } else {
  418. message.warn("请先保存基本信息数据")
  419. }
  420. }
  421. return <div style={{ padding: '20px' }}>
  422. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  423. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板</p>
  424. <div>
  425. <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}><img src={logo} style={{ width: '22px', marginRight: '10px' }} />知与行互动</p>
  426. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue ? inputValue : '置业V客厅 精准获客平台'}</p>
  427. <img style={{ width: '200px', height: '140px' }} src={imgValue ? imgValue : poster2} alt="" />
  428. </div>
  429. </div>
  430. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  431. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享标题</p>
  432. <Input placeholder="请输入分享标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
  433. </div>
  434. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  435. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>助力分享图</p>
  436. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  437. </div>
  438. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginBottom: '30px'}}>建议图片尺寸:750*600px,比例5:4,格式:jpg,用于助力活动分享好友</p>
  439. <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
  440. <Button onClick={() => router.go(-1)}>取消</Button>
  441. </div>
  442. }
  443. return (
  444. <div>
  445. <div>
  446. <Radio.Group value={tab} buttonStyle="solid" onChange={e => changeTab(e.target.value)}>
  447. <Radio.Button value="basic">基本信息</Radio.Button>
  448. <Radio.Button value="poster">海报图片</Radio.Button>
  449. <Radio.Button value="share">分享设置</Radio.Button>
  450. </Radio.Group>
  451. </div>
  452. <div>
  453. {tab === 'basic' && <Basic helpActivityId={helpActivityId}/>}
  454. {tab === 'poster' && <Poster />}
  455. {tab === 'share' && <Share />}
  456. </div>
  457. </div>
  458. );
  459. }
  460. export default Edit