agreeButton.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import React, { Component } from "react";
  2. import { Modal, Button, Input, Form, message } from "antd";
  3. import $ from "jquery/src/ajax";
  4. import { moneyVerify } from "@/tools.js";
  5. class ReasonInput extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. visible: false,
  10. reason: this.props.reason,
  11. flag: false,
  12. flagS: false,
  13. };
  14. this.reset = this.reset.bind(this);
  15. this.judge = this.judge.bind(this);
  16. this.onOk = this.onOk.bind(this);
  17. this.sendRequest = this.sendRequest.bind(this);
  18. this.inputAjax = this.inputAjax.bind(this);
  19. }
  20. componentWillMount() {
  21. let reason = this.props.reason
  22. this.setState({
  23. reason
  24. })
  25. // const data = this.props.data;
  26. // const backData = this.props.backData;
  27. // const ajaxData = this.props.ajaxData;
  28. // Object.assign(backData, ajaxData);
  29. // // this.sendRequest()
  30. // this.onOk(data,backData)
  31. // console.log("222222",this.props);
  32. }
  33. // 理由请求
  34. sendRequest(data, backData) {
  35. if(this.state.flagS) return
  36. $.ajax({
  37. method: "post",
  38. dataType: "json",
  39. crossDomain: false,
  40. url: globalConfig.context + "/api/admin/orderChange/orderChangeAudit",
  41. data: {
  42. orderNo: backData.orderNo,
  43. remarks: this.props.reason,
  44. status: data.status,
  45. processState: this.props.processState,
  46. // 驳回位置
  47. rejectState: this.props.rejectState
  48. },
  49. success: function(data) {
  50. if (data.error.length || data.data.list == "") {
  51. if (data.error && data.error.length) {
  52. if (!this.state.flag) return;
  53. message.warning(data.error[0].message);
  54. return
  55. }
  56. } else {
  57. this.setState({
  58. flagS: !this.state.flagS
  59. })
  60. message.success("操作成功!");
  61. this.props.visible();
  62. this.changeModal();
  63. this.props.onCancel();
  64. // window.location.reload()
  65. }
  66. }.bind(this)
  67. }).done(
  68. function() {
  69. if (this.props.loadData) {
  70. this.props.loadData("2");
  71. }
  72. }.bind(this)
  73. );
  74. }
  75. // 输入框请求
  76. inputAjax(_data, backData) {
  77. if (this.state.flag) return;
  78. $.ajax({
  79. method: "post",
  80. dataType: "json",
  81. crossDomain: false,
  82. url: globalConfig.context + "/api/admin/orderChange/updateOrderChange",
  83. data: backData,
  84. success: function(data) {
  85. if (data.error.length || data.data.list == "") {
  86. if (data.error && data.error.length) {
  87. if (!this.state.flag) return;
  88. message.warning(data.error[0].message);
  89. return
  90. }
  91. } else {
  92. this.setState({
  93. flag: !this.state.flag
  94. });
  95. }
  96. }.bind(this)
  97. }).done(
  98. function() {
  99. this.sendRequest(this.props.data, backData);
  100. }.bind(this)
  101. );
  102. }
  103. reset() {
  104. this.setState({
  105. reason: this.props.reason
  106. });
  107. }
  108. changeModal() {
  109. this.setState(
  110. {
  111. visible: !this.state.visible
  112. },
  113. () => {
  114. this.reset();
  115. }
  116. );
  117. const data = this.props.data;
  118. const backData = this.props.backData;
  119. backData.consultantExamine = []
  120. backData.managerExamine = []
  121. const ajaxData = this.props.ajaxData;
  122. if(ajaxData.ContactsLists) {
  123. ajaxData.ContactsLists = [];
  124. ajaxData.contactList = [];
  125. }
  126. Object.assign(backData, ajaxData);
  127. // this.sendRequest()
  128. this.onOk(data,backData)
  129. // this.setState({reason: this.props.reason})
  130. // console.log(this.props,this.state)
  131. }
  132. judge() {
  133. if (!this.props.reason) {
  134. message.error("理由不能为空!");
  135. return false;
  136. }
  137. }
  138. onOk(data, backData) {
  139. if (!this.props.reason) {
  140. message.error("理由不能为空!");
  141. return false;
  142. }
  143. if( this.props.data.status == 2 && this.props.processState == 5) {
  144. if (
  145. moneyVerify(this.props.ajaxData.cwCost) ||
  146. moneyVerify(this.props.ajaxData.refundableAmount)
  147. ) {
  148. return;
  149. }
  150. }
  151. if (
  152. this.props.processState <= 1 ||
  153. this.props.processState == 4 ||
  154. this.props.processState >= 6
  155. ) {
  156. // 判断权限是否大于营销管理员
  157. this.sendRequest(data, backData);
  158. } else {
  159. this.inputAjax(data, backData);
  160. }
  161. data.onChange(this.state.reason);
  162. }
  163. render() {
  164. const { visible } = this.state;
  165. const data = this.props.data;
  166. const backData = this.props.backData;
  167. const ajaxData = this.props.ajaxData;
  168. Object.assign(backData, ajaxData);
  169. return (
  170. <div style={{ display: "inline-block" }}>
  171. <Button
  172. type={data.type}
  173. onClick={() => {
  174. this.changeModal();
  175. }}
  176. >
  177. {data.name}
  178. </Button>
  179. <Modal
  180. maskClosable={false}
  181. title={data.title}
  182. visible={false}
  183. onCancel={() => {
  184. this.changeModal();
  185. }}
  186. onOk={_e => {
  187. this.onOk(data, backData);
  188. }}
  189. >
  190. <Form.Item>
  191. <Input.TextArea
  192. rows={4}
  193. placeholder={data.placeholder}
  194. value={this.state.reason}
  195. onChange={e => {
  196. // console.log(this.props);
  197. this.setState({
  198. reason: e.target.value
  199. });
  200. }}
  201. />
  202. </Form.Item>
  203. </Modal>
  204. </div>
  205. );
  206. }
  207. }
  208. const AgreeButton = Form.create()(ReasonInput);
  209. export default AgreeButton;