import { BaseEventOrig, InputProps } from '@tarojs/components'; import { forwardRef, useCallback, useImperativeHandle, useState } from 'react'; import BlFormInput from '@/components/bl-form-input'; import BlFormItem from '@/components/bl-form-item'; import { BlFormRadio, BlFormRadioGroup } from '@/components/bl-form-radio'; import BlFormSelect from '@/components/bl-form-select'; import { WORK_YEAR_OPTIONS, WorkedYears } from '@/constants/material'; import { MaterialProfile } from '@/types/material'; import { logWithPrefix, string2Number } from '@/utils/common'; import './index.less'; interface IProps { profile: Partial; } const PREFIX = 'fragment-profile-experience'; const log = logWithPrefix(PREFIX); // const STYLE_VALUES = Object.values(StyleType).filter(v => typeof v === 'number'); // const calcInitStyle = (styleString: string = '') => { // const styles = styleString.split('、'); // return styles.filter(v => STYLE_VALUES.includes(Number(v))).map(v => Number(v)); // }; // const getStyleString = (styles: StyleType[]) => { // return styles.join('、'); // }; const calcInitMaxGmv = (maxGmv: number) => { if (!maxGmv) { return ''; } return maxGmv / 10000; }; const getMaxGmv = (maxGmv: number) => { if (Number.isNaN(maxGmv)) { return 0; } return maxGmv * 10000; }; function ProfileExperienceFragment(props: IProps, ref) { const { profile } = props; const [workedYear, setWorkedYear] = useState(profile.workedYear); const [workedAccounts, setWorkedAccounts] = useState(profile.workedAccounts || ''); const [newAccountExperience, setNewAccountExperience] = useState(profile.newAccountExperience); // const [style, setStyle] = useState(calcInitStyle(profile.style)); const [maxGmv, setMaxGmv] = useState(calcInitMaxGmv(profile?.maxGmv || 0)); // const [maxOnline, setMaxOnline] = useState(profile.maxOnline || ''); const handleSelectWorkYear = useCallback((newYear: WorkedYears) => { setWorkedYear(newYear); }, []); const handleInputWorkedAccounts = useCallback((e: BaseEventOrig) => { const value = e.detail.value || ''; setWorkedAccounts(value); }, []); const handleNewAccountExperienceChange = useCallback((value: number) => { log('handleNewAccountExperienceChange', value); setNewAccountExperience(value); }, []); // const handleStyleChange = useCallback((value: StyleType[]) => { // log('handleStyleChange', value); // setStyle(value); // }, []); const handleInputMaxGmv = useCallback((e: BaseEventOrig) => { const value = e.detail.value || ''; if (Number.isNaN(Number(value))) { return; } setMaxGmv(string2Number(value)); }, []); // // const handleInputMaxOnline = useCallback((e: BaseEventOrig) => { // const value = e.detail.value || ''; // if (Number.isNaN(Number(value))) { // return; // } // setMaxOnline(string2Number(value)); // }, []); useImperativeHandle( ref, () => ({ getData: () => ({ workedYear, workedAccounts, newAccountExperience, // style: getStyleString(style.sort()), // maxOnline: maxOnline === '' ? undefined : maxOnline, maxGmv: maxGmv === '' ? undefined : getMaxGmv(Number(maxGmv)), }), }), [workedYear, workedAccounts, newAccountExperience, maxGmv] ); return (
{/* */} {/**/} {/* */} {/**/}
); } export default forwardRef(ProfileExperienceFragment);