import React from "react"; import { Popover } from "antd"; import { PopoverProps } from "antd/lib/popover"; import WantedPublishView from "../WantedPublishView"; import popClose from "../assets/icon/close@2x.png"; import styles from "./WantedPublishPopover.less"; export interface WantedPublishPopoverProp { popoverConfig?: PopoverProps; handleConfirm?: Function; } export interface WantedPublishPopoverState { visible: boolean; current_wanted: number | string | null; } export class WantedPublishPopover extends React.Component< WantedPublishPopoverProp, WantedPublishPopoverState > { constructor(props: WantedPublishPopoverProp) { super(props); this.state = { visible: false, current_wanted: null }; } handleClose = () => { const { handleConfirm } = this.props; if (handleConfirm) { this.handleUpdateCurrentWanted( this.state.current_wanted, (value: string) => { handleConfirm(Number(value).toFixed(2)); } ); } this.setState({ visible: false }); }; clearCurrentWanted = (cb: Function) => { this.setState( { current_wanted: null }, () => cb() ); }; handleUpdateCurrentWanted = ( value: string | number | null, afterUpdate?: Function ) => { if (!value) return; let result: string | number; result = value; if (parseInt(`${value}`, 10) === value) { // 无小数判断 result = Number(value); } if (!result) return; if (result > 10000) result = 10000; if (result < 5) result = 5; this.setState( { current_wanted: result }, () => afterUpdate && afterUpdate(result) ); }; renderInitView() { const { current_wanted } = this.state; return ( this.setState({ current_wanted: v }) } InputWantedPressEnter={(v: string) => this.handleUpdateCurrentWanted(v, this.handleClose) } InputWantedOnBlur={(v: string) => this.handleUpdateCurrentWanted(v)} InputWantedClear={() => this.clearCurrentWanted(this.handleClose)} CloseFunction={this.handleClose} /> ); } render() { const { children, popoverConfig = {} } = this.props; return ( { if (!value) { this.handleClose(); } this.setState({ visible: value }); }} {...popoverConfig} content={
close wanted button
{this.renderInitView()}
} > {children}
); } } export default WantedPublishPopover;