No Description

index.tsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React from "react";
  2. import { Popover } from "antd";
  3. import { PopoverProps } from "antd/lib/popover";
  4. import WantedPublishView from "../WantedPublishView";
  5. import popClose from "../assets/icon/close@2x.png";
  6. import styles from "./WantedPublishPopover.less";
  7. import {
  8. WatnedPublishBase,
  9. WatnedPublishBaseP
  10. } from "@components/Payment/BaseClassComponents/WantedPublish";
  11. export interface WantedPublishPopoverProp extends WatnedPublishBaseP {
  12. popoverConfig?: PopoverProps;
  13. }
  14. export interface WantedPublishPopoverState {
  15. visible: boolean;
  16. current_wanted: number | string | null;
  17. }
  18. export class WantedPublishPopover extends WatnedPublishBase<
  19. WantedPublishPopoverProp,
  20. WantedPublishPopoverState
  21. > {
  22. constructor(props: WantedPublishPopoverProp) {
  23. super(props);
  24. this.state = {
  25. visible: false,
  26. current_wanted: null
  27. };
  28. }
  29. handleConfirmButton = (containerRef?: React.RefObject<any>) => {
  30. const { handleConfirm } = this.props;
  31. if (handleConfirm) {
  32. const value = this.formatCurrentWanted(this.state.current_wanted);
  33. handleConfirm(this.formatResult(value), containerRef);
  34. }
  35. this.setState({ visible: false });
  36. };
  37. renderInitView() {
  38. const { current_wanted } = this.state;
  39. return (
  40. <WantedPublishView
  41. type="pop"
  42. current_wanted={current_wanted}
  43. InputWantedValueChange={(v: string) =>
  44. this.setState({ current_wanted: v })
  45. }
  46. InputWantedPressEnter={(v: string) => {
  47. const value = this.formatCurrentWanted(v);
  48. if (this.props.handleConfirm)
  49. this.props.handleConfirm(this.formatResult(value));
  50. this.setState({ current_wanted: value, visible: false });
  51. }}
  52. InputWantedOnBlur={(v: string) => {
  53. const value = this.formatCurrentWanted(v);
  54. this.setState({ current_wanted: value });
  55. }}
  56. InputWantedClear={() => {
  57. this.setState(
  58. {
  59. current_wanted: null
  60. },
  61. () => {
  62. if (this.props.handleConfirm) this.props.handleConfirm(null);
  63. this.setState({ visible: false });
  64. }
  65. );
  66. }}
  67. InputWantedConfirm={this.handleConfirmButton}
  68. {...this.props.viewConfig}
  69. />
  70. );
  71. }
  72. render() {
  73. const { children, popoverConfig = {}, currentWanted } = this.props;
  74. return (
  75. <Popover
  76. placement="left"
  77. trigger="click"
  78. visible={this.state.visible}
  79. onVisibleChange={(value: boolean) => {
  80. if (value && currentWanted) {
  81. this.setState({ current_wanted: +currentWanted });
  82. }
  83. this.setState({ visible: value });
  84. }}
  85. {...popoverConfig}
  86. content={
  87. <div className={styles.wantedWrapper}>
  88. <div role="button" tabIndex={1} className={styles.closeBtnWrapper}>
  89. <div
  90. className={styles.closeBtn}
  91. onClick={() => {
  92. this.setState({ visible: false });
  93. }}
  94. >
  95. <img src={popClose} alt="close wanted button" />
  96. </div>
  97. </div>
  98. {this.renderInitView()}
  99. </div>
  100. }
  101. >
  102. {children}
  103. </Popover>
  104. );
  105. }
  106. }
  107. export default WantedPublishPopover;