import React, { Component } from 'react'; import { Scrollbars } from "react-custom-scrollbars"; import './index.scss' import { getApiUrl2, taker } from '../../../components/helper' import NoTask from '../../quadrant/noTask' import WeekList from './weekList' import {RenderTrackHorizontal,RenderTrackVertical} from '../propsSetting' import tubiao from '../panelimages/2and3.png' import titaimg from '../panelimages/week.png' import { getBSGlobal } from '&/components/helper' import RangePickerPop from '&/components/rangePickerPop' import moment from 'moment' import { TaskInfo } from '&/types/task'; import ReactToolTip from 'react-tooltip' interface Props { workId: number pushScreen: any toUserId: number status: number isSuper: boolean renderCreateTaskView:Function createEnable: boolean eventBridge: any isSelf: boolean } interface State { weekTaskArray: any[] startDate: moment.Moment endDate: moment.Moment isDefaultRange: boolean } export default class SecondQuadrant extends Component { constructor(p:Props){ super(p); this.state = { weekTaskArray: [], startDate: moment().day(1), endDate: moment().day(6).add(1,'day'), isDefaultRange: true } } componentDidMount(){ const {eventBridge,workId} = this.props; this.getWeekTask(workId); eventBridge.listenTo('addWeekTask',this.handleAddTask) } componentWillUnmount(){ this.props.eventBridge.removeListener('addWeekTask',this.handleAddTask); } handleAddTask = (task:TaskInfo) => { this.setState({ weekTaskArray:[task,...this.state.weekTaskArray] }) } componentDidUpdate(prevProps:Props) { if(prevProps.workId != this.props.workId){ this.setState({ startDate: moment().day(1), endDate: moment().day(6).add(1,'day'), isDefaultRange: true },() => { this.getWeekTask(this.props.workId) }) } } getWeekTask = async (workId:number) => { const {startDate,endDate} = this.state let url = getApiUrl2(`work/task/week?workId=${workId}&startDate=${startDate.format('YYYY/MM/DD')}&endDate=${endDate.format('YYYY/MM/DD')}`); taker(url, 'GET').then(res => { if (res.Code == 1 && res.Data) { this.setState({ weekTaskArray: res.Data }) } else { this.setState({ weekTaskArray: [] }) } }) } handleChangeRange = (date:any) => { let currentStartDate = moment(date.startDate),currentEndDate = moment(date.endDate); if(moment().day(1).format('YYYY-MM-DD') != date.startDate || moment().day(6).add(1,'day').format('YYYY-MM-DD') != date.endDate){ this.setState({ isDefaultRange: false }) }else { this.setState({ isDefaultRange: true }) } this.setState({ startDate: currentStartDate, endDate: currentEndDate },() => { this.getWeekTask(this.props.workId) }) } handleBackToThisWeek = () => { this.setState({ startDate: moment().day(1), endDate: moment().day(6).add(1,'day'), isDefaultRange: true },() => { this.getWeekTask(this.props.workId) }) } render() { const { pushScreen, toUserId, workId,status,isSuper,renderCreateTaskView,createEnable,isSelf } = this.props const { weekTaskArray,startDate,endDate,isDefaultRange } = this.state; const { apiPath } = getBSGlobal() const scrollStyle = { 'height': 'calc(100% - 5px)', 'backgroundColor': 'transparent', 'width': '100%' } const noTaskConfig = { noTaskText: '请基于目标及当前进展,制定本周重点工作', linkText: '去制定', gotoLink: `${apiPath}/u/${toUserId}/Home#okr/manage?relation=1&work_id=${workId}&app_id=1&app_type=1&workType=&to_user_id=${toUserId}&status=1&detail_type=task`, taNoTaskText: "暂未分配任务", taLinkText: '', toUserId: toUserId, status: status, titaimg:titaimg, tubiao:tubiao, isSelf, isSuper:isSuper } const currentYear = moment().year(); let formatStr = currentYear == startDate.year() && currentYear == endDate.year() ? 'MM/DD':'YYYY/MM/DD'; return (
本周任务
{startDate.format(formatStr)}-{endDate.format(formatStr)}
{ !weekTaskArray.length? { createEnable && this.props.renderCreateTaskView(e,{workId,startDate,endDate,type:'week'},{topBias:300})}> 创建任务 } : renderCreateTaskView(e,{workId,type:'week'},{topBias:300})} weekTaskArray={weekTaskArray} pushScreen={pushScreen} /> }
) } }