import { Input } from 'antd-mobile' import { SubFieldLabel } from '../common' import BasicField from '../Basic' import { FormControl } from '../../form' import type { IBuyerNickInputProps, BuyerNickInputValueType, FieldValueChangeType, TriggerEventPartFCType, FiledRenderPropsType } from '@/types' class BuyerNickInput extends BasicField { props: IBuyerNickInputProps constructor(props: IBuyerNickInputProps, form: FormControl) { super(props, form) this.props = props this.rules = this.getRules(props.componentConfig) } getRules(config: IBuyerNickInputProps['componentConfig']) { const rules = [] if (config.required) { rules.push({ required: true, validator: (_: any, value: BuyerNickInputValueType) => { if (!value.buyerNick) { return Promise.reject(new Error(`请输入${this.name}`)) } return Promise.resolve() } }) } return rules } render({ triggerEvent, isSubField = false, key, value, onChange }: FiledRenderPropsType< BuyerNickInputValueType, FieldValueChangeType> >) { const { replaceWarn, required } = this.props.componentConfig const handleTriggerEventPartFC: TriggerEventPartFCType = ( type, { value } ) => { const needReplaceWarn = type === 'REPEAT_CHECK' && replaceWarn needReplaceWarn && triggerEvent?.({ type, value, componentName: `buyerNick`, fieldData: this.props }) } return ( ) } } const FormElement = ({ readOnly, name, isSubField = false, required = false, onChange, triggerEventPartFC, value = { buyerNick: '', buyerOpenUid: '' } }: { required: boolean isSubField: boolean readOnly?: boolean name: string onChange?: FieldValueChangeType> triggerEventPartFC?: TriggerEventPartFCType value?: BuyerNickInputValueType }) => { const triggerValue = (changedValue: Partial) => { onChange?.(isSubField ? changedValue : { ...value, ...changedValue }) } const onBuyerNickChange = (value: string) => { triggerValue({ buyerNick: value }) } const onBuyerNickBlur = () => { triggerEventPartFC?.('REPEAT_CHECK', { value: value.buyerNick }) } return ( <> {isSubField && }
) } export default BuyerNickInput