import * as React from 'react' import { getQueryString, getUserInfo, getTitaExpire, getBSGlobal, takerCloud } from '../../helper'; import { getCloudApiUrl } from '../../helper/getCloudApi.js' import ToolTip from '@beisen/tool-tip'; import Avatar from 'ux-feature-avatar'; import ReactToolTip from 'react-tooltip'; interface Props { userInfo:any } export default class UserInfo extends React.PureComponent{ state = { isFetching: true, avatarColor: '', avatarImg: '', name: '', department: '', position: '', isSelf: false, jumpUrl: '#', blessingType: 0, userId: '', medalType: 1, medalUrl: '', decorationType: 1, showChangeAvatarTip: false } constructor(props: any) { super(props); } componentDidMount() { this.getMedalConfig() } // componentWillReceiveProps(nextProps:any) { // debugger // this.getData() // } getMedalConfig = () => { const userId = getQueryString()['to_user_id'] || getUserInfo()['Id'] const url = `${getCloudApiUrl('/UPaaSCoreMRest/100000/UserProerty/GetSimpleUserProerty')}`; const _body = { userId: [userId] } takerCloud(url, 'POST', _body ).then(res => { if (res.HttpCode == 200 && res.OperationObject && res.OperationObject[userId]) { const { BlessingType, DecorationType, MedalUrl } = res.OperationObject[userId]; this.setState({ medalType: DecorationType == 2 ? 1 : 0, blessingType: BlessingType, medalUrl: MedalUrl, decorationType: DecorationType }) } }) } willUnmount = false componentWillUnmount() { this.willUnmount = true } getData = (userInfo:any) => { const selfId = getUserInfo()['Id']; const { UserAvatar, Name = 'ren', DepartmentName = '', PositionName = '', UserId } = userInfo; const deadline = getTitaExpire().Day; const titaHost = getBSGlobal('titaHost'); let isSelf, jumpUrl; if (selfId == UserId) { isSelf = true if (deadline > 0) { jumpUrl = `${titaHost}/u/${selfId}/Home#${encodeURIComponent(`set?url=//${titaHost}/u/${selfId}/Setting/Avatar&page_id=avatar`)}` } else { //www.italent.cn/200730475/ITalentHome#widget/italent?iTalentFrame=//www.italent.cn/200730475/UIBuilder#/PersonalSettings jumpUrl = `${titaHost}/${selfId}/ITalentHome#widget/italent?iTalentFrame=//${titaHost}/${selfId}/UIBuilder#/PersonalSettings`; } } else { isSelf = false; } if (this.willUnmount) return; this.setState({ isFetching: false, avatarColor: UserAvatar.Color, avatarImg: UserAvatar.Large, name: Name, department: DepartmentName, position: PositionName, isSelf, jumpUrl, userId: UserId }) } componentWillReceiveProps(p:any){ if(!this.state.isFetching) return; if(p.userInfo){ this.getData(p.userInfo) } } handleClick = (e: any): any => { const { isSelf, jumpUrl } = this.state; const _decorationClass = ['_company-medal-wrap', '_company-medal-img', '_birthday', '_anniversary', '_system-medal-wrap', '_medal-icon'] if (_decorationClass.indexOf(e.target.className) !== -1) return; if (isSelf) { window.open(jumpUrl); } } handleMouseOverOnAvatar = (e: any) => { const _decorationClass = ['_company-medal-wrap', '_company-medal-img', '_birthday', '_anniversary', '_system-medal-wrap', '_medal-icon']; if (_decorationClass.indexOf(e.target.className) !== -1) { this.setState({ showChangeAvatarTip: false }) } else { this.setState({ showChangeAvatarTip: true }) } } render() { const { isFetching, avatarColor, avatarImg, name, department, position, isSelf, blessingType, userId, decorationType, medalUrl, showChangeAvatarTip } = this.state; // const { tagShow } = this.props; const avatarConfig = { name: name, avatar: { hasAvatar: avatarImg, img: avatarImg, //头像图片, color: avatarColor }, blessingType: blessingType || 0, medalurl: medalUrl, medalType: 1, userId: userId, size: 80, decorationType: decorationType, udc: { bless: { ext: { type: "bless", "from": "prfile-avatar", to: userId } }, medal: { ext: { type: "medal", desc: "view-wall", from: "profile-avatar" } } } } if (isFetching) return null const depart = department.split('>'); return
{ showChangeAvatarTip ? : }
{name} {/* */}
{this.props.children}
} }