知与行后台管理端

editNewsList.jsx 14KB

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