agreeButton.js 6.0 KB

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