知与行后台管理端

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