SalesCard.js 5.66 KB
Newer Older
陈帅's avatar
陈帅 committed
1 2 3 4
import React, { memo } from 'react';
import { Row, Col, Card, Tabs, DatePicker } from 'antd';
import { FormattedMessage, formatMessage } from 'umi/locale';
import numeral from 'numeral';
5 6 7 8
import { Charts } from 'ant-design-pro';
import styles from '../style.less';

const { Bar } = Charts;
陈帅's avatar
陈帅 committed
9 10 11 12 13 14 15

const { RangePicker } = DatePicker;
const { TabPane } = Tabs;

const rankingListData = [];
for (let i = 0; i < 7; i += 1) {
  rankingListData.push({
16
    title: formatMessage({ id: 'BLOCK_NAME.analysis.test' }, { no: i }),
陈帅's avatar
陈帅 committed
17 18 19 20 21 22 23 24 25 26 27 28 29
    total: 323234,
  });
}

const SalesCard = memo(
  ({ rangePickerValue, salesData, isActive, handleRangePickerChange, loading, selectDate }) => (
    <Card loading={loading} bordered={false} bodyStyle={{ padding: 0 }}>
      <div className={styles.salesCard}>
        <Tabs
          tabBarExtraContent={
            <div className={styles.salesExtraWrap}>
              <div className={styles.salesExtra}>
                <a className={isActive('today')} onClick={() => selectDate('today')}>
30
                  <FormattedMessage id="BLOCK_NAME.analysis.all-day" defaultMessage="All Day" />
陈帅's avatar
陈帅 committed
31 32
                </a>
                <a className={isActive('week')} onClick={() => selectDate('week')}>
33
                  <FormattedMessage id="BLOCK_NAME.analysis.all-week" defaultMessage="All Week" />
陈帅's avatar
陈帅 committed
34 35
                </a>
                <a className={isActive('month')} onClick={() => selectDate('month')}>
36
                  <FormattedMessage id="BLOCK_NAME.analysis.all-month" defaultMessage="All Month" />
陈帅's avatar
陈帅 committed
37 38
                </a>
                <a className={isActive('year')} onClick={() => selectDate('year')}>
39
                  <FormattedMessage id="BLOCK_NAME.analysis.all-year" defaultMessage="All Year" />
陈帅's avatar
陈帅 committed
40 41 42 43 44 45 46 47 48 49 50 51 52
                </a>
              </div>
              <RangePicker
                value={rangePickerValue}
                onChange={handleRangePickerChange}
                style={{ width: 256 }}
              />
            </div>
          }
          size="large"
          tabBarStyle={{ marginBottom: 24 }}
        >
          <TabPane
53
            tab={<FormattedMessage id="BLOCK_NAME.analysis.sales" defaultMessage="Sales" />}
陈帅's avatar
陈帅 committed
54 55 56 57 58 59 60 61 62
            key="sales"
          >
            <Row>
              <Col xl={16} lg={12} md={12} sm={24} xs={24}>
                <div className={styles.salesBar}>
                  <Bar
                    height={295}
                    title={
                      <FormattedMessage
63
                        id="BLOCK_NAME.analysis.sales-trend"
陈帅's avatar
陈帅 committed
64 65 66 67 68 69 70 71 72 73 74
                        defaultMessage="Sales Trend"
                      />
                    }
                    data={salesData}
                  />
                </div>
              </Col>
              <Col xl={8} lg={12} md={12} sm={24} xs={24}>
                <div className={styles.salesRank}>
                  <h4 className={styles.rankingTitle}>
                    <FormattedMessage
75
                      id="BLOCK_NAME.analysis.sales-ranking"
陈帅's avatar
陈帅 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                      defaultMessage="Sales Ranking"
                    />
                  </h4>
                  <ul className={styles.rankingList}>
                    {rankingListData.map((item, i) => (
                      <li key={item.title}>
                        <span
                          className={`${styles.rankingItemNumber} ${i < 3 ? styles.active : ''}`}
                        >
                          {i + 1}
                        </span>
                        <span className={styles.rankingItemTitle} title={item.title}>
                          {item.title}
                        </span>
                        <span className={styles.rankingItemValue}>
                          {numeral(item.total).format('0,0')}
                        </span>
                      </li>
                    ))}
                  </ul>
                </div>
              </Col>
            </Row>
          </TabPane>
          <TabPane
101
            tab={<FormattedMessage id="BLOCK_NAME.analysis.visits" defaultMessage="Visits" />}
陈帅's avatar
陈帅 committed
102 103 104 105 106 107 108 109 110
            key="views"
          >
            <Row>
              <Col xl={16} lg={12} md={12} sm={24} xs={24}>
                <div className={styles.salesBar}>
                  <Bar
                    height={292}
                    title={
                      <FormattedMessage
111
                        id="BLOCK_NAME.analysis.visits-trend"
陈帅's avatar
陈帅 committed
112 113 114 115 116 117 118 119 120 121 122
                        defaultMessage="Visits Trend"
                      />
                    }
                    data={salesData}
                  />
                </div>
              </Col>
              <Col xl={8} lg={12} md={12} sm={24} xs={24}>
                <div className={styles.salesRank}>
                  <h4 className={styles.rankingTitle}>
                    <FormattedMessage
123
                      id="BLOCK_NAME.analysis.visits-ranking"
陈帅's avatar
陈帅 committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
                      defaultMessage="Visits Ranking"
                    />
                  </h4>
                  <ul className={styles.rankingList}>
                    {rankingListData.map((item, i) => (
                      <li key={item.title}>
                        <span
                          className={`${styles.rankingItemNumber} ${i < 3 ? styles.active : ''}`}
                        >
                          {i + 1}
                        </span>
                        <span className={styles.rankingItemTitle} title={item.title}>
                          {item.title}
                        </span>
                        <span>{numeral(item.total).format('0,0')}</span>
                      </li>
                    ))}
                  </ul>
                </div>
              </Col>
            </Row>
          </TabPane>
        </Tabs>
      </div>
    </Card>
  )
);

export default SalesCard;