messageForm.jsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. import SelectContent from './selectContent'
  11. import {getZiYuanType} from '@/tools'
  12. const NewDetailForm = Form.create()(React.createClass({
  13. getInitialState() {
  14. return {
  15. visible: false,
  16. loading: false,
  17. visibleSel:false,
  18. auditStatus: 0,
  19. textFileList: [],
  20. videoFileList: [],
  21. objData:[],
  22. objName:'',
  23. objId:''
  24. };
  25. },
  26. getPictureUrl(e) {
  27. this.setState({ pictureUrl: e });
  28. },
  29. handleSubmit(e,index) {
  30. e.preventDefault();
  31. if(this.props.data.id&&!this.state.objTitle){
  32. message.warning('请选择推送内容!');
  33. return;
  34. }
  35. this.props.form.validateFields((err, values) => {
  36. if (!err) {
  37. this.setState({
  38. loading: true
  39. });
  40. let hours =new Date(),
  41. year = hours.getFullYear(),
  42. month = (hours.getMonth()+1)<10?'0'+(hours.getMonth()+1):(hours.getMonth()+1),
  43. day = hours.getDate()<10?'0'+hours.getDate():hours.getDate(),
  44. hour=hours.getHours()<10?'0'+hours.getHours():hours.getHours(),
  45. mins = hours.getMinutes()<10?'0'+hours.getMinutes():hours.getMinutes(),
  46. sec = hours.getSeconds()<10?'0'+hours.getSeconds():hours.getSeconds();
  47. let times = year+'-'+month+'-'+day+' '+hour+':'+mins+':'+sec;
  48. $.ajax({
  49. method: "post",
  50. dataType: "json",
  51. async:true,
  52. url: this.props.data.id?globalConfig.context +"/api/admin/message/updMessageById":globalConfig.context +"/api/admin/message/createMyMessage",
  53. data: {
  54. subject:1,
  55. id: this.props.data.id,
  56. title: values.title,
  57. subject:1, //消息类别 0-系统消息
  58. isDraft:index=='1'?1:0, //是否草稿 0-否 1-是
  59. deleteSign:0, //删除标识 0-否 ,1-是
  60. isSend:index=='2'?1:0, //是否发送0-否 1-是
  61. body:values.body,
  62. messageCreateTime:!(this.props.data.id)?times:'null',
  63. resourceId:this.props.data.id?this.state.objData.rowId:'',
  64. resourceType:this.props.data.id?this.state.objData.fromTable>=0?this.state.objData.fromTable:getZiYuanType(this.state.objData.fromTable):'',
  65. resourceName:this.props.data.id?this.state.objTitle:''
  66. }
  67. }).done(function (data) {
  68. this.setState({
  69. loading: false
  70. });
  71. if (!data.error.length) {
  72. message.success('保存成功!');
  73. this.setState({
  74. visible: false
  75. });
  76. this.props.handOk();
  77. } else {
  78. message.warning(data.error[0].message);
  79. }
  80. }.bind(this));
  81. }
  82. });
  83. },
  84. cancelFun(){
  85. this.props.closeDesc(false,false);
  86. },
  87. componentWillMount() {
  88. if (this.props.data.id) {
  89. this.setState({
  90. objTitle:this.props.data.resourceName||'',
  91. objData:{fromTable:this.props.data.resourceType,rowId:this.props.data.rowId}
  92. })
  93. } else {
  94. this.state.visible=true;
  95. this.state.data = {};
  96. };
  97. },
  98. visFun(state,data){
  99. if(state){
  100. this.setState({
  101. visibleSel:false,
  102. objData:data,
  103. objTitle:data.title
  104. });
  105. }else{
  106. this.setState({
  107. visibleSel:false,
  108. })
  109. }
  110. },
  111. selContent(){
  112. this.setState({
  113. visibleSel:true
  114. })
  115. },
  116. componentWillReceiveProps(nextProps) {
  117. if (!this.props.visible && nextProps.visible) {
  118. this.state.textFileList = [];
  119. this.state.videoFileList = [];
  120. if (nextProps.data.id) {
  121. this.setState({
  122. objTitle:nextProps.data.resourceName,
  123. objData:{
  124. fromTable:this.props.data.resourceType,
  125. rowId:this.props.data.rowId,
  126. }
  127. })
  128. } else {
  129. this.state.visible=true;
  130. this.state.visibleSel=false
  131. this.state.data = {};
  132. };
  133. this.props.form.resetFields();
  134. };
  135. },
  136. render() {
  137. console.log(this.state.objData)
  138. const theData = this.props.data || {};
  139. const { getFieldDecorator } = this.props.form;
  140. const FormItem = Form.Item;
  141. const formItemLayout = {
  142. labelCol: { span: 6 },
  143. wrapperCol: { span: 12 },
  144. };
  145. return (
  146. <div className='login'>
  147. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,1)}} id="demand-form">
  148. <Spin spinning={this.state.loading}>
  149. <div className="clearfix">
  150. {this.props.data&&this.props.data.id?<div>
  151. <FormItem className="half-item" {...formItemLayout} label="创建人">
  152. <span>{theData.admin?theData.admin:'管理员'}</span>
  153. </FormItem>
  154. </div>:''}
  155. </div>
  156. <div className="clearfix">
  157. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 14 }} label="标题">
  158. {getFieldDecorator('title', {
  159. rules: [ { required: true, message: '此项为必填项!' } ],
  160. initialValue: theData.title
  161. })(<Input placeholder="请输入消息标题" />)}
  162. </FormItem>
  163. </div>
  164. <div className="clearfix">
  165. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="消息内容">
  166. {getFieldDecorator('body', {
  167. rules: [ { required: true, message: '此项为必填项!' } ],
  168. initialValue: theData.body
  169. })(<Input type="textarea" rows={4} placeholder="输入内容" />)}
  170. </FormItem>
  171. </div>
  172. {this.props.data&&this.props.data.id?<div className="clearfix">
  173. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label={<span><strong style={{color:'#f00'}}> * </strong>推送内容</span>}>
  174. <div>
  175. <span>{this.state.objTitle}</span>
  176. <Button
  177. onClick={this.selContent.bind(this)}
  178. type="primary"
  179. style={{marginLeft:10}}>选择</Button>
  180. </div>
  181. </FormItem>
  182. </div>:''}
  183. {this.props.data&&this.props.data.id?<div>
  184. <div className="clearfix">
  185. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="创建时间">
  186. <span>{theData.createTime}</span>
  187. </FormItem>
  188. </div>
  189. </div>:''}
  190. <div className="clearfix">
  191. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  192. <Button className="set-submit" type="primary" htmlType="submit">
  193. 保存
  194. </Button>
  195. {this.props.data&&this.props.data.id?<Button
  196. className="set-submit"
  197. style={{background: 'rgb(63, 207, 158)',border:'none',color:'#FFF'}}
  198. type="ghost"
  199. onClick={(e) => {
  200. this.handleSubmit(e,2)
  201. }}
  202. >
  203. 推送
  204. </Button>:''}
  205. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  206. 取消
  207. </Button>
  208. </FormItem>
  209. </div>
  210. </Spin>
  211. </Form>
  212. <SelectContent
  213. visible={this.state.visibleSel}
  214. visFun={this.visFun.bind(this)}
  215. />
  216. </div>
  217. )
  218. }
  219. }));
  220. export default NewDetailForm;