agreeButton.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import React, { Component } from "react";
  2. import { Modal, Button, Input, Form, message } from "antd";
  3. import $ from "jquery/src/ajax";
  4. class ReasonInput extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. visible: false,
  9. reason: ""
  10. };
  11. this.reset = this.reset.bind(this);
  12. this.judge = this.judge.bind(this);
  13. this.onOk = this.onOk.bind(this);
  14. this.sendRequest = this.sendRequest.bind(this);
  15. this.inputAjax = this.inputAjax.bind(this);
  16. }
  17. // 理由请求
  18. sendRequest(data, backData) {
  19. $.ajax({
  20. method: "post",
  21. dataType: "json",
  22. crossDomain: false,
  23. url: globalConfig.context + "/api/admin/orderChange/orderChangeAudit",
  24. data: {
  25. orderNo: backData.orderNo,
  26. remarks: this.state.reason,
  27. status: data.status,
  28. processState: this.props.processState,
  29. changeType: 0
  30. },
  31. success: function(data) {
  32. if (data.error.length || data.data.list == "") {
  33. if (data.error && data.error.length) {
  34. message.warning(data.error[0].message);
  35. }
  36. } else {
  37. message.success("操作成功!");
  38. this.props.visible();
  39. this.changeModal();
  40. }
  41. }.bind(this)
  42. }).done(
  43. function() {
  44. if (this.props.loadData) {
  45. this.props.loadData("2");
  46. }
  47. }.bind(this)
  48. );
  49. }
  50. // 输入框请求
  51. inputAjax(_data, backData) {
  52. $.ajax({
  53. method: "post",
  54. dataType: "json",
  55. crossDomain: false,
  56. url: globalConfig.context + "/api/admin/orderChange/updateOrderChange",
  57. data: backData,
  58. success: function(data) {
  59. if (data.error.length || data.data.list == "") {
  60. if (data.error && data.error.length) {
  61. message.warning(data.error[0].message);
  62. }
  63. } else {
  64. }
  65. }.bind(this)
  66. }).done(
  67. function() {
  68. this.sendRequest(this.props.data, backData);
  69. }.bind(this)
  70. );
  71. }
  72. reset() {
  73. this.setState({
  74. reason: ""
  75. });
  76. }
  77. changeModal() {
  78. this.setState(
  79. {
  80. visible: !this.state.visible
  81. },
  82. () => {
  83. this.reset();
  84. }
  85. );
  86. }
  87. judge() {
  88. if (!this.state.reason) {
  89. message.error("理由不能为空!");
  90. return false;
  91. }
  92. }
  93. onOk(data, backData) {
  94. if (!this.state.reason) {
  95. message.error("理由不能为空!");
  96. return false;
  97. }
  98. // 判断权限是否大于营销管理员
  99. if (
  100. this.props.processState <= 1 ||
  101. this.props.processState == 4 ||
  102. this.props.processState >= 6
  103. ) {
  104. this.sendRequest(data, backData);
  105. } else {
  106. this.inputAjax(data, backData);
  107. }
  108. data.onChange(this.state.reason);
  109. }
  110. render() {
  111. const { visible } = this.state;
  112. const data = this.props.data;
  113. const backData = this.props.backData;
  114. const ajaxData = this.props.ajaxData;
  115. Object.assign(backData, ajaxData);
  116. return (
  117. <div style={{ display: "inline-block" }}>
  118. <Button
  119. type={data.type}
  120. onClick={() => {
  121. this.changeModal();
  122. }}
  123. >
  124. {data.name}
  125. </Button>
  126. <Modal
  127. maskClosable={false}
  128. title={data.title}
  129. visible={visible}
  130. onCancel={() => {
  131. this.changeModal();
  132. }}
  133. onOk={_e => {
  134. this.onOk(data, backData);
  135. }}
  136. >
  137. <Form.Item>
  138. <Input.TextArea
  139. rows={4}
  140. placeholder={data.placeholder}
  141. value={this.state.reason}
  142. onChange={e => {
  143. this.setState({
  144. reason: e.target.value
  145. });
  146. }}
  147. />
  148. </Form.Item>
  149. </Modal>
  150. </div>
  151. );
  152. }
  153. }
  154. const AgreeButton = Form.create()(ReasonInput);
  155. export default AgreeButton;