知与行后台管理端

editNewsList.jsx 12KB

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