import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts'; import GridContent from '@/components/PageHeaderWrapper/GridContent'; import PageLoading from '@/components/PageLoading'; import { getTimeDistance } from '@/utils/utils'; import { Col, Dropdown, Icon, Menu, Row } from 'antd'; import { RangePickerValue } from 'antd/es/date-picker/interface'; import { connect } from 'dva'; import * as H from 'history'; import React, { Component, Suspense } from 'react'; import { Dispatch } from 'redux'; import styles from './Analysis.less'; import { IChartModelState } from './models/chart'; const IntroduceRow = React.lazy(() => import('./IntroduceRow')); const SalesCard = React.lazy(() => import('./SalesCard')); const TopSearch = React.lazy(() => import('./TopSearch')); const ProportionSales = React.lazy(() => import('./ProportionSales')); const OfflineData = React.lazy(() => import('./OfflineData')); interface AnalysisProps { dispatch: Dispatch; location: H.Location; chart: IChartModelState; loading: boolean; } interface AnalysisState { salesType: string; currentTabKey: string; rangePickerValue: RangePickerValue; } @connect(({ chart, loading }) => ({ chart, loading: loading.effects['chart/fetch'], })) class Analysis extends Component { state = { salesType: 'all', currentTabKey: '', rangePickerValue: getTimeDistance('year'), }; reqRef: number; componentDidMount() { const { dispatch } = this.props; this.reqRef = requestAnimationFrame(() => { dispatch({ type: 'chart/fetch', }); }); } componentWillUnmount() { const { dispatch } = this.props; dispatch({ type: 'chart/clear', }); cancelAnimationFrame(this.reqRef); } handleChangeSalesType = e => { this.setState({ salesType: e.target.value, }); }; handleTabChange = key => { this.setState({ currentTabKey: key, }); }; handleRangePickerChange: ( dates: RangePickerValue, dateStrings: [string, string], ) => void = rangePickerValue => { const { dispatch } = this.props; this.setState({ rangePickerValue, }); dispatch({ type: 'chart/fetchSalesData', }); }; selectDate: (type: string) => void = type => { const { dispatch } = this.props; this.setState({ rangePickerValue: getTimeDistance(type), }); dispatch({ type: 'chart/fetchSalesData', }); }; isActive: (type: string) => string = type => { const { rangePickerValue } = this.state; const value = getTimeDistance(type); if (!rangePickerValue[0] || !rangePickerValue[1]) { return ''; } if ( rangePickerValue[0].isSame(value[0], 'day') && rangePickerValue[1].isSame(value[1], 'day') ) { return styles.currentDate; } return ''; }; render() { const { rangePickerValue, salesType, currentTabKey } = this.state; const { chart, loading } = this.props; const { visitData, visitData2, salesData, searchData, offlineData, offlineChartData, salesTypeData, salesTypeDataOnline, salesTypeDataOffline, } = chart; let salesPieData; if (salesType === 'all') { salesPieData = salesTypeData; } else { salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline; } const menu = ( 操作一 操作二 ); const dropdownGroup = ( ); const activeKey = currentTabKey || (offlineData[0] && offlineData[0].name); return ( }>
); } } const AnalysisPage: React.FC = props => ( ); export default AnalysisPage;