No Description

index.tsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import React, { Component } from "react";
  2. import Modal, { ModalProps } from "../../Common/Modal";
  3. import WantedPublishView from "../WantedPublishView";
  4. import styles from "./WantedPublishModal.less";
  5. interface WantedPublishModalProps {
  6. modalConfig?: ModalProps;
  7. handleConfirm?: Function;
  8. }
  9. interface WantedPublishModalState {
  10. modalVisible: boolean;
  11. current_wanted: number | string | null;
  12. }
  13. export class WantedPublishModal extends Component<
  14. WantedPublishModalProps,
  15. WantedPublishModalState
  16. > {
  17. constructor(props: WantedPublishModalProps) {
  18. super(props);
  19. this.state = {
  20. modalVisible: false,
  21. current_wanted: null
  22. };
  23. }
  24. handleModalShow = () => {};
  25. handleClose = () => {
  26. const { handleConfirm } = this.props;
  27. if (handleConfirm) {
  28. this.handleUpdateCurrentWanted(
  29. this.state.current_wanted,
  30. (value: string) => {
  31. handleConfirm(Number(value).toFixed(2));
  32. }
  33. );
  34. }
  35. this.setState({ modalVisible: false });
  36. };
  37. handleUpdateCurrentWanted = (
  38. value: string | number | null,
  39. afterUpdate?: Function
  40. ) => {
  41. if (!value) return;
  42. let result: string | number;
  43. result = value;
  44. if (parseInt(`${value}`, 10) === value) {
  45. // 无小数判断
  46. result = Number(value);
  47. }
  48. if (!result) return;
  49. if (result > 10000) result = 10000;
  50. if (result < 5) result = 5;
  51. this.setState(
  52. { current_wanted: result },
  53. () => afterUpdate && afterUpdate(result)
  54. );
  55. };
  56. clearCurrentWanted = (cb: Function) => {
  57. this.setState(
  58. {
  59. current_wanted: null
  60. },
  61. () => cb()
  62. );
  63. };
  64. renderMain() {
  65. const { current_wanted } = this.state;
  66. return (
  67. <WantedPublishView
  68. wrapperClass={styles.modalBg}
  69. current_wanted={current_wanted}
  70. InputWantedValueChange={(v: string) =>
  71. this.setState({ current_wanted: v })
  72. }
  73. InputWantedPressEnter={(v: string) =>
  74. this.handleUpdateCurrentWanted(v, this.handleClose)
  75. }
  76. InputWantedOnBlur={(v: string) => this.handleUpdateCurrentWanted(v)}
  77. InputWantedClear={() => this.clearCurrentWanted(this.handleClose)}
  78. CloseFunction={this.handleClose}
  79. />
  80. );
  81. }
  82. render() {
  83. return (
  84. <>
  85. <div onClick={() => this.setState({ modalVisible: true })}>
  86. {this.props.children}
  87. </div>
  88. <Modal visible={this.state.modalVisible} onCancel={this.handleClose} {...this.props.modalConfig}>
  89. {this.renderMain()}
  90. </Modal>
  91. </>
  92. );
  93. }
  94. }
  95. export default WantedPublishModal;