import React, { Component } from 'react'; import { connect } from 'dva'; import { formatMessage, FormattedMessage } from 'umi/locale'; import { Row, Col, Icon, Card, Tabs, Table, Radio, DatePicker, Tooltip, Menu, Dropdown, } from 'antd'; import { ChartCard, MiniArea, MiniBar, MiniProgress, Field, Bar, Pie, TimelineChart, } from '@/components/Charts'; import Trend from '@/components/Trend'; import NumberInfo from '@/components/NumberInfo'; import numeral from 'numeral'; import GridContent from '@/components/PageHeaderWrapper/GridContent'; import Yuan from '@/utils/Yuan'; import { getTimeDistance } from '@/utils/utils'; import styles from './Analysis.less'; const { TabPane } = Tabs; const { RangePicker } = DatePicker; const rankingListData = []; for (let i = 0; i < 7; i += 1) { rankingListData.push({ title: `工专路 ${i} 号店`, total: 323234, }); } @connect(({ chart, loading }) => ({ chart, loading: loading.effects['chart/fetch'], })) class Analysis extends Component { constructor(props) { super(props); this.rankingListData = []; for (let i = 0; i < 7; i += 1) { this.rankingListData.push({ title: formatMessage({ id: 'app.analysis.test' }, { no: i }), total: 323234, }); } this.state = { salesType: 'all', currentTabKey: '', loading: true, rangePickerValue: getTimeDistance('year'), }; } componentDidMount() { const { dispatch } = this.props; this.reqRef = requestAnimationFrame(() => { dispatch({ type: 'chart/fetch', }); this.timeoutId = setTimeout(() => { this.setState({ loading: false, }); }, 600); }); } componentWillUnmount() { const { dispatch } = this.props; dispatch({ type: 'chart/clear', }); cancelAnimationFrame(this.reqRef); clearTimeout(this.timeoutId); } handleChangeSalesType = e => { this.setState({ salesType: e.target.value, }); }; handleTabChange = key => { this.setState({ currentTabKey: key, }); }; handleRangePickerChange = rangePickerValue => { const { dispatch } = this.props; this.setState({ rangePickerValue, }); dispatch({ type: 'chart/fetchSalesData', }); }; selectDate = type => { const { dispatch } = this.props; this.setState({ rangePickerValue: getTimeDistance(type), }); dispatch({ type: 'chart/fetchSalesData', }); }; isActive(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, loading: propsLoding, currentTabKey } = this.state; const { chart, loading: stateLoading } = this.props; const { visitData, visitData2, salesData, searchData, offlineData, offlineChartData, salesTypeData, salesTypeDataOnline, salesTypeDataOffline, } = chart; const loading = propsLoding || stateLoading; let salesPieData; if (salesType === 'all') { salesPieData = salesTypeData; } else { salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline; } const menu = (
); const iconGroup = (