messageForm.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Icon,
  5. Modal,
  6. message,
  7. Spin,
  8. Upload,
  9. Input,
  10. Button,
  11. Radio,
  12. Form,
  13. Checkbox,
  14. Cascader,
  15. Row,
  16. Select,
  17. Col
  18. } from 'antd';
  19. import { splitUrl} from '@/tools.js';
  20. import {provinceSelect } from '@/NewDicProvinceList';
  21. import Editors from '@/richTextEditors';
  22. const NewDetailForm = Form.create()(React.createClass({
  23. getInitialState() {
  24. return {
  25. visible: false,
  26. loading: false,
  27. auditStatus: 0,
  28. textFileList: [],
  29. videoFileList: [],
  30. };
  31. },
  32. loadData(id) {
  33. this.setState({
  34. loading: true
  35. });
  36. $.ajax({
  37. method: "get",
  38. dataType: "json",
  39. crossDomain: false,
  40. url: globalConfig.context + '/api/admin/news/detail' ,
  41. data: {
  42. id: id
  43. },
  44. success: function (data) {
  45. let thisData = data.data,provice=[];
  46. if (!thisData) {
  47. if (data.error && data.error.length) {
  48. message.warning(data.error[0].message);
  49. };
  50. thisData = {};
  51. };
  52. this.setState({
  53. id:thisData.id,
  54. data: thisData,
  55. Province:provice,
  56. auditStatus:thisData.auditStatus,
  57. });
  58. }.bind(this),
  59. }).always(function () {
  60. this.setState({
  61. loading: false
  62. });
  63. }.bind(this));
  64. },
  65. getPictureUrl(e) {
  66. this.setState({ pictureUrl: e });
  67. },
  68. handleSubmit(e,index) {
  69. e.preventDefault();
  70. this.props.form.validateFields((err, values) => {
  71. if((this.state.edit)==undefined||!this.state.edit||(this.state.edit)=='<p><br></p>'){
  72. message.warning('请填写政策正文');
  73. return false;
  74. }
  75. if (!err) {
  76. this.setState({
  77. loading: true
  78. });
  79. $.ajax({
  80. method: "post",
  81. dataType: "json",
  82. async:true,
  83. url: this.props.data.id ? globalConfig.context + '/api/admin/news/updateNews' : globalConfig.context + '/api/admin/news/apply',
  84. data: {
  85. id: this.props.data.id,
  86. type:values.type,
  87. title: values.title,
  88. author: values.author,
  89. titleImg: thePictureUrl,
  90. content:this.state.edit,
  91. hot:values.hot,
  92. }
  93. }).done(function (data) {
  94. this.setState({
  95. loading: false
  96. });
  97. if (!data.error.length) {
  98. message.success('操作成功!');
  99. this.setState({
  100. visible: false
  101. });
  102. this.props.handOk();
  103. } else {
  104. message.warning(data.error[0].message);
  105. }
  106. }.bind(this));
  107. }
  108. });
  109. },
  110. cancelFun(){
  111. this.props.closeDesc();
  112. },
  113. componentWillMount() {
  114. if (this.props.data.id) {
  115. this.loadData(this.props.data.id);
  116. } else {
  117. this.state.visible=true;
  118. this.state.pictureUrl = [];
  119. };
  120. },
  121. componentWillReceiveProps(nextProps) {
  122. if (!this.props.visible && nextProps.visible) {
  123. this.state.textFileList = [];
  124. this.state.videoFileList = [];
  125. if (nextProps.data.id) {
  126. this.loadData(nextProps.data.id);
  127. } else {
  128. this.state.visible=true;
  129. this.state.data = {};
  130. };
  131. this.props.form.resetFields();
  132. };
  133. },
  134. render() {
  135. const theData = this.state.data || {};
  136. const { getFieldDecorator } = this.props.form;
  137. const FormItem = Form.Item
  138. const formItemLayout = {
  139. labelCol: { span: 6 },
  140. wrapperCol: { span: 12 },
  141. };
  142. return (
  143. <div className='login'>
  144. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  145. <Spin spinning={this.state.loading}>
  146. <div className="clearfix">
  147. <div>{this.props.data&&this.props.data.id?<div>
  148. <FormItem className="half-item" {...formItemLayout} label="编号">
  149. <span>{theData.biahao}</span>
  150. </FormItem>
  151. <FormItem className="half-item" {...formItemLayout} label="创建人">
  152. <span>{theData.biahao}</span>
  153. </FormItem>
  154. </div>:''}
  155. </div>
  156. <FormItem className="half-item" {...formItemLayout} label="标题">
  157. {getFieldDecorator('title', {
  158. rules: [ { required: true, message: '此项为必填项!' } ],
  159. initialValue: theData.title
  160. })(<Input placeholder="请输入消息标题" />)}
  161. </FormItem>
  162. </div>
  163. <div className="clearfix">
  164. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="消息内容">
  165. {getFieldDecorator('summary', {
  166. rules: [ { required: true, message: '此项为必填项!' } ],
  167. initialValue: theData.summary
  168. })(<Input type="textarea" rows={4} placeholder="输入内容" />)}
  169. </FormItem>
  170. </div>
  171. {this.props.data&&this.props.data.id?<div>
  172. <div className="clearfix">
  173. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="创建时间">
  174. <span>{theData.releaseStatus?'已推送':'未推送'}</span>
  175. </FormItem>
  176. </div>
  177. </div>:''}
  178. <div className="clearfix">
  179. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  180. <Button className="set-submit" type="primary" htmlType="submit">
  181. 保存
  182. </Button>
  183. <Button
  184. className="set-submit"
  185. type="ghost"
  186. onClick={(e) => {
  187. this.handleSubmit(e,2)
  188. }}
  189. >
  190. 推送
  191. </Button>
  192. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  193. 取消
  194. </Button>
  195. </FormItem>
  196. </div>
  197. </Spin>
  198. </Form>
  199. </div>
  200. )
  201. }
  202. }));
  203. export default NewDetailForm;