editActivity.jsx 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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 Prompt from 'umi/prompt';
  5. import router from 'umi/router';
  6. import styles from '../style/GoodsList.less';
  7. import apis from '../../services/apis';
  8. import moment from 'moment';
  9. import ActivityType from '../../components/SelectButton/ActivityType'
  10. import XForm, { FieldTypes } from '../../components/XForm';
  11. import Wangedit from '../../components/Wangedit/Wangedit'
  12. import request from '../../utils/request'
  13. import yinhao from '../../assets/yinhao.png'
  14. import ImageUploader from '../../components/XForm/ImageUpload';
  15. import logo from '../../assets/logo.png';
  16. import touxiang from '../../assets/touxiang.jpg';
  17. import poster1 from '../../assets/poster1.png';
  18. import poster2 from '../../assets/poster2.png';
  19. import xiaochengxu from '../../assets/xiaochengxu.png'
  20. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  21. const { TextArea } = Input;
  22. const formItemLayout = {
  23. labelCol: { span: 6 },
  24. wrapperCol: { span: 14 },
  25. };
  26. const cancelPage = () => {
  27. router.push({
  28. pathname: '/activity/ActivityList',
  29. });
  30. }
  31. const BasicForm = props => {
  32. const [isEnlist, setIsEnlist] = useState(1)
  33. const [activityStatus, setActivityStatus] = useState(1)
  34. const [disable, setDisable] = useState(false)
  35. const [data, setData] = useState(1)
  36. const [showSignupTime, setShowSignupTime] = useState([])
  37. const radioOnChange = e => {
  38. setIsEnlist(e.target.value)
  39. }
  40. const { dynamicId } = props
  41. // 查询详情
  42. const getDynamicData = dynamicId => {
  43. request({ ...apis.activity.details, params: { dynamicId } }).then(data => {
  44. data.activityTime = [moment(data.startDate), moment(data.endDate)]
  45. data.signupTime = [moment(data.enlistStart), moment(data.enlistEnd)]
  46. // setSignupTime([moment(data.enlistStart), moment(data.enlistEnd)])
  47. setData(data)
  48. setIsEnlist(data.isEnlist)
  49. setActivityStatus(data.activityStatus)
  50. setDisable(data.activityStatus === 0)
  51. props.form.setFieldsValue(data)
  52. })
  53. }
  54. // eslint-disable-next-line react-hooks/rules-of-hooks
  55. useEffect(() => {
  56. props.form.setFieldsValue({ isEnlist })
  57. if (dynamicId) {
  58. getDynamicData(dynamicId);
  59. }
  60. }, [])
  61. const checkTime = () => {
  62. function compareDate(dateTime1, dateTime2) {
  63. return new Date(dateTime1) > new Date(dateTime2)
  64. }
  65. // 1)修改后的开始时间不得大于当前时间(会存在已经成功报名的用户)
  66. // (2)修改后开始时间<当前时间<修改后结束时间:活动进行中
  67. // (3)修改后结束时间<当前时间:活动已结束
  68. if (showSignupTime[0]) {
  69. // const date = data.signupTime
  70. const nowDate = new Date()
  71. // console.log(compareDate(nowDate, showSignupTime[0]))
  72. if (compareDate(nowDate, showSignupTime[0])) {
  73. return true
  74. } else {
  75. // return '修改后的开始时间不得大于当前时间(会存在已经成功报名的用户)'
  76. }
  77. }
  78. return true
  79. }
  80. const handleSubmit = e => {
  81. e.preventDefault();
  82. props.form.validateFields((err, values) => {
  83. if (!err) {
  84. console.log('Received values of form: ', values);
  85. const { activityTime, signupTime } = values
  86. const [startDate, endDate] = activityTime
  87. values.startDate = moment(startDate).format('YYYY-MM-DD HH:mm');
  88. values.endDate = moment(endDate).format('YYYY-MM-DD HH:mm');
  89. if (signupTime) {
  90. const [enlistStart, enlistEnd] = signupTime
  91. values.enlistStart = moment(enlistStart).format('YYYY-MM-DD HH:mm');
  92. values.enlistEnd = moment(enlistEnd).format('YYYY-MM-DD HH:mm');
  93. }
  94. console.log('submit data --->', values)
  95. if (dynamicId) {
  96. const checks = checkTime()
  97. if (checks != true) {
  98. message.info(checks)
  99. return
  100. }
  101. console.log(data.enlistNum,values.personNum,'143')
  102. if (data.enlistNum > values.personNum) {
  103. message.info('活动人数必须大于已报名人数')
  104. return
  105. }
  106. values.dynamicId = dynamicId
  107. request({ ...apis.activity.update, data: values }).then(data => {
  108. message.info('保存成功')
  109. cancelPage()
  110. }).catch((err) => {
  111. message.info(err.msg || err.message)
  112. })
  113. } else {
  114. request({ ...apis.activity.add, data: { ...values } }).then((data) => {
  115. message.info('保存成功')
  116. cancelPage()
  117. // router.push({
  118. // pathname: '/activity/editActivity',
  119. // query: {
  120. // dynamicId: data.dynamicId,
  121. // },
  122. // });
  123. // router.go(-1)
  124. }).catch((err) => {
  125. message.info(err.msg || err.message)
  126. })
  127. }
  128. }
  129. });
  130. }
  131. const changeTime = (value, date) => {
  132. // console.log(value, data, '-----checkTime---------')
  133. // console.log(props.form.getFieldsValue(), '--------time1-----------')
  134. // let datas = data
  135. // console.log(value, date, datas)
  136. // datas.signupTime = date
  137. // // data.signupTime = [moment(data.enlistStart), moment(data.enlistEnd)]
  138. // console.log(datas,'-------datas--------')
  139. // props.form.setFieldsValue(data)
  140. setShowSignupTime(date)
  141. // props.form.setFieldsValue(datas)
  142. // // form.setFieldsValue
  143. // console.log('-------1--------')
  144. }
  145. const { getFieldDecorator } = props.form;
  146. return (
  147. <>
  148. <Form {...formItemLayout} onSubmit={handleSubmit}>
  149. <Form.Item label="活动类型">
  150. {getFieldDecorator('dynamicTypeId', {
  151. rules: [
  152. {
  153. required: true,
  154. message: '请选择活动类型',
  155. },
  156. ],
  157. })(<ActivityType disabled={disable} />)}
  158. </Form.Item>
  159. <Form.Item label="活动封面图" help="建议图片尺寸:690px*388px,比例16:9,格式:jpg,用于:首页推荐/活动列表">
  160. {getFieldDecorator('listImgUrl', {
  161. rules: [
  162. {
  163. required: true,
  164. message: '请选择活动封面图1',
  165. },
  166. ],
  167. })(<ImageUploader />)}
  168. </Form.Item>
  169. {/* <Form.Item label="活动封面图2" help="建议图片尺寸:750*250,比例3:1,格式:jpg,用于:项目详情页">
  170. {getFieldDecorator('bannerListImg', {
  171. rules: [
  172. {
  173. required: true,
  174. message: '请选择活动封面图2',
  175. },
  176. ],
  177. })(<ImageUploader />)}
  178. </Form.Item> */}
  179. <Form.Item label="活动详情主图" help="建议图片尺寸:750*564px,比例4:3,格式:jpg,用于:普通活动详情">
  180. {getFieldDecorator('imgUrl', {
  181. rules: [
  182. {
  183. required: true,
  184. message: '请选择活动详情主图',
  185. },
  186. ],
  187. })(<ImageUploader />)}
  188. </Form.Item>
  189. <Form.Item label="活动标题">
  190. {getFieldDecorator('title', {
  191. rules: [
  192. {
  193. required: true,
  194. message: '请输入活动标题',
  195. },
  196. ],
  197. })(<Input />)}
  198. </Form.Item>
  199. <Form.Item label="活动时间">
  200. {getFieldDecorator('activityTime', {
  201. rules: [
  202. {
  203. required: true,
  204. message: '请选择活动时间',
  205. },
  206. ],
  207. })(<RangePicker showTime={{ format: 'HH:mm' }}
  208. format="YYYY-MM-DD HH:mm" />)}
  209. </Form.Item>
  210. <Form.Item label="活动地点">
  211. {getFieldDecorator('address', {
  212. rules: [
  213. {
  214. required: true,
  215. message: '请输入活动地点',
  216. },
  217. ],
  218. })(<Input />)}
  219. </Form.Item>
  220. {/* disabled={activityStatus === 0 ? true : false} */}
  221. <Form.Item label="活动人数" help="当前活动最多可报名人数">
  222. {getFieldDecorator('personNum', {
  223. rules: [
  224. {
  225. required: true,
  226. message: '请输入活动人数',
  227. },
  228. // {
  229. // min: data.personNum,min={data.personNum || 0}
  230. // message: '活动人数必须大于已报名人数',
  231. // },
  232. ],
  233. })(<Input type="number" />)}
  234. </Form.Item>
  235. <Form.Item label="用户携带人数" help="每个用户最多可携带参与活动的人数">
  236. {getFieldDecorator('maxEnlistByPerson', {
  237. rules: [
  238. {
  239. required: true,
  240. message: '请输入用户携带人数',
  241. },
  242. ],
  243. })(<Input type="number" min={1} />)}
  244. </Form.Item>
  245. <Form.Item label="活动详情">
  246. {getFieldDecorator('desc')(<Wangedit />)}
  247. </Form.Item>
  248. <Form.Item label="报名时间">
  249. {getFieldDecorator('signupTime', {
  250. rules: [
  251. {
  252. required: true,
  253. message: '请选择报名时间',
  254. },
  255. ],
  256. })(<RangePicker showTime={{ format: 'HH:mm' }}
  257. format="YYYY-MM-DD HH:mm" onChange={changeTime} />)}
  258. </Form.Item>
  259. <Form.Item label="权重">
  260. {getFieldDecorator('heavy', {
  261. rules: [
  262. {
  263. required: true,
  264. message: '请输入权重',
  265. },
  266. ],
  267. })(<Input type="number" style={{ width: 80 }} />)}<span style={{ marginLeft: 30, color: 'grey' }}>数字越大越靠前</span>
  268. </Form.Item>
  269. <Form.Item wrapperCol={{ span: 12, offset: 8 }}>
  270. <Button type="primary" htmlType="submit">
  271. 确认
  272. </Button>
  273. &nbsp;&nbsp;&nbsp;&nbsp;
  274. <Button onClick={() => cancelPage()}>
  275. 取消
  276. </Button>
  277. </Form.Item>
  278. </Form>
  279. </>
  280. )
  281. }
  282. const Basic = Form.create({ name: 'BasicForm' })(BasicForm);
  283. const Poster = props => {
  284. const { dynamicId } = props
  285. const [inputValue, changeInput] = useState('')
  286. const [textAreaValue, changeTextArea] = useState('')
  287. const [imgValue, changeImg] = useState('')
  288. const [posterId, setPosterId] = useState('')
  289. useEffect(() => {
  290. if (dynamicId) {
  291. request({ ...apis.activity.poster, params: { targetId: dynamicId, targetType: 'activity' } }).then(data => {
  292. if (data.length > 0) {
  293. setPosterId(data[0].posterId)
  294. changeImg(data[0].posterImg)
  295. changeTextArea(data[0].posterDescription)
  296. changeInput(data[0].posterTitle)
  297. }
  298. }).catch(err => {
  299. message.info(err.msg || err.message)
  300. })
  301. }
  302. // getMiniappName()
  303. }, [])
  304. // 获取小程序名称
  305. // const [miniappName, setMiniappName] = useState('')
  306. // function getMiniappName() {
  307. // request({ ...apis.building.getMiniappName }).then(res => {
  308. // console.log(res, "0000000000000")
  309. // setMiniappName(res)
  310. // })
  311. // }
  312. const submitPoster = () => {
  313. if (dynamicId) {
  314. if (posterId) {
  315. request({ ...apis.activity.updatePoster, urlData: { id: posterId }, data: { targetId: dynamicId, targetType: 'activity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue } }).then(data => {
  316. message.info('保存成功')
  317. }).catch(err => {
  318. message.info(err.msg || err.message)
  319. })
  320. } else {
  321. request({ ...apis.activity.addPoster, data: { targetId: dynamicId, targetType: 'activity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue } }).then(data => {
  322. setPosterId(data.posterId)
  323. message.info('保存成功')
  324. }).catch(err => {
  325. message.info(err.msg || err.message)
  326. })
  327. }
  328. } else {
  329. message.warn('请先保存基本信息数据')
  330. }
  331. }
  332. return <div>
  333. <div style={{ display: 'flex' }}>
  334. <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
  335. <div style={{ width: '375px', height: '700px', backgroundColor: '#fff', boxShadow: '0px 0px 16px 6px rgba(0,0,0,0.15)', position: 'relative', margin: '0 auto' }}>
  336. <img style={{ width: '100%', height: '300px' }} src={imgValue || poster1} alt="" />
  337. <div style={{ display: 'flex', alignItems: 'center', marginTop: '-24px' }}>
  338. <img style={{ width: '70px', height: '70px', border: '4px solid #fff', borderRadius: '35px', marginLeft: '16px' }} src={touxiang} alt="" />
  339. <span style={{ color: '#222', fontWeight: '600', margin: '24px 10px 0 14px', fontSize: '17px' }}>喵喵</span>
  340. <span style={{ color: '#999', marginTop: '25px', fontSize: '17px' }}>邀您参与</span>
  341. <span style={{ color: '#999', margin: '25px 0 0 60px', fontSize: '17px' }}>2019.09.21</span>
  342. </div>
  343. <p style={{
  344. margin: '10px 20px',
  345. fontSize: '20px',
  346. color: '#222',
  347. fontWeight: '600',
  348. display: '-webkit-box',
  349. lineClamp: '3',
  350. height: '60px',
  351. WebkitLineClamp: '2',
  352. WebkitBoxOrient: 'vertical',
  353. overflow: 'hidden',
  354. textOverflow: 'ellipsis',
  355. }}>{inputValue || '海报标题'}</p>
  356. <img src={yinhao} style={{ width: '30px', marginLeft: '20px' }} alt="" />
  357. <p style={{
  358. margin: '16px 20px 28px 20px',
  359. fontSize: '17px',
  360. color: '#999',
  361. display: '-webkit-box',
  362. lineClamp: '3',
  363. height: '72px',
  364. WebkitLineClamp: '3',
  365. WebkitBoxOrient: 'vertical',
  366. overflow: 'hidden',
  367. textOverflow: 'ellipsis',
  368. }}>{textAreaValue || '海报描述'}</p>
  369. <div style={{ backgroundColor: '#f1f1f1', padding: '22px 30px', boxShadow: '0px 6px 12px -4px #dcdcdc', position: 'relative' }}>
  370. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>长按识别小程序码</p>
  371. <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>进入活动查看详情</p>
  372. <img style={{ width: '80px', position: 'absolute', right: '30px', top: '10px' }} src={xiaochengxu} alt="" />
  373. </div>
  374. </div>
  375. <p style={{ textAlign: 'center', fontSize: '19px', color: '#666', marginTop: '30px' }}>海报模板</p>
  376. </div>
  377. <div >
  378. <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
  379. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>活动海报图</p>
  380. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  381. </div>
  382. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginBottom: '30px' }}>建议图片尺寸:640*670px,比例64:67,格式:jpg,用于普通活动海报</p>
  383. <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
  384. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
  385. <Input style={{ width: '20vw' }} value={inputValue} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
  386. </div>
  387. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  388. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述</p>
  389. <TextArea rows={5} maxLength={1024} value={textAreaValue} onChange={e => changeTextArea(e.target.value)} />
  390. </div>
  391. </div>
  392. </div>
  393. <Button type="primary" onClick={submitPoster} style={{ margin: '40px 40px 40px 30vw' }}> 确定</Button>
  394. <Button onClick={() => cancelPage()}>
  395. 取消
  396. </Button>
  397. </div>
  398. }
  399. const Share = props => {
  400. const { dynamicId } = props
  401. const [inputValue, changeInput] = useState('')
  402. const [imgValue, changeImg] = useState('')
  403. const [shareContentId, setShareContentId] = useState('')
  404. useEffect(() => {
  405. if (dynamicId) {
  406. request({ ...apis.activity.shareContent, params: { targetId: dynamicId, targetType: 'activity' } }).then(data => {
  407. if (data.length > 0) {
  408. setShareContentId(data[0].shareContentId)
  409. changeImg(data[0].shareContentImg)
  410. changeInput(data[0].shareContentTitle)
  411. }
  412. }).catch(err => {
  413. message.info(err.msg || err.message)
  414. })
  415. }
  416. }, [dynamicId])
  417. const submitShare = () => {
  418. if (dynamicId) {
  419. if (shareContentId) {
  420. request({ ...apis.activity.updateShareContent, urlData: { id: shareContentId }, data: { targetId: dynamicId, shareContentType: 'activity', shareContentImg: imgValue, shareContentTitle: inputValue } }).then(data => {
  421. message.info('保存成功')
  422. }).catch(err => {
  423. message.info(err.msg || err.message)
  424. })
  425. } else {
  426. request({ ...apis.activity.addShareContent, data: { targetId: dynamicId, shareContentType: 'activity', shareContentImg: imgValue, shareContentTitle: inputValue } }).then(data => {
  427. setShareContentId(data.shareContentId)
  428. message.info('保存成功')
  429. }).catch(err => {
  430. message.info(err.msg || err.message)
  431. })
  432. }
  433. } else {
  434. message.warn('请先保存基本信息数据')
  435. }
  436. }
  437. return <div style={{ padding: '20px' }}>
  438. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  439. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板</p>
  440. <div>
  441. {/* <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}>
  442. <img src={logo} style={{ width: '22px', marginRight: '10px' }} alt=""/>南京云致</p> */}
  443. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue || ''}</p>
  444. <img style={{ width: '200px', height: '160px' }} src={imgValue || poster2} alt="" />
  445. </div>
  446. </div>
  447. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  448. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享标题</p>
  449. <Input placeholder="请输入分享标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
  450. </div>
  451. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  452. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>活动分享图</p>
  453. <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
  454. </div>
  455. <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginTop: '20px' }}>建议图片尺寸:750*600px,比例5:4,格式:jpg,用于活动分享好友</p>
  456. <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
  457. <Button onClick={() => cancelPage()}>
  458. 取消
  459. </Button>
  460. </div>
  461. }
  462. /**
  463. *
  464. *
  465. * @param {*} props
  466. * @returns
  467. */
  468. const Edit = props => {
  469. const [tab, changeTab] = useState('basic')
  470. const { dynamicId } = props.location.query
  471. return (
  472. <div>
  473. {/* <div>
  474. <Radio.Group value={tab} buttonStyle="solid" onChange={e => changeTab(e.target.value)}>
  475. <Radio.Button value="basic">基本信息</Radio.Button>
  476. <Radio.Button value="poster">海报图片</Radio.Button>
  477. <Radio.Button value="share">分享设置</Radio.Button>
  478. </Radio.Group>
  479. </div> */}
  480. <div>
  481. {tab === 'basic' && <Basic dynamicId={dynamicId} />}
  482. {tab === 'poster' && <Poster dynamicId={dynamicId}/>}
  483. {tab === 'share' && <Share dynamicId={dynamicId}/>}
  484. </div>
  485. <Prompt message={location =>
  486. (location.pathname.startsWith('/activity/ActivityList')
  487. ? true
  488. : (location.pathname.startsWith("/activity/detailActivity") ? true : localStorage.removeItem("activePageParams")))} />
  489. </div>
  490. );
  491. }
  492. export default Edit