CategorySalesTrendTop.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * 统计里TOP10品类销售趋势
  3. * @zjf-2021-06-30
  4. * */
  5. import { connect } from 'dva/index';
  6. import moment from 'moment';
  7. import React, { Component, Fragment } from 'react';
  8. import { Form, Spin, Radio } from 'antd';
  9. import {
  10. sldLlineRtextAddGoodsAddMargin,
  11. sldComLanguage,
  12. noDataPlaceholder,
  13. } from '@/utils/utils';
  14. import global from '@/global.less';
  15. import stat from '@/assets/css/stat.less';
  16. import SldStatDate from '@/components/SldStatDate';
  17. import AreaStack from '@/components/SldStatBizcharts/AreaStack';
  18. import BarStack from '@/components/SldStatBizcharts/BarStack';
  19. import defaultSettings from '@/defaultSettings';
  20. const barColor = ['name', ['rgba(2, 137, 255, 1)', 'rgba(236, 140, 100, 1)', 'rgba(62, 207, 250, 1)', 'rgba(138, 125, 250, 1)', 'rgba(124, 140, 168, 1)', 'rgba(248, 201, 78, 1)', 'rgba(30, 135, 240, 1)', 'rgba(224, 224, 224, 1)', 'rgba(255, 123, 123, 1)', 'rgba(38, 172, 106, 1)']];//TOP10品类销售趋势——柱状图颜色
  21. @connect(({ common }) => ({
  22. common,
  23. }))
  24. @Form.create()
  25. export default class CategorySalesTrendTop extends Component {
  26. constructor(props) {
  27. super(props);
  28. this.state = {
  29. goodsSalesTendLoading: false,//商品动销趋势模块loading
  30. goodsSalesTendParams: {
  31. startTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 00:00:00'),
  32. endTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 23:59:59:999'),
  33. },//商品动销趋势的筛选条件
  34. goodsSalesTendData: [],//TOP10品类销售趋势面积图数据(销量)
  35. goodsSalesTendAmountData: [],//TOP10品类销售趋势面积图数据(销售额)
  36. goodsSalesTendAllData: [],//商品动销趋势全部数据
  37. goodsSalesTendBarAmountData: [],//TOP10品类销售趋势柱状图数据(销售额)
  38. goodsSalesTendBarData: [],//TOP10品类销售趋势柱状图数据(销量)
  39. curGoodsSalesTendDataTopActive: 'amount',//商品销售变化趋势-TOP10当前tab amount-销售额 sales-销量
  40. showType: 'area',//展示类型,默认为area area-面积图 bar-柱状图
  41. areaShowType: 'amount',//面积图展示类型,默认为amount amount-销售额 sales-销量
  42. };
  43. };
  44. componentDidMount() {
  45. this.getGoodsSalesTendData();
  46. }
  47. //获取商品动销趋势数据
  48. getGoodsSalesTendData = () => {
  49. this.setState({ goodsSalesTendLoading: true });
  50. const { dispatch } = this.props;
  51. let { goodsSalesTendParams, goodsSalesTendAllData } = this.state;
  52. let goodsSalesTendBarData = [];
  53. let goodsSalesTendBarAmountData = [];
  54. let goodsSalesTendData = [];
  55. let goodsSalesTendAmountData = [];
  56. dispatch({
  57. type: 'common/get_category_sales_rank',
  58. payload: goodsSalesTendParams,
  59. callback: (res) => {
  60. this.setState({ goodsSalesTendLoading: false });
  61. if (res.state == 200) {
  62. goodsSalesTendAllData = res.data;
  63. if (res.data.length > 0) {
  64. res.data.map(item => {
  65. item.categoryList.map(child => {
  66. //柱状图数据处理-start
  67. goodsSalesTendBarAmountData.push({
  68. key: item.statsTime,
  69. name: child.categoryName,
  70. value: child.saleAmount,
  71. });
  72. goodsSalesTendBarData.push({
  73. key: item.statsTime,
  74. name: child.categoryName,
  75. value: child.saleNum,
  76. });
  77. //柱状图数据处理-end
  78. //面积图数据处理-start
  79. goodsSalesTendAmountData.push({
  80. month: item.statsTime,
  81. city: child.categoryName,
  82. temperature: child.saleAmount,
  83. });
  84. goodsSalesTendData.push({
  85. month: item.statsTime,
  86. city: child.categoryName,
  87. temperature: child.saleNum,
  88. });
  89. //面积图数据处理-end
  90. });
  91. });
  92. }
  93. this.setState({
  94. goodsSalesTendAllData,
  95. goodsSalesTendBarAmountData,
  96. goodsSalesTendBarData,
  97. goodsSalesTendData,
  98. goodsSalesTendAmountData,
  99. });
  100. }
  101. },
  102. });
  103. };
  104. //时间筛选器返回的时间数据
  105. updateSelectDate = (date, index) => {
  106. let { goodsSalesTendParams } = this.state;
  107. let _this = this;
  108. if (index == '_goods_sales_trend') {
  109. //商品动销趋势的时间筛选
  110. goodsSalesTendParams = { ...goodsSalesTendParams, ...date };
  111. this.setState({ goodsSalesTendParams }, () => {
  112. _this.getGoodsSalesTendData();
  113. });
  114. }
  115. };
  116. //tab切换事件
  117. handleChangeTab = (e, type) => {
  118. this.setState({ [type]: e.target.value });
  119. };
  120. render() {
  121. const { goodsSalesTendLoading, goodsSalesTendData, showType, areaShowType, goodsSalesTendBarData, goodsSalesTendBarAmountData, goodsSalesTendAmountData } = this.state;
  122. return (
  123. <div style={{ margin: '0 0 10px 0', paddingBottom: 10, width: '100%' }} className={`${stat.common_table_item}`}>
  124. <div className={`${stat.label_panel} ${global.flex_row_between_center}`}>
  125. <div className={`${global.flex_row_start_center}`}>
  126. {sldLlineRtextAddGoodsAddMargin(defaultSettings.primaryColor, `${sldComLanguage('TOP10品类销售趋势')}`, 10, 0, 0)}
  127. <div style={{ marginLeft: 10 }}>
  128. <Radio.Group size={'small'} onChange={(e) => this.handleChangeTab(e, 'showType')}
  129. defaultValue={showType}>
  130. <Radio.Button value="area">面积图</Radio.Button>
  131. <Radio.Button value="bar">柱状图</Radio.Button>
  132. </Radio.Group>
  133. </div>
  134. </div>
  135. <SldStatDate idIndex={'_goods_sales_trend'}
  136. updateSelectDate={(date) => this.updateSelectDate(date, '_goods_sales_trend')}/>
  137. </div>
  138. <Spin spinning={goodsSalesTendLoading}>
  139. <div className={`${stat.stat_common_table}`} style={{ paddingLeft: 10, height: 520 }}>
  140. <div style={{ margin: '12px 0 0 20px' }}>
  141. <Radio.Group size={'small'} onChange={(e) => this.handleChangeTab(e, 'areaShowType')}
  142. defaultValue={areaShowType}>
  143. <Radio.Button value="amount">销售额</Radio.Button>
  144. <Radio.Button value="sales">销量</Radio.Button>
  145. </Radio.Group>
  146. </div>
  147. <div style={{ padding: '10px 20px 35px 20px', height: 443 }}>
  148. {showType == 'area'
  149. ? (goodsSalesTendBarData.length > 0
  150. ? <AreaStack
  151. data={areaShowType == 'amount' ? goodsSalesTendAmountData : goodsSalesTendData}
  152. unit={areaShowType == 'amount' ? '¥' : ''}/>
  153. : noDataPlaceholder()
  154. )
  155. : (goodsSalesTendBarData.length > 0
  156. ? <BarStack
  157. data={areaShowType == 'amount' ? goodsSalesTendBarAmountData : goodsSalesTendBarData}
  158. color={barColor}
  159. flag={2}
  160. unit={areaShowType == 'amount' ? '¥' : ''}/>
  161. : noDataPlaceholder()
  162. )
  163. }
  164. </div>
  165. </div>
  166. </Spin>
  167. </div>
  168. );
  169. }
  170. }