agreeButton.js 5.9 KB

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