OfflineData.tsx 2.11 KB
Newer Older
陈帅's avatar
陈帅 committed
1 2
import { Card, Col, Row, Tabs } from 'antd';
import { FormattedMessage, formatMessage } from 'umi-plugin-react/locale';
陈帅's avatar
陈帅 committed
3
import React from 'react';
陈帅's avatar
陈帅 committed
4
import { OfflineChartData, OfflineDataType } from '../data.d';
陈帅's avatar
陈帅 committed
5

陈帅's avatar
陈帅 committed
6
import { TimelineChart, Pie } from './Charts';
陈帅's avatar
陈帅 committed
7
import NumberInfo from './NumberInfo';
陈帅's avatar
陈帅 committed
8
import styles from '../style.less';
陈帅's avatar
陈帅 committed
9

陈帅's avatar
陈帅 committed
10 11 12 13
const CustomTab = ({
  data,
  currentTabKey: currentKey,
}: {
陈帅's avatar
陈帅 committed
14
  data: OfflineDataType;
陈帅's avatar
陈帅 committed
15
  currentTabKey: string;
陈帅's avatar
陈帅 committed
16
}) => (
陈帅's avatar
陈帅 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  <Row gutter={8} style={{ width: 138, margin: '8px 0' }}>
    <Col span={12}>
      <NumberInfo
        title={data.name}
        subTitle={
          <FormattedMessage
            id="BLOCK_NAME.analysis.conversion-rate"
            defaultMessage="Conversion Rate"
          />
        }
        gap={2}
        total={`${data.cvr * 100}%`}
        theme={currentKey !== data.name ? 'light' : undefined}
      />
    </Col>
    <Col span={12} style={{ paddingTop: 36 }}>
      <Pie
        animate={false}
        inner={0.55}
        tooltip={false}
        margin={[0, 0, 0, 0]}
        percent={data.cvr * 100}
        height={64}
      />
    </Col>
  </Row>
);
陈帅's avatar
陈帅 committed
44 45 46 47 48 49 50 51 52 53 54 55

const { TabPane } = Tabs;

const OfflineData = ({
  activeKey,
  loading,
  offlineData,
  offlineChartData,
  handleTabChange,
}: {
  activeKey: string;
  loading: boolean;
陈帅's avatar
陈帅 committed
56 57
  offlineData: OfflineDataType[];
  offlineChartData: OfflineChartData[];
陈帅's avatar
陈帅 committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  handleTabChange: (activeKey: string) => void;
}) => (
  <Card loading={loading} className={styles.offlineCard} bordered={false} style={{ marginTop: 32 }}>
    <Tabs activeKey={activeKey} onChange={handleTabChange}>
      {offlineData.map(shop => (
        <TabPane tab={<CustomTab data={shop} currentTabKey={activeKey} />} key={shop.name}>
          <div style={{ padding: '0 24px' }}>
            <TimelineChart
              height={400}
              data={offlineChartData}
              titleMap={{
                y1: formatMessage({ id: 'BLOCK_NAME.analysis.traffic' }),
                y2: formatMessage({ id: 'BLOCK_NAME.analysis.payments' }),
              }}
            />
          </div>
        </TabPane>
      ))}
    </Tabs>
  </Card>
);

export default OfflineData;