import * as React from 'react'; import {WorkInfo} from '../types' import moment from 'moment' import styled from 'styled-components' import MultiLineEllipsis from '&/components/common/multiLineEllipsis' // import { getToUserId, getBSGlobal } from '&/components/helper'; // import { getUserInfo } from '&/components/profileWrapper/helper'; export interface CardProps { data:WorkInfo onClick?:Function, style?: any, showSubNum?: boolean, onClickCard?:Function, } /** * * @param type number 0:自定义 1:年度 2:季度 3:月度 */ const getBackgroundByType = (type:0|1|2|3) => { switch(type){ case 0: return '#00C4CB' case 1: return '#8872FF' case 2: return '#4272FF' case 3: return '#009EFF' } } /** * * @param okrtype number 1:个人 2:部门 3:公司 */ const getOkrTypePos =(okrtype:1|2|3)=>{ switch(okrtype){ case 3: return '0 0px' case 2: return '0 -46px' case 1:return '0 -94px' } } const Wrapper = styled.div` display: inline-flex; flex-direction: column; user-select: none; width: 281px; height: 160px; background: #FFFFFF; box-shadow: 0 0 4px 0 rgba(0,0,0,0.10); border-radius: 4px; overflow: hidden; transition: all .3s ease-in; cursor: ${(props:{clickable:boolean}) => props.clickable? 'pointer': 'default'}; box-shadow: 0 0 8px 0 rgba(0,0,0,0.30); transition: all .3s ease; &:hover{ transform: ${(props:any) => props.onClick? 'scale(1.03)':'scale(1)'} } ` const Header = styled.div` box-sizing: border-box; padding: 10px 10px 11px; background-color: ${(props:{cycleType:0|1|2|3}) => getBackgroundByType(props.cycleType)}; background-size: 101px 36px; background-position: 100% 100%; background-repeat: no-repeat; position:relative; ` const OkrType = styled.div` background-image: url(${require('../assets/okrType.png')}); background-position:${(props:{okrType:1|2|3}) => getOkrTypePos(props.okrType)}; width:43px; height:42px; position:absolute; top:0px; right:-1px; background-size:cover; ` const HeaderBottom = styled.div` display: flex; align-items: center; height:17px; line-height:17px; ` const Kr = styled.div` height: 17px; width: 34px; background: rgba(255,255,255,0.20); border-radius: 11px; font-size: 12px; color: #FFFFFF; margin-right: 10px; text-align: center; line-height: 18px; ` const Cycle = styled.div` display: inline-block; box-sizing: border-box; line-height: 18px; padding: 0px 10px; background-color: #FFF; height: 17px; border-radius: 9px; -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; color: ${(props:{cycleType:0|1|2|3}) => getBackgroundByType(props.cycleType)}; font-size: 12px; margin-bottom:10px; vertical-align:top; ` // const Line = styled.img` // width: 258px; // height: 2px; // display: block; // margin: 0 auto; // ` const PersonInfo = styled.div` display: flex; flex-direction: row; align-items: center; color: #565E66; font-size: 12px; line-height: 17px; ` const Footer = styled.div` box-sizing: border-box; flex:1; width: 100%; padding:12px 10px; ` const FooterTop = styled.div` display: flex; flex-direction: row; justify-content: space-between; color: #666; font-size: 12px; line-height:17px; ` const EllipsisP = styled.p` overflow: hidden; text-overflow: ellipsis; white-space: nowrap; ` const SubIcon = styled.span` color: #666; transform: rotate(-90deg); ` const ProgressText = styled.div` color:#fff; font-size: 24px; ` const CardContext = styled.a` color: rgb(255, 255, 255); cursor: pointer; width: 190px; margin-right: 20px; &:hover{ color:#fff; } ` export default class Card extends React.Component { private getCycleTextByType = () => { const {cycleType,yqmnum,annualNum} = this.props.data; switch(cycleType) { case 0: return '自定义'; case 1: return annualNum+'年'; case 2: return `第${yqmnum}季度`; case 3: return yqmnum+'月' } } private handleClick = () => { const {onClick} = this.props; onClick && onClick(this.props.data) } isNowYear = (date:string) =>{ const nowDate = moment(new Date()).format("YYYY"); if(moment(new Date(date)).format( "YYYY") == nowDate){ return date.substring(5) }else{ return date } } decimal =(num:any,v:any)=>{ //对进度的后两位小数,战展示的时候四舍五入保留整数 let number = Math.pow(10,v); return Math.round(num*number)/number } public render() { const {data,style,showSubNum,onClickCard} = this.props; const avat = {...data.principalUser}; avat.name.length > 4&&( avat.name = avat.name.substring(0,4)); const map = ['','个人',data.departmentName,'公司'] const progress = this.decimal(parseFloat(data.progress),0) // let start='' // let end='' // const {startDate,endDate} = data // const startDateYY = moment(new Date(startDate)).format( "YYYY") // const endDateYY = moment(new Date(endDate)).format( // "YYYY" // ) // const nowDate = moment(new Date()).format( // "YYYY" // ) // if(!(startDate==""&&endDate=="")){ // if(startDateYY==nowDate&&endDateYY==nowDate){ // start=moment(new Date(startDate)).format( "MM/DD") // end=moment(new Date(endDate)).format( "MM/DD") // }else{ // start=moment(new Date(startDate)).format( "YYYY/MM/DD") // end=moment(new Date(endDate)).format( "YYYY/MM/DD") // } // } return (
{this.getCycleTextByType()}
{data.workName} {progress}%
KR 关键结果 {data.counter.krTotal}
); } }