messageForm.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. textFileList: [],
  16. videoFileList: [],
  17. };
  18. },
  19. handleSubmit(e,index) {
  20. e.preventDefault();
  21. this.props.form.validateFields((err, values) => {
  22. if (!err) {
  23. this.setState({
  24. loading: true
  25. });
  26. $.ajax({
  27. method: "get",
  28. dataType: "json",
  29. url: globalConfig.context +"/api/admin/message/mobileMessage",
  30. data: {
  31. messageCode: values.messageCode,
  32. }
  33. }).done(function (data) {
  34. this.setState({
  35. loading: false
  36. });
  37. if (!data.error.length) {
  38. message.success('推送成功!');
  39. this.setState({
  40. visible: false
  41. });
  42. this.props.handOk();
  43. } else {
  44. message.warning(data.error[0].message);
  45. }
  46. }.bind(this));
  47. }
  48. });
  49. },
  50. cancelFun(){
  51. this.props.closeDesc(false,false);
  52. },
  53. componentWillMount() {
  54. if (this.props.data.id) {
  55. } else {
  56. this.state.visible=true;
  57. this.state.data = {};
  58. };
  59. },
  60. componentWillReceiveProps(nextProps) {
  61. if (!this.props.visible && nextProps.visible) {
  62. this.state.textFileList = [];
  63. this.state.videoFileList = [];
  64. if (nextProps.data.id) {
  65. } else {
  66. this.state.visible=true;
  67. this.state.data = {};
  68. };
  69. this.props.form.resetFields();
  70. };
  71. },
  72. render() {
  73. const theData = this.props.data || {};
  74. const { getFieldDecorator } = this.props.form;
  75. const FormItem = Form.Item;
  76. const formItemLayout = {
  77. labelCol: { span: 6 },
  78. wrapperCol: { span: 12 },
  79. };
  80. return (
  81. <div className='login'>
  82. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,1)}} id="demand-form">
  83. <Spin spinning={this.state.loading}>
  84. <div className="clearfix">
  85. <FormItem {...formItemLayout} label="发送对象">
  86. <span>所有用户</span>
  87. </FormItem>
  88. </div>
  89. <div>
  90. <FormItem {...formItemLayout} label="创建人">
  91. <span>{theData.admin?theData.admin:'管理员'}</span>
  92. </FormItem>
  93. </div>
  94. <div className="clearfix">
  95. <FormItem {...formItemLayout} label="短信模板">
  96. {getFieldDecorator('messageCode', {
  97. rules: [ { required: true, message: '此项为必填项!' } ],
  98. initialValue: theData.messageCode
  99. })(<Input placeholder="请输入短信模板" />)}
  100. </FormItem>
  101. </div>
  102. <div className="clearfix">
  103. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  104. <Button className="set-submit" type="primary" htmlType="submit">
  105. 推送
  106. </Button>
  107. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  108. 取消
  109. </Button>
  110. </FormItem>
  111. </div>
  112. </Spin>
  113. </Form>
  114. </div>
  115. )
  116. }
  117. }));
  118. export default NewDetailForm;