import { BaseEventOrig, Image, Swiper, SwiperItem, SwiperProps } from '@tarojs/components'; import Taro from '@tarojs/taro'; import classNames from 'classnames'; import { useCallback, useState } from 'react'; import DevDiv from '@/components/dev-div'; import SafeBottomPadding from '@/components/safe-bottom-padding'; import { OpenSource, PageUrl } from '@/constants/app'; import { CITY_CODE_TO_NAME_MAP } from '@/constants/city'; import { FULL_PRICE_OPTIONS, PART_PRICE_OPTIONS } from '@/constants/job'; import { ProfileGroupType, ProfileTitleMap, WORK_YEAR_OPTIONS } from '@/constants/material'; import { MaterialProfile } from '@/types/material'; import { logWithPrefix, isDesktop } from '@/utils/common'; import { getBasicInfo, sortVideos } from '@/utils/material'; import { navigateTo } from '@/utils/route'; import './index.less'; import onChangeEventDetail = SwiperProps.onChangeEventDetail; import { JoinGroupHint } from '@/components/join-group-hint'; interface IProps { editable: boolean; profile: MaterialProfile; onDev?: () => void; } const PREFIX = 'profile-view-fragment'; const log = logWithPrefix(PREFIX); const DEFAULT_TEXT = '未填写'; const getIndentCity = (codeString: string = '') => { const codes = codeString.split('、'); const cityNames: string[] = []; codes.forEach(code => { const cityName = CITY_CODE_TO_NAME_MAP.get(code); cityName && cityNames.push(cityName); }); return cityNames.join('、'); }; const getIndentPrice = (min: number, max: number, full: boolean) => { if (!min && !max) { return DEFAULT_TEXT; } const options = full ? FULL_PRICE_OPTIONS : PART_PRICE_OPTIONS; const option = options.find(o => o.value.minSalary === min && o.value.maxSalary === max); if (option) { return option.label; } const unit = full ? 'K' : ''; const prices: string[] = []; min && prices.push(`${full ? Number(min) / 1000 : min}${unit}`); max && prices.push(`${full ? Number(max) / 1000 : max}${unit}`); return prices.join(' - '); }; const getWorkYear = (year: number) => { if (!year) { return DEFAULT_TEXT; } const y = Math.min(year, 3); return WORK_YEAR_OPTIONS.find(option => option.value === y)?.label || `${y}年`; }; const getDataGroup = (profile: MaterialProfile | null) => { if (!profile) { return []; } return [ { title: ProfileTitleMap[ProfileGroupType.Intention], type: ProfileGroupType.Intention, items: [ { title: '全职薪资', value: getIndentPrice(profile.fullTimeMinPrice, profile.fullTimeMaxPrice, true) || '' }, { title: '兼职薪资', value: getIndentPrice(profile.partyTimeMinPrice, profile.partyTimeMaxPrice, false) || '' }, { title: '意向城市', value: getIndentCity(profile.cityCodes) || DEFAULT_TEXT }, { title: '是否接受坐班', value: profile.acceptWorkForSit ? '是' : '否' }, ], }, { title: ProfileTitleMap[ProfileGroupType.Experience], type: ProfileGroupType.Experience, items: [ { title: '直播年限', value: getWorkYear(profile.workedYear) || DEFAULT_TEXT }, { title: '直播过的账号', value: profile.workedAccounts || DEFAULT_TEXT }, { title: '自然流起号经验', value: Boolean(profile.newAccountExperience) ? '有' : '无' }, { title: '直播过的品类', value: profile.workedSecCategoryStr || DEFAULT_TEXT }, { title: '最高GMV', value: profile.maxGmv ? `${profile.maxGmv / 10000}万` : DEFAULT_TEXT }, { title: '最高在线人数', value: profile.maxOnline || DEFAULT_TEXT }, ], }, { title: ProfileTitleMap[ProfileGroupType.Advantages], type: ProfileGroupType.Advantages, items: [{ title: '自身优势', value: profile.advantages || DEFAULT_TEXT, fullLine: true }], }, ]; }; export default function ProfileViewFragment(props: IProps) { const { profile, editable, onDev } = props; const [coverIndex, setCoverIndex] = useState(0); const dataGroup = getDataGroup(profile); const videos = sortVideos(profile?.materialVideoInfoList || []); const handleClickVideo = useCallback( (index: number) => { log('handleClickVideo', index); if (isDesktop) { navigateTo(PageUrl.MaterialWebview, { source: encodeURIComponent(videos[index].url), }); } else { Taro.previewMedia({ sources: videos.map(video => ({ url: video.url, type: video.type })), current: index, }); } }, [videos] ); const handleEditVideo = useCallback(() => { log('handleEditBasic'); navigateTo(PageUrl.MaterialUploadVideo, { source: OpenSource.UserPage }); }, []); const handleEditBasic = useCallback(() => { log('handleEditBasic'); navigateTo(PageUrl.MaterialEditProfile, { type: ProfileGroupType.Basic }); }, []); const handleEditGroupItem = useCallback((groupType: ProfileGroupType) => { log('handleEditGroupItem', groupType); navigateTo(PageUrl.MaterialEditProfile, { type: groupType }); }, []); const videoLength = videos.length ? videos.length : 0; const showSwiperButton = videoLength > 1 && isDesktop; const handleChange = useCallback((e: BaseEventOrig) => { setCoverIndex(e.detail.current); }, []); const handlePrev = useCallback(() => { setCoverIndex(coverIndex ? coverIndex - 1 : videoLength - 1); }, [coverIndex, videoLength]); const handleNext = useCallback(() => { setCoverIndex(coverIndex === videoLength - 1 ? 0 : coverIndex + 1); }, [coverIndex, videoLength]); return (
{videos.map((cover, index) => (
handleClickVideo(index)} /> {cover.type === 'video' && ( handleClickVideo(index)} /> )}
))}
{showSwiperButton && (
)} {showSwiperButton && (
)} {editable && (
编辑录屏
)}
{videos[coverIndex]?.title || ''}
{`${coverIndex + 1}/${profile.materialVideoInfoList.length}`}
{!editable && }
{profile.name} {editable && (
编辑
)}
{getBasicInfo(profile)}
{dataGroup.map((data, index: number) => (
{index ? (
{data.title}
) : ( {data.title} )} {editable && (
handleEditGroupItem(data.type)}> 编辑
)}
{data.items.map(item => (
{item.title}
{item.value}
))}
{index !== dataGroup.length - 1 &&
}
))}
); }