import React from "react"; import { Col, Form, Modal, Radio, Row, Select } from "kts-xui"; import { DefaultOptionType } from "kts-components-antd-x4/lib/select"; import './index.less'; export interface IFormValues { /** 开票种类 */ billingType: 'digital' | 'taxation'; /** 特定业务 */ business?: any; /** 选择票类 */ invoiceType?: any; } export interface IInvoiceTypeModalProps { /** 是否禁用 */ isDisabled?: boolean; /** 窗口标题 */ modalTitle?: string; /** 是否开启 */ open?: boolean; /** 点击了确认 */ onOk?: (values: IFormValues) => void; /** 点击了取消 */ onCancel?: () => void; /** 切换了 开票种类 */ onChange?: (e: 'digital' | 'taxation') => void; /** 切换了 发票类型 */ onInvoiceTypeChange?: (e: any) => void; /** 禁用列表 */ disableds?: ('billingType' | 'invoiceType' | 'business')[]; /** 选择票类 选项 */ invoiceTypeOptions?: DefaultOptionType[]; /** 特定业务 选项 */ businessOptions?: DefaultOptionType[]; /** 票类默认值 */ defaultInvoiceType?: any; /** 特定业务默认值 */ defaultBusiness?: any; /** 开票种类 默认值 */ defaultBillingType?: 'digital' | 'taxation'; } export default function InvoiceTypeModal(props: IInvoiceTypeModalProps) { const { disableds = [] } = props; const [formValues, setValues] = React.useState({ billingType: props.defaultBillingType || 'digital' }); const [form] = Form.useForm(); const onConfirm = React.useCallback(async () => { const values = await form.validateFields(); props.onOk && props.onOk(values); }, [props.onOk, form]) const onChangeBillingType = React.useCallback(e => { props.onChange && props.onChange(e.target.value); form.setFieldsValue({ invoiceType: null, business: null }); setValues(form.getFieldsValue()); }, [props.onChange, form]) const onInvoiceTypeChange = React.useCallback(value => { props.onInvoiceTypeChange && props.onInvoiceTypeChange(value); form.setFieldsValue({ business: null }); setValues(form.getFieldsValue()); }, [props.onInvoiceTypeChange, form]) React.useEffect(() => { if (props.open) { const values = { billingType: props.defaultBillingType || 'digital', invoiceType: props.defaultInvoiceType, business: props.defaultBusiness, } form.resetFields(); form.setFieldsValue(values); setValues(values); } }, [props.open, props.defaultBillingType, props.defaultBusiness, props.defaultInvoiceType, form]) return (
{ setValues(e) }} > = 0} onChange={onChangeBillingType} options={[ { label: '数电发票', value: 'digital' }, { label: '税控发票', value: 'taxation' }, ]} /> = 0 || !formValues.invoiceType} options={props.businessOptions} />
) }