知与行后台管理端

editActivity.jsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 moment from 'moment';
  6. import router from 'umi/router';
  7. import BuildSelect from '../../components/SelectButton/BuildSelect'
  8. import XForm, { FieldTypes } from '../../components/XForm';
  9. import Wangedit from '../../components/Wangedit/Wangedit'
  10. import request from '../../utils/request'
  11. import PosterBottom from '../../assets/bottom.png'
  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. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  19. const { TextArea } = Input;
  20. /**
  21. *
  22. *
  23. * @param {*} props
  24. * @returns
  25. */
  26. const Edit = (props) => {
  27. const [tab, changeTab] = useState('poster')
  28. // const [tab, changeTab] = useState('basic')
  29. const dynamicId = props.location.query.dynamicId
  30. const [dynamicData, setDynamicData] = useState({})
  31. if (dynamicId) {
  32. useEffect(() => {
  33. getDynamicData(dynamicId);
  34. }, [])
  35. // 查询列表
  36. const getDynamicData = (dynamicId) => {
  37. request({
  38. url: '/api/admin/buildingDynamic/Details',
  39. method: 'GET',
  40. params: { dynamicId },
  41. }).then((data) => {
  42. console.log(data)
  43. setDynamicData(data)
  44. })
  45. }
  46. }
  47. const cancelPage = () => {
  48. router.push({
  49. pathname: '/activity/ActivityList',
  50. });
  51. }
  52. const Basic = (props) => {
  53. const fields = [
  54. {
  55. label: '所属项目',
  56. name: 'buildingId',
  57. render: <BuildSelect />,
  58. value: dynamicData.buildingId,
  59. rules: [
  60. { required: true, message: '请选择所属项目' },
  61. ]
  62. },
  63. {
  64. label: '主图',
  65. name: 'imgUrl',
  66. type: FieldTypes.ImageUploader,
  67. value: dynamicData.imgUrl,
  68. },
  69. {
  70. label: '活动标题',
  71. name: 'title',
  72. type: FieldTypes.Text,
  73. value: dynamicData.title,
  74. rules: [
  75. { required: true, message: '请输入活动标题' },
  76. ]
  77. },
  78. {
  79. label: '活动时间',
  80. name: 'activityTime',
  81. type: FieldTypes.RangePicker,
  82. value: dynamicData.startDate != null ? [moment(dynamicData.startDate, 'YYYY-MM-DD'), moment(dynamicData.endDate, 'YYYY-MM-DD')] : null,
  83. rules: [
  84. { required: true, message: '请选择活动时间' },
  85. ]
  86. },
  87. {
  88. label: '活动地点',
  89. name: 'address',
  90. type: FieldTypes.Text,
  91. value: dynamicData.address,
  92. rules: [
  93. { required: true, message: '请输入活动地点' },
  94. ]
  95. },
  96. {
  97. label: '活动人数',
  98. name: 'enlistNum',
  99. type: FieldTypes.Text,
  100. value: dynamicData.enlistNum,
  101. rules: [
  102. { required: true, message: '请输入活动人数' },
  103. ]
  104. },
  105. {
  106. label: '活动详情',
  107. name: 'desc',
  108. render: <Wangedit />,
  109. value: dynamicData.desc,
  110. },
  111. {
  112. label: '是否需要报名',
  113. name: 'isEnlist',
  114. render: <Radio.Group name="radiogroup">
  115. <Radio value={1}>是</Radio>
  116. <Radio value={0}>否</Radio>
  117. </Radio.Group>,
  118. value: dynamicData.isEnlist != null ? dynamicData.isEnlist - 0 : 1,
  119. },
  120. {
  121. label: '报名时间',
  122. name: 'signupTime',
  123. type: FieldTypes.RangePicker,
  124. value: dynamicData.enlistStart != null ? [moment(dynamicData.enlistStart, 'YYYY-MM-DD'), moment(dynamicData.enlistEnd, 'YYYY-MM-DD')] : null,
  125. rules: [
  126. { required: true, message: '请选择报名时间' },
  127. ]
  128. },
  129. ]
  130. const handleSubmit = val => {
  131. let { activityTime, signupTime, ...submitValue } = val
  132. const [startDate, endDate] = activityTime
  133. submitValue.startDate = moment(startDate).format('YYYY-MM-DD');
  134. submitValue.endDate = moment(endDate).format('YYYY-MM-DD');
  135. const [enlistStart, enlistEnd] = signupTime
  136. submitValue.enlistStart = moment(enlistStart).format('YYYY-MM-DD');
  137. submitValue.enlistEnd = moment(enlistEnd).format('YYYY-MM-DD');
  138. console.log('submit data --->', submitValue)
  139. if (dynamicId) {
  140. submitValue.dynamicId = dynamicId
  141. request({
  142. url: '/api/admin/buildingDynamic/update',
  143. method: 'PUT',
  144. data: submitValue,
  145. }).then((data) => {
  146. cancelPage()
  147. }).catch((err) => {
  148. message.info(err.msg || err.message)
  149. })
  150. } else {
  151. request({
  152. url: '/api/admin/buildingDynamic/add',
  153. method: 'POST',
  154. data: submitValue,
  155. }).then((data) => {
  156. cancelPage()
  157. }).catch((err) => {
  158. message.info(err.msg || err.message)
  159. })
  160. }
  161. }
  162. return <XForm onSubmit={handleSubmit} onCancel={cancelPage} fields={fields}></XForm>
  163. }
  164. const Poster = (props) => {
  165. const [inputValue, changeInput] = useState('')
  166. const [textAreaValue, changeTextArea] = useState('')
  167. const [imgValue, changeImg] = useState('')
  168. return <div>
  169. <div style={{ display: 'flex' }}>
  170. <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
  171. <div style={{ width: '375px', height: '785px', backgroundColor: '#fff', boxShadow: '0px 0px 16px 6px rgba(0,0,0,0.15)', position: 'relative', margin: '0 auto' }}>
  172. <img style={{ width: '100%', height: '300px' }} src={imgValue ? imgValue : poster1} alt="" />
  173. <div style={{ display: 'flex', alignItems: 'center', marginTop: '-24px' }}>
  174. <img style={{ width: '70px', height: '70px', border: '4px solid #fff', borderRadius: '35px', marginLeft: '16px' }} src={touxiang} alt="" />
  175. <span style={{ color: '#222', fontWeight: '600', margin: '24px 10px 0 14px', fontSize: '17px' }}>喵喵</span>
  176. <span style={{ color: '#999', marginTop: '25px', fontSize: '17px' }}>邀您阅读</span>
  177. <span style={{ color: '#999', margin: '25px 0 0 60px', fontSize: '17px' }}>2019.09.21</span>
  178. </div>
  179. <p style={{
  180. margin: '10px 20px', fontSize: '20px', color: '#222', fontWeight: '600',
  181. display: '-webkit-box', lineClamp: '3', height: '60px',
  182. WebkitLineClamp: '2',
  183. WebkitBoxOrient: 'vertical',
  184. overflow: 'hidden',
  185. textOverflow: 'ellipsis'
  186. }}>{inputValue ? inputValue : '海报标题'}</p>
  187. <img src={yinhao} style={{ width: '30px', marginLeft: '10px' }} alt="" />
  188. <p style={{
  189. margin: '16px 20px 28px 20px', fontSize: '17px', color: '#999',
  190. display: '-webkit-box', lineClamp: '3', height: '76px',
  191. WebkitLineClamp: '3',
  192. WebkitBoxOrient: 'vertical',
  193. overflow: 'hidden',
  194. textOverflow: 'ellipsis'
  195. }}>{textAreaValue ? textAreaValue : '海报描述'}</p>
  196. <img src={PosterBottom} style={{ width: '100%' }} alt="" />
  197. </div>
  198. <p style={{ textAlign: 'center', fontSize: '19px', color: '#666', marginTop: '30px' }}>海报模板</p>
  199. </div>
  200. <div >
  201. <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
  202. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报图片</p>
  203. <ImageUploader onChange={e => changeImg(e)} />
  204. </div>
  205. <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
  206. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
  207. <Input style={{ width: '20vw' }} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
  208. </div>
  209. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  210. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述</p>
  211. <TextArea rows={5} onChange={e => changeTextArea(e.target.value)} />
  212. </div>
  213. </div>
  214. </div>
  215. <Button type="primary" onClick={() => router.go(-1)} style={{ margin: '40px 40px 40px 30vw' }}> 确定</Button>
  216. <Button onClick={() => router.go(-1)}>取消</Button>
  217. </div>
  218. }
  219. const Share = (props) => {
  220. const [inputValue, changeInput] = useState('')
  221. const [imgValue, changeImg] = useState('')
  222. // const changeInputValue = e => {
  223. // changeInput(e.target.value)
  224. // }
  225. // const handleSubmit = (values) => {
  226. // }
  227. return <div style={{ padding: '20px' }}>
  228. <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
  229. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板</p>
  230. <div>
  231. <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}><img src={logo} style={{ width: '22px', marginRight: '10px' }} />知与行互动</p>
  232. <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue ? inputValue : '置业V客厅 精准获客平台'}</p>
  233. <img style={{ width: '200px', height: '140px' }} src={imgValue ? imgValue : poster2} alt="" />
  234. </div>
  235. </div>
  236. <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
  237. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
  238. <Input placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
  239. </div>
  240. <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
  241. <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享图片</p>
  242. <ImageUploader onChange={e => changeImg(e)} />
  243. </div>
  244. <Button type="primary" htmlType="submit" style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
  245. <Button onClick={() => router.go(-1)}>取消</Button>
  246. </div>
  247. }
  248. return (
  249. <div>
  250. <div>
  251. <Radio.Group value={tab} buttonStyle="solid" onChange={e => changeTab(e.target.value)}>
  252. <Radio.Button value="basic">基本信息</Radio.Button>
  253. <Radio.Button value="poster">海报图片</Radio.Button>
  254. <Radio.Button value="share">分享设置</Radio.Button>
  255. </Radio.Group>
  256. </div>
  257. <div>
  258. {tab === 'basic' && <Basic />}
  259. {tab === 'poster' && <Poster />}
  260. {tab === 'share' && <Share />}
  261. </div>
  262. </div>
  263. );
  264. }
  265. export default Edit