UserConversion.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React, { Component, useState, useEffect } from 'react';
  2. import echarts from 'echarts/lib/echarts';
  3. import EChart from '../../../components/EchartsTest/EChart';
  4. import request from '../../../utils/request';
  5. import apis from '../../../services/apis';
  6. import moment from 'moment';
  7. import router from 'umi/router';
  8. import { Table, Select, Row, Col, Menu, Dropdown, Button, Icon, message } from 'antd';
  9. import styles from '../styles.less'
  10. const UserSource = props => {
  11. const [theCurrent, setTheCurrent] = useState({ records: [] })
  12. const [conversionRate, setConversionRate] = useState(0)
  13. useEffect(() => {
  14. UserConversionRate({ conversion: 'authorization_phone' })
  15. }, [])
  16. function UserConversionRate(params) {
  17. request({
  18. ...apis.indexEcharts.userConversion,
  19. params,
  20. }).then(data => {
  21. console.log(data.data_count.registeredCount / data.data_count.pvNum, '1241234')
  22. setDataset(data, params.conversion)
  23. })
  24. }
  25. function setDataset(data, theStatis) {
  26. const { pvNum, ...other } = data.data_count
  27. // 获取第一个值
  28. let num = 0
  29. for (const v of Object.keys(other)) {
  30. num = other[v]
  31. break
  32. }
  33. if (pvNum < num) {
  34. setTheCurrent([
  35. { name: getStatisName(theStatis), value: '0' },
  36. { name: '其余', value: '0' },
  37. ])
  38. } else {
  39. setConversionRate(num / pvNum)
  40. setTheCurrent([
  41. { name: getStatisName(theStatis), value: num },
  42. { name: '其余', value: pvNum - num },
  43. ])
  44. }
  45. }
  46. function getStatisName(theStatis) {
  47. const statisTypes = [
  48. { label: '授权手机', value: 'authorization_phone' },
  49. { label: '项目收藏', value: 'building_save' },
  50. { label: '项目转发', value: 'building_share' },
  51. { label: '活动收藏', value: 'activity_save' },
  52. { label: '活动转发', value: 'activity_share' },
  53. { label: '资讯收藏', value: 'news_save' },
  54. { label: '资讯转发', value: 'news_share' },
  55. { label: '活动报名', value: 'activity_sign' },
  56. ]
  57. return statisTypes.filter(x => x.value === theStatis)[0].label
  58. }
  59. const options = {
  60. legend: {},
  61. color: ['#FF7E48', '#dcdcdc'],
  62. tooltip: {},
  63. series: {
  64. type: 'pie',
  65. name: '转化率',
  66. radius: ['34%', '52%'],
  67. avoidLabelOverlap: false,
  68. label: {
  69. formatter: '{b} {@value}',
  70. emphasis: {
  71. show: true,
  72. formatter: '{d}%',
  73. textStyle: {
  74. fontSize: '22',
  75. fontWeight: 'bold'
  76. }
  77. }
  78. },
  79. labelLine: {
  80. normal: {
  81. show: false
  82. }
  83. },
  84. data: theCurrent,
  85. },
  86. }
  87. function onChange(e) {
  88. UserConversionRate({ conversion: e })
  89. }
  90. const piestyles = {
  91. width: '100%',
  92. height: '400px',
  93. }
  94. return (
  95. <>
  96. <div>
  97. <p style={{ fontSize: '0.12rem', fontWeight: '600' }}>转化率</p>
  98. <Select
  99. style={{ width: 200 }}
  100. placeholder="授权手机"
  101. onChange={onChange}
  102. >
  103. <Select.Option value="authorization_phone">授权手机</Select.Option>
  104. <Select.Option value="building_save">项目收藏</Select.Option>
  105. <Select.Option value="building_share">项目转发</Select.Option>
  106. <Select.Option value="activity_save">活动收藏</Select.Option>
  107. <Select.Option value="activity_share">活动转发</Select.Option>
  108. <Select.Option value="news_save">资讯收藏</Select.Option>
  109. <Select.Option value="news_share">资讯转发</Select.Option>
  110. <Select.Option value="activity_sign">活动报名</Select.Option>
  111. </Select>
  112. <EChart options={options} style={piestyles} />
  113. </div>
  114. </>
  115. )
  116. }
  117. export default UserSource