policyDetails.jsx 8.8 KB

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