知与行后台管理端

editGroupActivity.jsx 16KB

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