proDetails.jsx 8.4 KB

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