feat: 模卡更新

This commit is contained in:
chashaobao
2025-11-03 22:18:39 +08:00
parent fde2027588
commit 5e3e6903cb
31 changed files with 479 additions and 193 deletions

View File

@ -0,0 +1,94 @@
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 BlFormSelect from '@/components/bl-form-select';
import { EDUCATION_TYPE_OPTIONS, EducationType } from '@/constants/material';
import { MaterialProfile } from '@/types/material';
import { logWithPrefix, string2Number } from '@/utils/common';
import './index.less';
interface IProps {
profile: Partial<MaterialProfile>;
}
const PREFIX = 'fragment-profile-others';
const log = logWithPrefix(PREFIX);
function ProfileOthersFragment(props: IProps, ref) {
const { profile } = props;
const [educationType, setEducationType] = useState(profile.educationType || '');
const [height, setHeight] = useState(profile.height || '');
const [weight, setWeight] = useState(profile.weight || '');
const [shoeSize, setShoeSize] = useState(profile.shoeSize || '');
const handleInputHeight = useCallback((e: BaseEventOrig<InputProps.inputEventDetail>) => {
const value = e.detail.value || '';
if (Number.isNaN(Number(value))) {
return;
}
setHeight(string2Number(value));
}, []);
const handleInputWeight = useCallback((e: BaseEventOrig<InputProps.inputEventDetail>) => {
const value = e.detail.value || '';
if (Number.isNaN(Number(value))) {
return;
}
setWeight(string2Number(value));
}, []);
const handleInputShoeSize = useCallback((e: BaseEventOrig<InputProps.inputEventDetail>) => {
const value = e.detail.value || '';
if (Number.isNaN(Number(value))) {
return;
}
setShoeSize(string2Number(value));
}, []);
const handleSelectEducationType = useCallback((type: EducationType) => {
setEducationType(type);
}, []);
useImperativeHandle(
ref,
() => ({
getData: () => ({ height, weight, shoeSize, educationType }),
}),
[height, weight, shoeSize, educationType]
);
return (
<div className={PREFIX}>
<div className={`${PREFIX}__title`}>穿</div>
<BlFormItem title="身高" optional>
<BlFormInput value={String(height)} type="number" maxlength={3} onInput={handleInputHeight} rightText="CM" />
</BlFormItem>
<BlFormItem title="体重" optional>
<BlFormInput value={String(weight)} type="number" maxlength={3} onInput={handleInputWeight} rightText="KG" />
</BlFormItem>
<BlFormItem title="鞋码" optional>
<BlFormInput
value={String(shoeSize)}
type="number"
maxlength={2}
onInput={handleInputShoeSize}
rightText="码"
/>
</BlFormItem>
<BlFormItem title="学历" optional>
<BlFormSelect
title="学历"
value={educationType}
options={EDUCATION_TYPE_OPTIONS}
onSelect={handleSelectEducationType}
/>
</BlFormItem>
</div>
);
}
export default forwardRef(ProfileOthersFragment);