import * as React from 'react' import { taker, getApiUrl, getApiUrl2, getUserInfo, getToUserId, getBSGlobal } from '../../helper'; interface HonourWallProps { honorWall: any, userInfo: any } declare global { interface Window { Features: any; } } export default class HonourWall extends React.PureComponent { state = { isFetching: true, ranksData: [], medalState: 0 } componentDidMount() { this.getData(this.props) } componentWillReceiveProps(nextProps: HonourWallProps) { let origin = JSON.stringify(this.props.honorWall); let next = JSON.stringify(nextProps.honorWall); if(origin != next){ this.getData(nextProps) } } Features:any; willUnmount = false; componentWillUnmount() { this.willUnmount = true } getData = async (props: HonourWallProps) => { const { honorWall: savedHonorWallData } = props const honourWallUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/TalentHonor/GetAppItems?code=TalentOperation&toUserId=${getToUserId()}`); const honourWallRes = await taker(honourWallUrl); const rankUrl = getApiUrl2(`user/info/rank?to_userId=${getToUserId()}`); const rankRes = await taker(rankUrl); const medalUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/Medal/GainedMedalList?toUserId=${getToUserId()}&type=0`); const medalRes = await taker(medalUrl); let honourWallData: any[] = []; let ranksData: any[] = []; let { medalState } = this.state; if (honourWallRes.Code === 200) { const honourWallResData = honourWallRes.OperationObject.map((item: any) => { return { name: item.Title, inCheck: true } }) if (savedHonorWallData !== undefined) { honourWallData = savedHonorWallData.map((item: any) => { if (honourWallResData.find((i: any) => { return i.name == item.name })) return item; }) } honourWallResData.forEach((item: any) => { if (!honourWallData.find((i: any) => { return !!i && i.name == item.name })) honourWallData.push(item) }) } if (rankRes && rankRes.Code == 1 && rankRes.Data && rankRes.Data.length) { const { Data } = rankRes; honourWallData.forEach((item: any) => { let rankData: any if (!!item && item.inCheck) { switch (item.name) { case '点赞': rankData = this.findRankData(Data, 3); if (rankData) ranksData[2] = rankData; break; case '红包': rankData = this.findRankData(Data, 2); if (rankData) ranksData[0] = rankData; break; case '勋章': rankData = this.findRankData(Data, 5); if (rankData) ranksData[1] = rankData; break; } } }) ranksData = ranksData.filter(item => !!item) if (medalRes && medalRes.Code === 200 && (!medalRes.OperationObject || !medalRes.OperationObject.length)) { medalState = 1 } if (this.willUnmount) return; this.setState({ isFetching: false, ranksData, medalState: medalState }) } } findRankData = (Data: any, type: any) => { return Data.find((i: any) => i.rankType == type); } getRankTitle = (type: any) => { let typeName = ''; switch (type) { case 2: typeName = '红包'; break; case 3: typeName = '点赞'; break; case 4: typeName = '分享'; break; case 5: typeName = '勋章'; break; } return typeName } getRankInfo = (data: any) => { const { rank, overPercentage } = data; if (rank > 10) { return ( 打败了 {`${overPercentage}`}的人 ) } else { return ( 企业排名 第{rank}名 ) } } openReward = () => { if(!window.Features) return; const {userInfo} = this.props; if(!userInfo) return; const loginUser = getUserInfo(); if(!this.Features){ this.Features = new window.Features({ needMask: false, zIndex: 1111, //层级 onClose: function() { //关闭的回调 }, onSuccess:function(){ //打赏成功的回掉函数 }, changeLeftMenuShade:true,//是否改变菜单阴影 domNode:document.getElementById('_feature_cmp_wrapper_'), //组件的挂载点 loginUser: { email:loginUser.Email, name:loginUser.Name, avatar: { hasAvatar: loginUser.UserAvatar.HasAvatar, img: loginUser.UserAvatar.Medium, color: loginUser.UserAvatar.Color }, id: loginUser.Id }, }); } this.Features.renderPayReward({ multi:false,//不传默认false toUserInfo: { email:userInfo.Email, name:userInfo.Name, avatar: { hasAvatar: userInfo.HasAvatar, img: userInfo.Avatar.Medium, color: userInfo.Avatar.Color }, id: userInfo.UserId }, objId: "", objType: 1 }); } getRankIcon = (type: number) => { const loginId = getUserInfo()['Id']; const toUserId = getToUserId(); const { medalState } = this.state; const webPath = getBSGlobal('apiPath'); const medal = encodeURIComponent( JSON.stringify({ ext: { type: "medal", desc: "view-wall", from: "okr-panel-head" } }) ) const reward = encodeURIComponent( JSON.stringify({ ext: { type: "reward", desc: "view", from: "okr-panel-head" } }) ) const doReward = encodeURIComponent( JSON.stringify({ ext: { type: "doReward", desc: "view", from: "okr-panel-head" } }) ) let iframeBoxUrl = `${webPath}/${loginId}/UpaasHome#`; if (webPath.indexOf('tita') > -1) { iframeBoxUrl = `${webPath}/u/${loginId}/Home#`; } if (webPath.indexOf('italent') > -1) { iframeBoxUrl = `${webPath}/${loginId}/ITalentHome#`; } if (loginId == toUserId) { // 红包 if (type == 2) { return } }else { if(type == 2) { return } } // 勋章 if (type == 5) { return } return } getRankQuantity = (type: number, value: number) => { const loginId = getUserInfo()['Id']; const toUserId = getToUserId(); const { medalState } = this.state; const webPath = getBSGlobal('apiPath'); let iframeBoxUrl = `${webPath}/${loginId}/UpaasHome#`; if (webPath.indexOf('tita') > -1) { iframeBoxUrl = `${webPath}/u/${loginId}/Home#`; } if (webPath.indexOf('italent') > -1) { iframeBoxUrl = `${webPath}/${loginId}/ITalentHome#`; } if (loginId == toUserId) { // 红包 if (type == 2) { return ( {`${this.getRankTitle(type)}${value}`} ) } }else { if(type == 2){ return ( {`${this.getRankTitle(type)}${value}`} ) } } // 勋章 if (type == 5) { return ( {`${this.getRankTitle(type)}${value}`} ) } return ( {`${this.getRankTitle(type)}${value}`} ) } render() { const { isFetching, ranksData } = this.state return (
get管理新技能:目标工作法 { isFetching ? null : ranksData.map((item: any, index: number) => { return (
{ this.getRankIcon(item.rankType) }
{ this.getRankQuantity(item.rankType, item.value) }
) }) }
) } }