Analysis.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import React, { Component, Suspense } from 'react';
  2. import { connect } from 'dva';
  3. import { Row, Col, Icon, Menu, Dropdown } from 'antd';
  4. import GridContent from '@/components/PageHeaderWrapper/GridContent';
  5. import { getTimeDistance } from '@/utils/utils';
  6. import styles from './Analysis.less';
  7. import PageLoading from '@/components/PageLoading';
  8. import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts';
  9. const IntroduceRow = React.lazy(() => import('./IntroduceRow'));
  10. const SalesCard = React.lazy(() => import('./SalesCard'));
  11. const TopSearch = React.lazy(() => import('./TopSearch'));
  12. const ProportionSales = React.lazy(() => import('./ProportionSales'));
  13. const OfflineData = React.lazy(() => import('./OfflineData'));
  14. @connect(({ chart, loading }) => ({
  15. chart,
  16. loading: loading.effects['chart/fetch'],
  17. }))
  18. class Analysis extends Component {
  19. state = {
  20. salesType: 'all',
  21. currentTabKey: '',
  22. rangePickerValue: getTimeDistance('year'),
  23. };
  24. componentDidMount() {
  25. const { dispatch } = this.props;
  26. this.reqRef = requestAnimationFrame(() => {
  27. dispatch({
  28. type: 'chart/fetch',
  29. });
  30. });
  31. }
  32. componentWillUnmount() {
  33. const { dispatch } = this.props;
  34. dispatch({
  35. type: 'chart/clear',
  36. });
  37. cancelAnimationFrame(this.reqRef);
  38. clearTimeout(this.timeoutId);
  39. }
  40. handleChangeSalesType = e => {
  41. this.setState({
  42. salesType: e.target.value,
  43. });
  44. };
  45. handleTabChange = key => {
  46. this.setState({
  47. currentTabKey: key,
  48. });
  49. };
  50. handleRangePickerChange = rangePickerValue => {
  51. const { dispatch } = this.props;
  52. this.setState({
  53. rangePickerValue,
  54. });
  55. dispatch({
  56. type: 'chart/fetchSalesData',
  57. });
  58. };
  59. selectDate = type => {
  60. const { dispatch } = this.props;
  61. this.setState({
  62. rangePickerValue: getTimeDistance(type),
  63. });
  64. dispatch({
  65. type: 'chart/fetchSalesData',
  66. });
  67. };
  68. isActive = type => {
  69. const { rangePickerValue } = this.state;
  70. const value = getTimeDistance(type);
  71. if (!rangePickerValue[0] || !rangePickerValue[1]) {
  72. return '';
  73. }
  74. if (
  75. rangePickerValue[0].isSame(value[0], 'day') &&
  76. rangePickerValue[1].isSame(value[1], 'day')
  77. ) {
  78. return styles.currentDate;
  79. }
  80. return '';
  81. };
  82. render() {
  83. const { rangePickerValue, salesType, currentTabKey } = this.state;
  84. const { chart, loading } = this.props;
  85. const {
  86. visitData,
  87. visitData2,
  88. salesData,
  89. searchData,
  90. offlineData,
  91. offlineChartData,
  92. salesTypeData,
  93. salesTypeDataOnline,
  94. salesTypeDataOffline,
  95. } = chart;
  96. let salesPieData;
  97. if (salesType === 'all') {
  98. salesPieData = salesTypeData;
  99. } else {
  100. salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline;
  101. }
  102. const menu = (
  103. <Menu>
  104. <Menu.Item>操作一</Menu.Item>
  105. <Menu.Item>操作二</Menu.Item>
  106. </Menu>
  107. );
  108. const dropdownGroup = (
  109. <span className={styles.iconGroup}>
  110. <Dropdown overlay={menu} placement="bottomRight">
  111. <Icon type="ellipsis" />
  112. </Dropdown>
  113. </span>
  114. );
  115. const activeKey = currentTabKey || (offlineData[0] && offlineData[0].name);
  116. return (
  117. <GridContent>
  118. <Suspense fallback={<PageLoading />}>
  119. <IntroduceRow loading={loading} visitData={visitData} />
  120. </Suspense>
  121. <Suspense fallback={null}>
  122. <SalesCard
  123. rangePickerValue={rangePickerValue}
  124. salesData={salesData}
  125. isActive={this.isActive}
  126. handleRangePickerChange={this.handleRangePickerChange}
  127. loading={loading}
  128. selectDate={this.selectDate}
  129. />
  130. </Suspense>
  131. <div className={styles.twoColLayout}>
  132. <Row gutter={24}>
  133. <Col xl={12} lg={24} md={24} sm={24} xs={24}>
  134. <Suspense fallback={null}>
  135. <TopSearch
  136. loading={loading}
  137. visitData2={visitData2}
  138. selectDate={this.selectDate}
  139. searchData={searchData}
  140. dropdownGroup={dropdownGroup}
  141. />
  142. </Suspense>
  143. </Col>
  144. <Col xl={12} lg={24} md={24} sm={24} xs={24}>
  145. <Suspense fallback={null}>
  146. <ProportionSales
  147. dropdownGroup={dropdownGroup}
  148. salesType={salesType}
  149. loading={loading}
  150. salesPieData={salesPieData}
  151. handleChangeSalesType={this.handleChangeSalesType}
  152. />
  153. </Suspense>
  154. </Col>
  155. </Row>
  156. </div>
  157. <Suspense fallback={null}>
  158. <OfflineData
  159. activeKey={activeKey}
  160. loading={loading}
  161. offlineData={offlineData}
  162. offlineChartData={offlineChartData}
  163. handleTabChange={this.handleTabChange}
  164. />
  165. </Suspense>
  166. </GridContent>
  167. );
  168. }
  169. }
  170. export default props => (
  171. <AsyncLoadBizCharts>
  172. <Analysis {...props} />
  173. </AsyncLoadBizCharts>
  174. );