dingxin 5 years ago
parent
commit
431d783894
1 changed files with 46 additions and 26 deletions
  1. 46
    26
      src/pages/indexEcharts/components/UserConversion.jsx

+ 46
- 26
src/pages/indexEcharts/components/UserConversion.jsx View File

@@ -13,22 +13,23 @@ import styles from '../styles.less'
13 13
 const UserSource = props => {
14 14
 
15 15
   const [theCurrent, setTheCurrent] = useState({ records: [] })
16
-
16
+  const [conversionRate, setConversionRate] = useState(0)
17 17
   useEffect(() => {
18 18
     UserConversionRate({ conversion: 'authorization_phone' })
19 19
   }, [])
20 20
 
21
- function UserConversionRate(params) {
22
-   
23
-      request({
24
-        ...apis.indexEcharts.userConversion,
25
-        params,
26
-      }).then(data => {
27
-        setDataset(data, params.conversion)
28
-      })
21
+  function UserConversionRate (params) {
22
+
23
+    request({
24
+      ...apis.indexEcharts.userConversion,
25
+      params,
26
+    }).then(data => {  
27
+      console.log(data.data_count.registeredCount/data.data_count.pvNum,'1241234')
28
+      setDataset(data, params.conversion)
29
+    })
29 30
   }
30 31
 
31
- function setDataset(data, theStatis) {
32
+  function setDataset (data, theStatis) {
32 33
     const { pvNum, ...other } = data.data_count
33 34
 
34 35
     // 获取第一个值
@@ -41,6 +42,8 @@ const UserSource = props => {
41 42
     if (pvNum < num) {
42 43
       setTheCurrent([])
43 44
     } else {
45
+
46
+      setConversionRate(num/pvNum)
44 47
       setTheCurrent([
45 48
         { name: getStatisName(theStatis), value: num },
46 49
         { name: '其余', value: pvNum - num },
@@ -48,34 +51,51 @@ const UserSource = props => {
48 51
     }
49 52
   }
50 53
 
51
-  function getStatisName(theStatis) {
52
-     const statisTypes = [
53
-    { label: '授权手机', value: 'authorization_phone' },
54
-    { label: '项目收藏', value: 'building_save' },
55
-    { label: '项目转发', value: 'building_share' },
56
-    { label: '活动收藏', value: 'activity_save' },
57
-    { label: '活动转发', value: 'activity_share' },
58
-    { label: '资讯收藏', value: 'news_save' },
59
-    { label: '资讯转发', value: 'news_share' },
60
-    { label: '活动报名', value: 'activity_sign' },
61
-
62
-  ]
54
+  function getStatisName (theStatis) {
55
+    const statisTypes = [
56
+      { label: '授权手机', value: 'authorization_phone' },
57
+      { label: '项目收藏', value: 'building_save' },
58
+      { label: '项目转发', value: 'building_share' },
59
+      { label: '活动收藏', value: 'activity_save' },
60
+      { label: '活动转发', value: 'activity_share' },
61
+      { label: '资讯收藏', value: 'news_save' },
62
+      { label: '资讯转发', value: 'news_share' },
63
+      { label: '活动报名', value: 'activity_sign' },
64
+
65
+    ]
63 66
     return statisTypes.filter(x => x.value === theStatis)[0].label
64 67
   }
65 68
 
66 69
   const options = {
67 70
     legend: {},
68
-    color: ['#8B7FE2', '#DDDDDD'],
71
+    color: ['#FF7E48', '#dcdcdc'],
69 72
     tooltip: {},
70 73
     series: {
71 74
       type: 'pie',
72 75
       name: '转化率',
73 76
       radius: ['34%', '52%'],
77
+      avoidLabelOverlap: false,
78
+      label: { 
79
+        normal: { 
80
+          show: true,
81
+          position: 'center',
82
+          color: '#666666',
83
+          fontSize: 24,
84
+          fontWeight: 'bold',
85
+          formatter: `${(conversionRate*100).toFixed(2) === 'NaN' ? 0 : (conversionRate*100).toFixed(2) }%`, // {b}:数据名; {c}:数据值; {d}:百分比,可以自定义显示内容,
86
+        }
87
+      },
88
+      labelLine: {
89
+        normal: {
90
+          show: false
91
+        }
92
+      },
93
+
74 94
       data: theCurrent,
75 95
     },
76 96
   }
77 97
 
78
-  function onChange(e) {
98
+  function onChange (e) {
79 99
     UserConversionRate({ conversion: e })
80 100
   }
81 101
   const piestyles = {
@@ -86,7 +106,7 @@ const UserSource = props => {
86 106
   return (
87 107
     <>
88 108
       <div>
89
-      <p style={{ fontSize: '0.12rem', fontWeight: '600' }}>转化率</p>
109
+        <p style={{ fontSize: '0.12rem', fontWeight: '600' }}>转化率</p>
90 110
 
91 111
         <Select
92 112
           style={{ width: 200 }}
@@ -110,6 +130,6 @@ const UserSource = props => {
110 130
 
111 131
     </>
112 132
   )
113
- }
133
+}
114 134
 
115 135
 export default UserSource