Няма описание

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { Component, Ref } from "react";
  2. import Modal, { ModalProps } from "../../Common/Modal";
  3. import WantedPublishView from "../WantedPublishView";
  4. import styles from "./WantedPublishModal.less";
  5. import {
  6. WatnedPublishBase,
  7. WatnedPublishBaseP
  8. } from "@components/Payment/BaseClassComponents/WantedPublish";
  9. interface WantedPublishModalProps extends WatnedPublishBaseP {
  10. modalConfig?: ModalProps;
  11. }
  12. interface WantedPublishModalState {
  13. modalVisible: boolean;
  14. current_wanted: number | string | null;
  15. }
  16. export class WantedPublishModal extends WatnedPublishBase<
  17. WantedPublishModalProps,
  18. WantedPublishModalState
  19. > {
  20. constructor(props: WantedPublishModalProps) {
  21. super(props);
  22. this.state = {
  23. modalVisible: false,
  24. current_wanted: null
  25. };
  26. }
  27. handleConfirmButton = (containerRef?: React.RefObject<any>) => {
  28. const { handleConfirm } = this.props;
  29. if (handleConfirm) {
  30. const value = this.formatCurrentWanted(this.state.current_wanted);
  31. handleConfirm(value ? Number(value).toFixed(2) : value);
  32. }
  33. this.setState({ modalVisible: false });
  34. };
  35. renderMain() {
  36. const { current_wanted } = this.state;
  37. return (
  38. <WantedPublishView
  39. wrapperClass={styles.modalBg}
  40. current_wanted={current_wanted}
  41. InputWantedValueChange={(v: string) =>
  42. this.setState({ current_wanted: v })
  43. }
  44. InputWantedPressEnter={(v: string) => {
  45. const value = this.formatCurrentWanted(v);
  46. if (this.props.handleConfirm)
  47. this.props.handleConfirm(this.formatResult(value));
  48. this.setState({ current_wanted: value, modalVisible: false });
  49. }}
  50. InputWantedOnBlur={(v: string) => {
  51. const value = this.formatCurrentWanted(v);
  52. this.setState({ current_wanted: value });
  53. }}
  54. InputWantedClear={() => {
  55. this.setState(
  56. {
  57. current_wanted: null
  58. },
  59. () => {
  60. if (this.props.handleConfirm) this.props.handleConfirm(null);
  61. this.setState({ modalVisible: false });
  62. }
  63. );
  64. }}
  65. InputWantedConfirm={this.handleConfirmButton}
  66. {...this.props.viewConfig}
  67. />
  68. );
  69. }
  70. render() {
  71. return (
  72. <>
  73. <div onClick={() => this.setState({ modalVisible: true })}>
  74. {this.props.children}
  75. </div>
  76. <Modal
  77. visible={this.state.modalVisible}
  78. onCancel={() => {
  79. this.setState({ modalVisible: false });
  80. }}
  81. {...this.props.modalConfig}
  82. >
  83. {this.renderMain()}
  84. </Modal>
  85. </>
  86. );
  87. }
  88. }
  89. export default WantedPublishModal;