GoodsSalesTrendTop.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { connect } from 'dva/index';
  2. import moment from 'moment';
  3. import React, { Component, Fragment } from 'react';
  4. import { Form, Spin, Radio } from 'antd';
  5. import {
  6. sldLlineRtextAddGoodsAddMargin,
  7. sldComLanguage,
  8. noDataPlaceholder,
  9. } from '@/utils/utils';
  10. import global from '@/global.less';
  11. import stat from '@/assets/css/stat.less';
  12. import SldStatDate from '@/components/SldStatDate';
  13. import AreaStack from '@/components/SldStatBizcharts/AreaStack';
  14. import defaultSettings from '@/defaultSettings';
  15. @connect(({ common }) => ({
  16. common,
  17. }))
  18. @Form.create()
  19. export default class GoodsSalesTrendTop extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. goodsSalesTendLoading: false,//商品动销趋势模块loading
  24. goodsSalesTrendRandParams: {
  25. startTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 00:00:00'),
  26. endTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 23:59:59:999'),
  27. },//商品动销趋势的筛选条件
  28. goodsSalesTendData: [],//商品销售变化趋势-TOP10(销量数据)
  29. goodsSalesTendAmountData: [],//商品销售变化趋势-TOP10(销售额数据)
  30. goodsSalesTendAllData: [],//商品动销趋势全部数据
  31. curGoodsSalesTendDataTopActive: 'amount',//商品销售变化趋势-TOP10当前tab amount-销售额 sales-销量
  32. };
  33. };
  34. componentDidMount() {
  35. this.getGoodsSalesTendRandData();
  36. }
  37. //获取商品动销趋势数据
  38. getGoodsSalesTendRandData = () => {
  39. this.setState({ goodsSalesTendLoading: true });
  40. const { dispatch } = this.props;
  41. let { goodsSalesTrendRandParams } = this.state;
  42. let goodsSalesTendData = [];
  43. let goodsSalesTendAmountData = [];
  44. dispatch({
  45. type: 'common/get_goods_sales_trend_top',
  46. payload: goodsSalesTrendRandParams,
  47. callback: (res) => {
  48. this.setState({ goodsSalesTendLoading: false });
  49. if (res.state == 200) {
  50. if (res.data.length > 0) {
  51. res.data.map(item => {
  52. item.goodsList.map(child => {
  53. goodsSalesTendData.push({
  54. month: item.statsTime,
  55. city: child.goodsName,
  56. temperature: child.saleNum,
  57. });
  58. goodsSalesTendAmountData.push({
  59. month: item.statsTime,
  60. city: child.goodsName,
  61. temperature: child.saleAmount,
  62. });
  63. });
  64. });
  65. }
  66. this.setState({
  67. goodsSalesTendData,
  68. goodsSalesTendAmountData,
  69. });
  70. }
  71. },
  72. });
  73. };
  74. //时间筛选器返回的时间数据
  75. updateSelectDate = (date, index) => {
  76. let { goodsSalesTrendRandParams } = this.state;
  77. let _this = this;
  78. if (index == '_goods_sales_rand') {
  79. //商品动销趋势的时间筛选
  80. goodsSalesTrendRandParams = { ...goodsSalesTrendRandParams, ...date };
  81. this.setState({ goodsSalesTrendRandParams }, () => {
  82. _this.getGoodsSalesTendRandData();
  83. });
  84. }
  85. };
  86. //销售额、销量切换事件
  87. handleChangeTab = (e) => {
  88. this.setState({ curGoodsSalesTendDataTopActive: e.target.value });
  89. };
  90. render() {
  91. const { goodsSalesTendLoading, goodsSalesTendData, curGoodsSalesTendDataTopActive, goodsSalesTendAmountData } = this.state;
  92. return (
  93. <div style={{ margin: '10px 0', paddingBottom: 10, width: '100%' }} className={`${stat.common_table_item}`}>
  94. <div className={`${stat.label_panel} ${global.flex_row_between_center}`}>
  95. <div className={`${global.flex_row_start_center}`}>
  96. {sldLlineRtextAddGoodsAddMargin(defaultSettings.primaryColor, `${sldComLanguage('商品销售变化趋势 - TOP10')}`, 10, 0, 0)}
  97. <div style={{ marginLeft: 10 }}>
  98. <Radio.Group size={'small'} onChange={(e) => this.handleChangeTab(e)}
  99. defaultValue={curGoodsSalesTendDataTopActive}>
  100. <Radio.Button value="amount">销售额</Radio.Button>
  101. <Radio.Button value="sales">销量</Radio.Button>
  102. </Radio.Group>
  103. </div>
  104. </div>
  105. <SldStatDate idIndex={'_goods_sales_rand'}
  106. updateSelectDate={(date) => this.updateSelectDate(date, '_goods_sales_rand')}/>
  107. </div>
  108. <Spin spinning={goodsSalesTendLoading}>
  109. <div style={{ height: 498 }}>
  110. <div style={{ padding: '10px 20px 35px 20px', height: 443 }}>
  111. {curGoodsSalesTendDataTopActive == 'amount' &&
  112. <Fragment>
  113. {goodsSalesTendAmountData.length > 0
  114. ? <AreaStack data={goodsSalesTendAmountData} unit={'¥'}/>
  115. : noDataPlaceholder()
  116. }
  117. </Fragment>
  118. }
  119. {curGoodsSalesTendDataTopActive == 'sales' &&
  120. <Fragment>
  121. {goodsSalesTendData.length > 0
  122. ? <AreaStack data={goodsSalesTendData}/>
  123. : noDataPlaceholder()
  124. }
  125. </Fragment>
  126. }
  127. </div>
  128. </div>
  129. </Spin>
  130. </div>
  131. );
  132. }
  133. }