import React, { Component } from 'react'; import { Scrollbars } from "react-custom-scrollbars"; import './index.scss' // import TaskItem from '../../quadrant/taskItem' import MonthList from './monthList' import NoTask from '../../quadrant/noTask' import {RenderTrackHorizontal,RenderTrackVertical} from '../propsSetting' import tubiao from '../panelimages/2and3.png' import titaimg from '../panelimages/month.png' import { getBSGlobal, getApiUrl2, taker } from '&/components/helper'; import RangePickerPop from '&/components/rangePickerPop' import moment from 'moment' import { TaskInfo } from '&/types/task'; import ReactToolTip from 'react-tooltip' interface Props { pushScreen: any toUserId?: number workId:number status:number isSuper:boolean createEnable: boolean renderCreateTaskView: Function eventBridge: any isSelf: boolean } interface State { monthTaskArray:any[] startDate: moment.Moment endDate: moment.Moment isDefaultRange: boolean } export default class ThirdyQuadrant extends Component { constructor(p:Props){ super(p) this.state = { monthTaskArray: [], startDate: moment().day(6).add(2,'day'), endDate: moment().day(6).add(29,'day'), isDefaultRange: true } } componentDidMount(){ const {eventBridge,workId} = this.props; this.getMonthTask(workId); eventBridge.listenTo('addMonthTask',this.handleAddTask) } componentWillUnmount(){ this.props.eventBridge.removeListener('addMonthTask',this.handleAddTask); } handleAddTask = (task:TaskInfo) => { this.setState({ monthTaskArray:[task,...this.state.monthTaskArray] }) } componentDidUpdate(prevProps:Props) { if(prevProps.workId != this.props.workId){ this.setState({ startDate: moment().day(6).add(2,'day'), endDate: moment().day(6).add(29,'day'), isDefaultRange: true },() => { this.getMonthTask(this.props.workId) }) } } getMonthTask = async (workId:number) => { const {startDate,endDate} = this.state; let url = getApiUrl2(`work/task/month?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({ monthTaskArray: res.Data }) } else { this.setState({ monthTaskArray: [] }) } }) } handleChangeRange = (date:any) => { let currentStartDate = moment(date.startDate),currentEndDate = moment(date.endDate); if(moment().day(6).add(2,'day').format('YYYY-MM-DD') != date.startDate || moment().day(6).add(29,'day').format('YYYY-MM-DD') != date.endDate){ this.setState({ isDefaultRange: false }) }else { this.setState({ isDefaultRange: true }) } this.setState({ startDate: currentStartDate, endDate: currentEndDate },() => { this.getMonthTask(this.props.workId) }) } handleBackToCommingForWeeks = () => { this.setState({ startDate: moment().day(6).add(2,'day'), endDate: moment().day(6).add(29,'day'), isDefaultRange: true },() => { this.getMonthTask(this.props.workId) }) } render() { const { pushScreen, toUserId, workId ,status,isSuper,createEnable,renderCreateTaskView,isSelf} = this.props const {monthTaskArray,startDate,endDate,isDefaultRange} = this.state; const { apiPath } = getBSGlobal() 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, isSuper:isSuper, isSelf } const scrollStyle = { 'height': 'calc(100% - 5px)', 'backgroundColor': 'transparent', 'width': '100%' }; const currentYear = moment().year(); let formatStr = currentYear == startDate.year() && currentYear == endDate.year() ? 'MM/DD':'YYYY/MM/DD'; return (
未来四周计划
{startDate.format(formatStr)}-{endDate.format(formatStr)}
{!monthTaskArray.length ? { createEnable && this.props.renderCreateTaskView(e,{workId,startDate,endDate,type:'month'},{topBias:300})}> 创建任务 } : renderCreateTaskView(e,{workId,type:'month'},{topBias:300})} monthTaskArray={monthTaskArray} pushScreen={pushScreen} /> }
) } }