NewTrend.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { connect } from 'dva/index';
  2. import moment from 'moment';
  3. import React, { Component } from 'react';
  4. import { Form, Spin } from 'antd';
  5. import { sldLlineRtextAddGoodsAddMargin, sldComLanguage, noDataPlaceholder } from '@/utils/utils';
  6. import global from '@/global.less';
  7. import SldStatDate from '@/components/SldStatDate';
  8. import stat from '@/assets/css/stat.less';
  9. import LineArea from '@/components/SldStatBizcharts/LineArea';
  10. import defaultSettings from '@/defaultSettings';
  11. @connect(({ common }) => ({
  12. common,
  13. }))
  14. @Form.create()
  15. export default class NewTrend extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. newTrendInitLoading: false,//会员/店铺新增趋势模块加载状态
  20. newTrendParams: {
  21. startTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 00:00:00'),
  22. endTime: (moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 23:59:59:999'),
  23. },//会员/店铺新增趋势的筛选条
  24. newTrendData: [],//会员/店铺新增趋势数据
  25. };
  26. }
  27. componentDidMount() {
  28. this.getNewTrend();
  29. }
  30. //时间筛选器返回的时间数据
  31. updateSelectDate = (date, index) => {
  32. let { newTrendParams } = this.state;
  33. let _this = this;
  34. if (index == '_new_trend') {
  35. //会员/店铺新增趋势的时间筛选
  36. newTrendParams = { ...newTrendParams, ...date };
  37. this.setState({ newTrendParams }, () => {
  38. _this.getNewTrend();
  39. });
  40. }
  41. };
  42. //获取会员/店铺新增趋势的数据
  43. getNewTrend = () => {
  44. this.setState({ newTrendInitLoading: true });
  45. const { dispatch } = this.props;
  46. let { newTrendParams } = this.state;
  47. let newTrendData = [];
  48. dispatch({
  49. type: 'common/get_new_trend',
  50. payload: newTrendParams,
  51. callback: (res) => {
  52. this.setState({ newTrendInitLoading: false });
  53. if (res.state == 200) {
  54. let data = res.data;
  55. for (let i in data.memberList) {
  56. newTrendData.push({
  57. month: data.memberList[i].statsTime,
  58. city: `${sldComLanguage('新增会员数')}`,
  59. temperature: data.memberList[i].newMemberNum,
  60. });
  61. newTrendData.push({
  62. month: data.storeList[i].statsTime,
  63. city: `${sldComLanguage('新增店铺数')}`,
  64. temperature: data.storeList[i].newStoreNum,
  65. });
  66. }
  67. this.setState({
  68. newTrendData,
  69. });
  70. }
  71. },
  72. });
  73. };
  74. render() {
  75. const { newTrendInitLoading, newTrendData } = this.state;
  76. return (
  77. <div className={`${stat.visualized_item}`}>
  78. <div className={`${stat.top_info_operate} ${global.flex_com_space_between}`}>
  79. <div className={`${stat.left_label}`}>
  80. {sldLlineRtextAddGoodsAddMargin(defaultSettings.primaryColor, `${sldComLanguage('会员/店铺新增趋势')}`, 10, 0, 0)}
  81. </div>
  82. <SldStatDate idIndex={'_new_trend'} updateSelectDate={(date) => this.updateSelectDate(date, '_new_trend')}/>
  83. </div>
  84. <Spin spinning={newTrendInitLoading}>
  85. <div className={`${stat.main_area}`}>
  86. {newTrendData.length>0
  87. ?<LineArea data={newTrendData}/>
  88. :noDataPlaceholder()
  89. }
  90. </div>
  91. </Spin>
  92. </div>
  93. );
  94. }
  95. }