import React, { PureComponent } from 'react' import EditPop from '&/components/krItem/components/EditPop'; // import UserSelector from '&/components/avatarSelector' import styled from 'styled-components' import { getApiUrl, taker } from '&/components/helper'; interface Props { editable: boolean isEvaluate:boolean value: string mileStoneId: number onChangeScore:Function showMessage?:boolean hasText?:boolean container?:HTMLDivElement|HTMLElement align?:string openUserSelector?:Function } interface State { atUsers: User[], showUserSelector:boolean } interface User { Id: number; Name: string; Email: string; DepartmentId: number; Department: string; UserAvatar: UserAvatar; } interface UserAvatar { Original?: any; Small?: any; Medium?: any; Normal?: any; Big?: any; Large?: any; HasAvatar: boolean; Color: string; } const ExtraWrapper = styled.div` min-height: 34px; line-height: 34px; background: #FFF; color: #BFC3C7; font-size: 12px; background:#FAFBFC; box-shadow:12px 0 #FAFBFC, -18px 0px #fafbfc; margin-bottom:12px; ` const Add = styled.span` display: inline-block; width: 24px; height: 24px; line-height: 24px; background: #0CC991; text-align: center; border-radius: 24px; color: #fff; cursor: pointer; &:hover { box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.26); transition: box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1); } ` const Avatar = styled.div` width: 24px; height: 24px; line-height: 24px; color: #fff; border-radius: 24px; display: inline-block; margin-right: 10px; font-size: 12px; text-align: center; cursor: pointer; ` const AvatarWrapper = styled.div` position:relative; display:inline-block; .tu-icon-cross { color: #a9b8bf; position: absolute; top: 3px; right: 5px; display: none; cursor: pointer; :hover{ color: #CC2929; } } &:hover .tu-icon-cross{ display: block; } ` const IconEdit = styled.i` padding: 4px; opacity: 0; margin-left: 5px; cursor: pointer; font-size: 12px; color: #106ECC; &: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; ` export default class Score extends PureComponent { score:HTMLDivElement constructor(p:Props){ super(p); this.state = { atUsers: [], showUserSelector: false } } static defaultProps = { hasText: false } showScore = () => {} deleteUser = (index:number) => { const {atUsers} = this.state; const newU = [...atUsers]; newU.splice(index,1); this.setState({ atUsers: newU }) } openUserSelector = (e:any) => { let options = { //@ts-ignore container :$(this.props.container), bias: { left:-50 } } this.props.openUserSelector && this.props.openUserSelector(e.target,this.handleAddAtUser,options) } handleAddAtUser = (users:User) => { const user = users const {atUsers} = this.state; // this.setState({showUserSelector:false}) if(atUsers.findIndex(u => u.Id == user.Id) != -1) return; this.setState({ atUsers: [user] }) } // closeUserSelector= () => { // this.setState({ // showUserSelector: false // }) // } handleUpdateScore = (value:string) => { let url = getApiUrl('kr/evaluate?workMileStoneId='+this.props.mileStoneId); const reg = /^0\.[0-9]{1,2}$/; if(reg.test(value)|| value == '1' || value =='0'){ let data ={ evaluateValue:parseFloat(value), toUserId:this.state.atUsers.map(u => u.Id).join(',') } taker(url, 'POST',data ) this.props.onChangeScore(value) return; } return '请输入0-1之间的数字,支持小数点后两位'; } getScoreEditPopOption = () => { const {atUsers} = this.state return { title:'@ta查看,ta可以通过系统通知修改kr分数', inputName:'分数', onConfirm:this.handleUpdateScore, value: this.props.value, placeHolder: '请输入0-1间的数字,支持小数点后两位', align: 'left', type: 'line', disable:true, container:this.props.container, onShow:() => { this.setState({atUsers:[],showUserSelector:false}); }, extra: ( @ta查看 { atUsers.map((item:User,index)=>{ return( item.UserAvatar.HasAvatar ? this.deleteUser(index)}> : {item.Name.slice(0,1)} this.deleteUser(index)}> ) }) } ) } } render() { const {value,editable,hasText,isEvaluate,align} = this.props; return (
{ !editable ? isEvaluate?{value}{hasText ? '分':''}:

--

: ( !isEvaluate ?
this.score=r} align={align} popClassName='krPush-score' >

评分

{ //@ts-ignore this.score.handleClick(e) }}/> 编辑
:
this.score=r} popClassName='krPush-score' align={align}> {value}{hasText ? '分':''} { //@ts-ignore this.score.handleClick(e) }}/> 编辑
) }
) } }