messageForm.jsx 7.0 KB

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