messageForm.jsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. subject:0,
  45. id: this.props.data.id,
  46. title: values.title,
  47. subject:0, //消息类别 0-系统消息
  48. isDraft:index=='1'?1:0, //是否草稿 0-否 1-是
  49. deleteSign:0, //删除标识 0-否 ,1-是
  50. isSend:index=='2'?1:0, //是否发送0-否 1-是
  51. body:values.body,
  52. messageCreateTime:!(this.props.data.id)?times:'null'
  53. }
  54. }).done(function (data) {
  55. this.setState({
  56. loading: false
  57. });
  58. if (!data.error.length) {
  59. message.success('保存成功!');
  60. this.setState({
  61. visible: false
  62. });
  63. this.props.handOk();
  64. } else {
  65. message.warning(data.error[0].message);
  66. }
  67. }.bind(this));
  68. }
  69. });
  70. },
  71. cancelFun(){
  72. this.props.closeDesc(false,false);
  73. },
  74. componentWillMount() {
  75. if (this.props.data.id) {
  76. } else {
  77. this.state.visible=true;
  78. this.state.data = {};
  79. };
  80. },
  81. componentWillReceiveProps(nextProps) {
  82. if (!this.props.visible && nextProps.visible) {
  83. this.state.textFileList = [];
  84. this.state.videoFileList = [];
  85. if (nextProps.data.id) {
  86. } else {
  87. this.state.visible=true;
  88. this.state.data = {};
  89. };
  90. this.props.form.resetFields();
  91. };
  92. },
  93. render() {
  94. const theData = this.props.data || {};
  95. const { getFieldDecorator } = this.props.form;
  96. const FormItem = Form.Item;
  97. const formItemLayout = {
  98. labelCol: { span: 6 },
  99. wrapperCol: { span: 12 },
  100. };
  101. return (
  102. <div className='login'>
  103. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,1)}} id="demand-form">
  104. <Spin spinning={this.state.loading}>
  105. <div className="clearfix">
  106. <FormItem className="half-item" {...formItemLayout} label="推送类型">
  107. <span>app站内消息</span>
  108. </FormItem>
  109. {this.props.data&&this.props.data.id?<div>
  110. <FormItem className="half-item" {...formItemLayout} label="创建人">
  111. <span>{theData.admin?theData.admin:'管理员'}</span>
  112. </FormItem>
  113. </div>:''}
  114. </div>
  115. <div className="clearfix">
  116. <FormItem className="half-item" {...formItemLayout} label="标题">
  117. {getFieldDecorator('title', {
  118. rules: [ { required: true, message: '此项为必填项!' } ],
  119. initialValue: theData.title
  120. })(<Input placeholder="请输入消息标题" />)}
  121. </FormItem>
  122. </div>
  123. <div className="clearfix">
  124. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="消息内容">
  125. {getFieldDecorator('body', {
  126. rules: [ { required: true, message: '此项为必填项!' } ],
  127. initialValue: theData.body
  128. })(<Input type="textarea" rows={4} placeholder="输入内容" />)}
  129. </FormItem>
  130. </div>
  131. {this.props.data&&this.props.data.id?<div>
  132. <div className="clearfix">
  133. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="创建时间">
  134. <span>{theData.createTime}</span>
  135. </FormItem>
  136. </div>
  137. </div>:''}
  138. <div className="clearfix">
  139. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  140. <Button className="set-submit" type="primary" htmlType="submit">
  141. 保存
  142. </Button>
  143. {this.props.data&&this.props.data.id?<Button
  144. className="set-submit"
  145. style={{background: 'rgb(63, 207, 158)',border:'none',color:'#FFF'}}
  146. type="ghost"
  147. onClick={(e) => {
  148. this.handleSubmit(e,2)
  149. }}
  150. >
  151. 推送
  152. </Button>:''}
  153. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  154. 取消
  155. </Button>
  156. </FormItem>
  157. </div>
  158. </Spin>
  159. </Form>
  160. </div>
  161. )
  162. }
  163. }));
  164. export default NewDetailForm;