newDetails.jsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Modal,
  5. message,
  6. Spin,
  7. Upload,
  8. Button,
  9. Form,
  10. } from 'antd';
  11. import {getProvince} from '@/NewDicProvinceList';
  12. import '../policy/policy.less';
  13. import {getReleaseStateList,getNewPosition,splitUrl,getNewType} from '@/tools';
  14. const NewDetail = Form.create()(React.createClass({
  15. getInitialState() {
  16. return {
  17. visible: false,
  18. loading: false,
  19. auditStatus: 0,
  20. textFileList: [],
  21. videoFileList: [],
  22. pictureUrl: [],
  23. };
  24. },
  25. loadData(id) {
  26. this.setState({
  27. loading: true
  28. });
  29. $.ajax({
  30. method: "get",
  31. dataType: "json",
  32. crossDomain: false,
  33. url: globalConfig.context + '/api/admin/news/detail' ,
  34. data: {
  35. id: id
  36. },
  37. success: function (data) {
  38. let thisData = data.data;
  39. if (!thisData) {
  40. if (data.error && data.error.length) {
  41. message.warning(data.error[0].message);
  42. };
  43. thisData = {};
  44. };
  45. document.querySelector('.txt').innerHTML='';
  46. let publishPagesArr = [];
  47. let pageList = thisData.publishPages?(thisData.publishPages).split(','):[];
  48. pageList.map(item=>{
  49. publishPagesArr.push(item.publishPage)
  50. });
  51. let ProvinceS = thisData.provinceId,page=[], //getprovince
  52. ProvinceCity = getProvince(ProvinceS);
  53. let pages =thisData.newsPublishs ||[];
  54. pages.map(item=>{
  55. page.push(item.publishPage)
  56. })
  57. let eleDiv = document.createElement('div');
  58. eleDiv.innerHTML=thisData.content;
  59. document.querySelector('.txt').append(eleDiv);
  60. this.setState({
  61. id:thisData.id,
  62. publishPagesArr:publishPagesArr,
  63. data: thisData,
  64. page:page,
  65. eleDiv:eleDiv,
  66. ProvinceCity:ProvinceCity,
  67. edit:{content:thisData.content},
  68. auditStatus:thisData.auditStatus,
  69. pictureUrl: thisData.titleImg ? splitUrl(thisData.titleImg, ',', globalConfig.avatarHost + '/upload') : []
  70. });
  71. }.bind(this),
  72. }).always(function () {
  73. this.setState({
  74. loading: false
  75. });
  76. }.bind(this));
  77. },
  78. cancelFun(){
  79. this.props.closeDesc();
  80. },
  81. //刷新发布
  82. updateFun(inex){
  83. this.setState({
  84. loading:true
  85. })
  86. $.ajax({
  87. method: "POST",
  88. dataType: "json",
  89. crossDomain: false,
  90. url: globalConfig.context +'/api/admin/news/updateStatus',
  91. data: {
  92. id: this.state.id,
  93. auditStatus:this.state.auditStatus,
  94. refresh:1
  95. }
  96. }).done(function (data) {
  97. if (!data.error.length) {
  98. message.success('刷新成功!');
  99. this.setState({
  100. loading: false,
  101. });
  102. } else {
  103. message.warning(data.error[0].message);
  104. };
  105. this.props.handOk();
  106. }.bind(this));
  107. },
  108. //撤销发布
  109. revokeFun(){
  110. this.setState({
  111. loading:true
  112. })
  113. $.ajax({
  114. method: "POST",
  115. dataType: "json",
  116. crossDomain: false,
  117. url: globalConfig.context + '/api/admin/news/updateStatus',
  118. data: {
  119. id: this.state.id,
  120. auditStatus:4,
  121. }
  122. }).done(function (data) {
  123. if (!data.error.length) {
  124. message.success('撤销成功!');
  125. this.setState({
  126. loading: false,
  127. });
  128. } else {
  129. message.warning(data.error[0].message);
  130. };
  131. this.props.handOk();
  132. }.bind(this));
  133. },
  134. componentWillMount() {
  135. if (this.props.data.id) {
  136. this.loadData(this.props.data.id);
  137. } else {
  138. this.state.data = {};
  139. };
  140. },
  141. componentWillReceiveProps(nextProps) {
  142. if (!this.props.visible && nextProps.visible) {
  143. this.state.textFileList = [];
  144. this.state.videoFileList = [];
  145. if (nextProps.data.id) {
  146. this.loadData(nextProps.data.id);
  147. } else {
  148. this.state.data = {};
  149. this.state.pictureUrl = [];
  150. };
  151. this.props.form.resetFields();
  152. };
  153. },
  154. render() {
  155. const theData = this.state.data || {};
  156. const FormItem = Form.Item
  157. const formItemLayout = {
  158. labelCol: { span: 6 },
  159. wrapperCol: { span: 12 },
  160. };
  161. return (
  162. <div className='login'>
  163. <Form layout="horizontal" id="demand-form">
  164. <Spin spinning={this.state.loading}>
  165. <div className="clearfix">
  166. <FormItem className="half-item" {...formItemLayout} label="新闻标题">
  167. <span>{theData.title}</span>
  168. </FormItem>
  169. <FormItem className="half-item" {...formItemLayout} label="新闻类型">
  170. <span>{getNewType(theData.type)}</span>
  171. </FormItem>
  172. <FormItem className="half-item" {...formItemLayout} label="热门">
  173. <span>{theData.hot=='0'&&'否'}{theData.hot=='1'&&'是'}</span>
  174. </FormItem>
  175. <FormItem className="half-item" {...formItemLayout} label="新闻来源">
  176. <span>{theData.source}</span>
  177. </FormItem>
  178. <FormItem className="half-item" {...formItemLayout} label="省市区">
  179. <span>{this.state.ProvinceCity}</span>
  180. </FormItem>
  181. </div>
  182. <div>
  183. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="来源链接">
  184. <span>{theData.sourceUrl}</span>
  185. </FormItem>
  186. </div>
  187. <div>
  188. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="关键字">
  189. <span>{theData.keyword}</span>
  190. </FormItem>
  191. </div>
  192. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="新闻图片">
  193. <div className="clearfix">
  194. <Upload className="demandDetailShow-upload"
  195. listType="picture-card"
  196. fileList={this.state.pictureUrl}
  197. onPreview={(file) => {
  198. this.setState({
  199. previewImage: file.url || file.thumbUrl,
  200. previewVisible: true,
  201. });
  202. }} >
  203. </Upload>
  204. <Modal maskClosable={false} footer={null}
  205. visible={this.state.previewVisible}
  206. onCancel={() => { this.setState({ previewVisible: false }) }}>
  207. <img alt="" style={{ width: '100%' }} src={this.state.previewImage || ''} />
  208. </Modal>
  209. </div>
  210. </FormItem>
  211. <div className="clearfix">
  212. <FormItem className="half-item" {...formItemLayout} label="发布状态">
  213. <span>{getReleaseStateList(theData.auditStatus)}</span>
  214. </FormItem>
  215. <FormItem className="half-item" {...formItemLayout} label="发布时间">
  216. <span>{theData.releaseDate?(new Date(theData.releaseDate)).toLocaleString():''}</span>
  217. </FormItem>
  218. </div>
  219. {/* <div className="clearfix">
  220. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发布位置">
  221. <span>{getNewPosition(this.state.page)}</span>
  222. </FormItem>
  223. </div> */}
  224. <div className="clearfix breakWord">
  225. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="新闻简介">
  226. <span>{theData.summary}</span>
  227. </FormItem>
  228. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="新闻正文">
  229. <div className="txt"></div>
  230. </FormItem>
  231. </div>
  232. <div className="clearfix">
  233. {this.props.data.auditStatus=='2'&&<FormItem wrapperCol={{ span: 12, offset: 3 }}>
  234. <Button className="set-submit" type="primary" onClick={(e)=>{this.updateFun()}} >
  235. 刷新发布
  236. </Button>
  237. <Button type="danger" style={{marginRight:20}} onClick={(e)=>{this.revokeFun()}}>
  238. 撤销发布
  239. </Button>
  240. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  241. 取消
  242. </Button>
  243. </FormItem>}
  244. </div>
  245. </Spin>
  246. </Form>
  247. </div>
  248. )
  249. }
  250. }));
  251. export default NewDetail;