知与行后台管理端

edithelpActivity.jsx 20KB

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