知与行后台管理端

editNewsList.jsx 13KB

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