import React from "react"; import { Button, Card, FormInstance, Popconfirm, Popover, Space, Tooltip, } from "antd"; import { CloseOutlined } from "@ant-design/icons"; import { DtmplData, FieldGroupConfig } from "../../tmpl/interface"; import FieldGroupForm from "../../form/field-group-form"; import { ButtonType } from "antd/es/button"; import { LocaleContext } from "../../locale/LocaleProvider"; interface RowEditCardProps { serverKey?: string; height?: any; onCancel?: () => void; onOk: (value: DtmplData, hidden: boolean) => void; fieldGroupConfig: FieldGroupConfig; dtmplData?: DtmplData; okButtonType?: ButtonType; okDanger?: boolean; needConfirm?: boolean; } interface RowEditCardState { isAdded?: boolean; } export default class PopoverEditCard extends React.PureComponent< RowEditCardProps, RowEditCardState > { formRef = React.createRef(); static defaultProps = { forceRender: true, style: { maxWidth: "calc(100vw - 60px)", maxHeight: "calc(100vh - 50px)" }, needConfirm: false, okButtonType: "primary", okDanger: false, }; state = { isAdded: false, }; static contextType = LocaleContext; context: React.ContextType; async componentDidMount() { } async componentDidUpdate() { //this.reset(); } reset = () => { // if (this.formRef.current) { // this.formRef.current.resetFields(); // } }; onOk = () => { this.setState({ isAdded: false }); this.formRef.current.submit(); }; add = () => { this.setState({ isAdded: true }); this.formRef.current.submit(); }; getTitle = () => { const { fieldGroupConfig, dtmplData } = this.props; const { translate } = this.context; let title = ""; title = fieldGroupConfig.title; if (dtmplData) { title = title + translate("[${行编辑}]"); } else { title = title + translate("[${新建一行}]"); } return title; }; render() { const { height, onOk, fieldGroupConfig, dtmplData, onCancel, okButtonType, needConfirm, okDanger, serverKey, } = this.props; const { isAdded } = this.state; const { translate } = this.context; function okButton(onOk) { return needConfirm ? ( okDanger ? ( ) : ( ) ) : ( ); } return ( {/**/} {okButton(this.onOk)} {onCancel ? ( ) : ( "" )} } > onOk(value, !isAdded)} dtmplData={dtmplData} /> ); } }