import React, { Component } from 'react' import styled from 'styled-components' import EditPop from '&/components/krItem/components/EditPop' import LineProgress from '&/components/common/progress/LineProgress' import { getApiUrl, taker } from '&/components/helper' // import UserSelector from '&/components/avatarSelector/index' import ConfidenceComp from '&/components/okr-Confidence' import Score from './krPushScore' import ErrorAlertPop from '&/components/millpostItem/error-alert-pop/index' import RangePickerPop from '&/components/rangePickerPop' interface KR { mileStoneId: number; workId: number; mileStoneName: string; startDate: string; endDate: string; user: User; status: number; taskTotal: number; finishTaskTotal: number; remainingDays: number; progress: number; riskLevel: number; isOpen: boolean; remainingContent: string; progressDescription: string; editable: boolean; evaluateEditable: boolean; confidenceIndex: number; evaluateValue: string; tasks?: any; index?:number isEvaluate:boolean; } interface User { userId: number; userType: number; Name: string; name?:string; email: string; departmentName: string; postition: string; avatar: Avatar; } interface Avatar { original: string; small: string; medium: string; big: string; normal: string; large: string; hasAvatar: boolean; color?: any; } interface Props { data:KR; readonly:boolean changeProp: Function container?:HTMLDivElement|HTMLElement refresh?:Function stopPropagation?:Function openUserSelector?:Function infoTipView:any } const CardItem = styled.div` display: flex; align-items: center; padding-bottom: 15px; position:relative; &:hover{ .tu-icon-edit{ opacity:1 } } ` const Card = styled.div` background: #FFFFFF; border-radius: 4px; padding: 16px 25px 3px 19px; margin-bottom: 15px; .kr-push-screen { .kr-logo{ width:36px; height:20px; line-height:20px; } .krname{ font-size: 16px; width: 50%; margin-top: 0; } .heart{ text-align: right; } } ` const SmallIcon = styled.span` color: #83898F; font-size: 13px; margin-right: 7px; ` const SmallTitle = styled.span` font-size: 14px; color: #83898F; margin-right: 18px; width:64px; line-height:16px; display:inline-block; ` const SmallText = styled.span` font-size: 14px; color: #83898F; ` const SmallTextP = styled.div` font-size: 14px; color: #83898F; display:inline-block; position:relative; max-width: 200px; overflow: hidden; text-overflow: ellipsis; vertical-align:text-top; white-space:nowrap; ` const Box = styled.div` width: 100%; flex: 1; display: flex; align-items: center; .tu-icon-edit { opacity: 0; margin-left: 5px; cursor: pointer; font-size: 12px; color: #106ECC; } &:hover { .tu-icon-edit { opacity: 1; } } ` const NumberWrapper = styled.p` margin-left: 16px; ` const Num = styled.span` font-size: 14px; color: #5CADFF ; ` const IconEdit = styled.i` padding: 4px; opacity: 0; margin-left: 5px; cursor: pointer; font-size: 12px; color: #106ECC; position:relative; &:hover{ background: #FAFBFC; box-shadow: 0 0 2px 0 rgba(0,0,0,0.17); border-radius: 1px; } ` const InfoTipEdit = styled.span` position:relative; &:hover{ .defore,.after{ display:block } } ` const InfoTipEditBefore = styled.span` width:0; height:0; border: 5px solid; border-color:rgba(0,0,0,0.8) transparent transparent ; margin-left:5px; content:''; bottom: 18px; left: 8px; position: absolute; display:inline-block; display:none; ` const InfoTipEditAfter = styled.span` position:absolute; left:0px; bottom:28px; max-width:200px; font-size:12px; background:rgba(0,0,0,0.8); color:#fff; padding:5px 10px; text-align:center; border-radius:1px; display:none; white-space: nowrap; ` const InfoTip = styled.div` position:absolute; justify-content: center; display: flex; flex-direction: column; left:100px; bottom:30px; ` const InfoText = styled.div` max-width:200px; font-size:12px; background:rgba(0,0,0,0.8); color:#fff; padding:5px; white-space:normal; text-align:center; ` const InfoBorder = styled.div` width:0; height:0; border: 5px solid; border-color:rgba(0,0,0,0.8) transparent transparent ; margin-left:5px; ` interface State { message:string showTip:boolean } export default class basicInfo extends Component { heart: HTMLDivElement; progress:HTMLDivElement; dateTime:HTMLDivElement; krName:HTMLDivElement; state = { message:'', showTip:false } // componentDidMount(){ // document.addEventListener('click', this.hideUserSelect) // } // componentWillUnmount() { // document.removeEventListener('click', this.hideUserSelect) // } // 点击头像出现选人弹层 handleUserSelector = (e:any) => { const {readonly} = this.props; if(readonly) return; e.stopPropagation() e.nativeEvent.stopImmediatePropagation(); const container = { //@ts-ignore container :$(this.props.container) } this.props.openUserSelector && this.props.openUserSelector(e.target,this.checkPrincipalId.bind(this),container); } componentDidMount(){ } updataProgress = (propName:string,value:string):string|void => { const {changeProp} = this.props; const { mileStoneId} = this.props.data; const reg = /^(\d|[1-9]\d)(\.\d{1,2})?$/; if(!reg.test(value) && value != '100'){ return '请输入0-100之间的数字、“.”,支持小数点后两位' } let url = getApiUrl(`kr/progress/update?krId=${mileStoneId}&progress=${value}`); taker(url, 'POST'); changeProp(propName,value,mileStoneId) } // 检查是否是项目成员 async checkPrincipalId(user:any) { const { workId } = this.props.data let checkUrl = getApiUrl(`Work/CheckWorkUser?workId=${workId}&toUserId=${user.Id}`) taker(checkUrl, 'GET').then(res => { if (res.Code == 1) { this.updataPrincipalId(user) } else { this.setState({ message: "非目标成员不能成为目标关键成果的负责人", }) setTimeout(() => { this.setState({ message: '' }) }, 1000) } }) } // 把更改后的负责人信息传给后端 updataPrincipalId =async(users:any)=> { const { mileStoneId, workId } = this.props.data; //@ts-ignore const { Color, HasAvatar, Small,Big } = users.UserAvatar const config = { workMileStoneId: mileStoneId, workId: workId, principalId: users.Id } let url = getApiUrl(`WorkMileStone/UpdatePrincipal?workMileStoneId=${mileStoneId}`); const res = await taker(url, 'POST', config); if (res.Code == 1) { const {mileStoneId} = this.props.data; this.props.changeProp('user',users,mileStoneId) } } updataConfidenceIndex = (index:number) => { const { mileStoneId} = this.props.data; const milepostProgressConfig = { confidenceIndex:index } let url = getApiUrl(`kr/updateConfidenceIndex?workMileStoneId=${mileStoneId}`); taker(url, 'POST', milepostProgressConfig); this.props.changeProp('confidenceIndex',index,mileStoneId) } //更新时间 updataDate = async (date:any) => { const { mileStoneId } = this.props.data; const { startDate, endDate } = date let url = getApiUrl(`WorkMileStone/UpdateDate?workMileStoneId=${mileStoneId}`); await taker(url, 'POST', {startDate,endDate}); this.props.refresh && this.props.refresh(mileStoneId) } //隐藏弹层 hideHide =()=>{ //@ts-ignore this.progress && this.progress.handleCancel(); //@ts-ignore this.refs.score.score && this.refs.score.score.handleCancel(); //@ts-ignore this.dateTime.handleCancel(); } showTip =()=>{ this.setState({ showTip:true }) } hideTip = () =>{ this.setState({ showTip:false }) } render() { const {data,readonly,container,changeProp,openUserSelector} = this.props; const {progress,confidenceIndex,isEvaluate,evaluateEditable,mileStoneId,remainingContent,startDate,endDate} = data; const {handleUserSelector,showTip,hideTip} = this; const defaultRange = { startDate:startDate, endDate:endDate } const evaluateValue = isEvaluate ? data.evaluateValue :''; let first=0,last=0; if(remainingContent){ for(let i=0;i0;i--){ if(remainingContent.charAt(i).match(/^\d$/g)){ first = i } } } const errorAlertConfig = { errorAlertText: this.state.message, top: 37, right:0, showExclamationMark: true } return ( 负责人 this.krName = r} onMouseEnter={showTip} onMouseLeave={hideTip}> {(data.user.Name||data.user.name)} { this.state.showTip && {(data.user.Name||data.user.name)} } { !readonly && 编辑 } { this.state.message.length ? :'' } KR进度
{progress}% {!readonly && this.updataProgress('progress',value)} disable={true} container={container} //@ts-ignore ref={(r:HTMLDivElement)=>this.progress = r} > 编辑 }
信心指数 this.heart=r} container={container} /> { !readonly && { //@ts-ignore this.heart.showHeart()}}/> 编辑 } KR评分 changeProp('evaluateValue',v,mileStoneId)} showMessage={false} hasText={true} openUserSelector={openUserSelector} ref='score' align={'bottom'} /> 起止时间 {data.startDate+' ~ '+data.endDate} { !first ? {remainingContent} : {remainingContent.slice(0,first)} {remainingContent.slice(first,last+1)} {remainingContent.slice(last+1)} } this.dateTime=r} stopPropagation={this.props.stopPropagation} > { !readonly && 编辑 }
) } }