messageForm.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. message,
  5. Spin,
  6. Input,
  7. Button,
  8. Form,
  9. } from 'antd';
  10. const NewDetailForm = Form.create()(React.createClass({
  11. getInitialState() {
  12. return {
  13. visible: false,
  14. loading: false,
  15. auditStatus: 0,
  16. textFileList: [],
  17. videoFileList: [],
  18. };
  19. },
  20. getPictureUrl(e) {
  21. this.setState({ pictureUrl: e });
  22. },
  23. handleSubmit(e,index) {
  24. e.preventDefault();
  25. this.props.form.validateFields((err, values) => {
  26. if (!err) {
  27. this.setState({
  28. loading: true
  29. });
  30. let hours =new Date(),
  31. year = hours.getFullYear(),
  32. month = (hours.getMonth()+1)<10?'0'+(hours.getMonth()+1):(hours.getMonth()+1),
  33. day = hours.getDate()<10?'0'+hours.getDate():hours.getDate(),
  34. hour=hours.getHours()<10?'0'+hours.getHours():hours.getHours(),
  35. mins = hours.getMinutes()<10?'0'+hours.getMinutes():hours.getMinutes(),
  36. sec = hours.getSeconds()<10?'0'+hours.getSeconds():hours.getSeconds();
  37. let times = year+'-'+month+'-'+day+' '+hour+':'+mins+':'+sec;
  38. $.ajax({
  39. method: "post",
  40. dataType: "json",
  41. async:true,
  42. url: this.props.data.id?globalConfig.context +"/api/admin/message/updMessageById":globalConfig.context +"/api/admin/message/createMyMessage",
  43. data: {
  44. id: this.props.data.id,
  45. title: values.title,
  46. subject:0, //消息类别 0-系统消息
  47. isDraft:index=='1'?1:0, //是否草稿 0-否 1-是
  48. deleteSign:0, //删除标识 0-否 ,1-是
  49. isSend:index=='2'?1:0, //是否发送0-否 1-是
  50. body:values.body,
  51. messageCreateTime:!(this.props.data.id)?times:'null'
  52. }
  53. }).done(function (data) {
  54. this.setState({
  55. loading: false
  56. });
  57. if (!data.error.length) {
  58. message.success('保存成功!');
  59. this.setState({
  60. visible: false
  61. });
  62. this.props.handOk();
  63. } else {
  64. message.warning(data.error[0].message);
  65. }
  66. }.bind(this));
  67. }
  68. });
  69. },
  70. cancelFun(){
  71. this.props.closeDesc(false,false);
  72. },
  73. componentWillMount() {
  74. if (this.props.data.id) {
  75. } else {
  76. this.state.visible=true;
  77. this.state.data = {};
  78. };
  79. },
  80. componentWillReceiveProps(nextProps) {
  81. if (!this.props.visible && nextProps.visible) {
  82. this.state.textFileList = [];
  83. this.state.videoFileList = [];
  84. if (nextProps.data.id) {
  85. } else {
  86. this.state.visible=true;
  87. this.state.data = {};
  88. };
  89. this.props.form.resetFields();
  90. };
  91. },
  92. render() {
  93. const theData = this.props.data || {};
  94. const { getFieldDecorator } = this.props.form;
  95. const FormItem = Form.Item;
  96. const formItemLayout = {
  97. labelCol: { span: 6 },
  98. wrapperCol: { span: 12 },
  99. };
  100. return (
  101. <div className='login'>
  102. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,1)}} id="demand-form">
  103. <Spin spinning={this.state.loading}>
  104. <div className="clearfix">
  105. {this.props.data&&this.props.data.id?<div>
  106. <FormItem className="half-item" {...formItemLayout} label="创建人">
  107. <span>{theData.admin?theData.admin:'管理员'}</span>
  108. </FormItem>
  109. </div>:''}
  110. </div>
  111. <div className="clearfix">
  112. <FormItem className="half-item" {...formItemLayout} label="标题">
  113. {getFieldDecorator('title', {
  114. rules: [ { required: true, message: '此项为必填项!' } ],
  115. initialValue: theData.title
  116. })(<Input placeholder="请输入消息标题" />)}
  117. </FormItem>
  118. </div>
  119. <div className="clearfix">
  120. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="消息内容">
  121. {getFieldDecorator('body', {
  122. rules: [ { required: true, message: '此项为必填项!' } ],
  123. initialValue: theData.body
  124. })(<Input type="textarea" rows={4} placeholder="输入内容" />)}
  125. </FormItem>
  126. </div>
  127. {this.props.data&&this.props.data.id?<div>
  128. <div className="clearfix">
  129. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="创建时间">
  130. <span>{theData.createTime}</span>
  131. </FormItem>
  132. </div>
  133. </div>:''}
  134. <div className="clearfix">
  135. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  136. <Button className="set-submit" type="primary" htmlType="submit">
  137. 保存
  138. </Button>
  139. {this.props.data&&this.props.data.id?<Button
  140. className="set-submit"
  141. style={{background: 'rgb(63, 207, 158)',border:'none',color:'#FFF'}}
  142. type="ghost"
  143. onClick={(e) => {
  144. this.handleSubmit(e,2)
  145. }}
  146. >
  147. 推送
  148. </Button>:''}
  149. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  150. 取消
  151. </Button>
  152. </FormItem>
  153. </div>
  154. </Spin>
  155. </Form>
  156. </div>
  157. )
  158. }
  159. }));
  160. export default NewDetailForm;