import React, { useCallback, useState } from 'react' import { View, Text, Input } from '@tarojs/components' import { Checkbox } from '@nutui/nutui-react-taro' import styles from './index.module.scss' interface FormSwitchProps { value: boolean onChange: (checked: boolean) => void subTitle: string wechatId?: string } const FormSwitch: React.FC = ({ value, onChange, subTitle, wechatId }) => { const [editWechat, setEditWechat] = useState(false) const [wechatIdValue, setWechatIdValue] = useState('') const [wechat, setWechat] = useState(wechatId) const editWechatId = () => { setEditWechat(true) } const setWechatId = useCallback((e: any) => { const value = e.target.value onChange && onChange(value) setWechatIdValue(value) }, [onChange]) const fillWithPhone = () => { if (wechat) { setWechatIdValue(wechat) } } return ( <> {subTitle} { !editWechat && wechatId && ( 微信号: {wechatId.replace(/(\d{3})(\d{4})(\d{4})/, '$1 $2 $3')} 修改 ) } { editWechat && ( 手机号填入:{wechat} ) } ) } export default FormSwitch