Bläddra i källkod

Merge branch 'main' of http://git.ycjcjy.com/marketing/miniapp into main

1002884655 3 år sedan
förälder
incheckning
9dc8763086

+ 10
- 8
src/components/Chart/index.jsx Visa fil

@@ -1,4 +1,4 @@
1
-import React, { useEffect, useRef, useMemo } from 'react'
1
+import React, { useEffect, useState, useMemo } from 'react'
2 2
 import * as echarts from '@/native/ec-canvas/echarts';
3 3
 
4 4
 function initChart(canvas, width, height, dpr) {
@@ -13,22 +13,24 @@ function initChart(canvas, width, height, dpr) {
13 13
 
14 14
 export default (props) => {
15 15
   const { options } = props
16
-  const chartRef = useRef()
16
+  
17
+  const [chart, setChart] = useState()
18
+
17 19
   const ec = useMemo(() => {
18 20
     const onInit = (...args) => {
19
-      const chart = initChart(...args)
20
-      chartRef.current = chart
21
-      return chart
21
+      const t = initChart(...args)
22
+      setChart(t)
23
+      return t
22 24
     }
23 25
 
24 26
     return { onInit }
25 27
   }, [])
26 28
 
27 29
   useEffect(() => {
28
-    if (options && chartRef.current) {
29
-      chartRef.current.setOption(options);
30
+    if (options && chart) {
31
+      chart.setOption(options);
30 32
     }
31
-  }, [options])
33
+  }, [options, chart])
32 34
 
33 35
   return (
34 36
     <ec-canvas ec={ec} />

+ 11
- 14
src/pages/mine/partnerChannel/hooks/useChart.js Visa fil

@@ -4,25 +4,22 @@ import { fillTime, cutDays, cutMonths } from '../utils'
4 4
 
5 5
 const now = new Date()
6 6
 
7
-export default function useReport(buildingId) {
7
+export default function useReport() {
8 8
   const [statType, setStatType] = useState('day')
9 9
   const [custType, setCustType] = useState('new')
10 10
   const [chartData, setChartData] = useState([])
11 11
 
12 12
   useEffect(() => {
13
-    if (buildingId) {
14
-      const startDate = statType === 'month' ? cutMonths(now, 6) : cutDays(now, 7)
15
-      getChannelLineChat({
16
-        buildingId,
17
-        type: statType,
18
-        customerType: custType,
19
-        startDate: fillTime(startDate.toJSON().substring(0, 10), true),
20
-        endDate: fillTime(now.toJSON().substring(0, 10), false),
21
-      }).then((res) => {
22
-        setChartData(res || [])
23
-      })
24
-    }
25
-  }, [buildingId, statType, custType])
13
+    const startDate = statType === 'month' ? cutMonths(now, 6) : cutDays(now, 7)
14
+    getChannelLineChat({
15
+      type: statType,
16
+      customerType: custType,
17
+      startDate: fillTime(startDate.toJSON().substring(0, 10), true),
18
+      endDate: fillTime(now.toJSON().substring(0, 10), false),
19
+    }).then((res) => {
20
+      setChartData(res || [])
21
+    })
22
+  }, [statType, custType])
26 23
 
27 24
   return [statType, setStatType, custType, setCustType, chartData]
28 25
 }

+ 9
- 12
src/pages/mine/partnerChannel/hooks/useRank.js Visa fil

@@ -4,22 +4,19 @@ import { fillTime } from '../utils'
4 4
 
5 5
 const now = new Date()
6 6
 
7
-export default function useRank(buildingId) {
7
+export default function useRank() {
8 8
   const [rankDateRange, setRankDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
9 9
   const [rankList, setRankList] = useState([])
10 10
 
11 11
   useEffect(() => {
12
-    if (buildingId) {
13
-      const [startDate, endDate] = rankDateRange
14
-      getChannelRank({
15
-        buildingId,
16
-        startDate: fillTime(startDate, true),
17
-        endDate: fillTime(endDate, false),
18
-      }).then((res) => {
19
-        setRankList(res || [])
20
-      })
21
-    }
22
-  }, [buildingId, rankDateRange])
12
+    const [startDate, endDate] = rankDateRange
13
+    getChannelRank({
14
+      startDate: fillTime(startDate, true),
15
+      endDate: fillTime(endDate, false),
16
+    }).then((res) => {
17
+      setRankList(res || [])
18
+    })
19
+  }, [rankDateRange])
23 20
 
24 21
   return [rankDateRange, setRankDateRange, rankList]
25 22
 }

+ 9
- 12
src/pages/mine/partnerChannel/hooks/useReport.js Visa fil

@@ -4,22 +4,19 @@ import { fillTime } from '../utils'
4 4
 
5 5
 const now = new Date()
6 6
 
7
-export default function useReport(buildingId) {
7
+export default function useReport() {
8 8
   const [reportDateRange, setReportDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
9 9
   const [reportInfo, setReportInfo] = useState({})
10 10
 
11 11
   useEffect(() => {
12
-    if (buildingId) {
13
-      const [startDate, endDate] = reportDateRange
14
-      getChannelStatReport({
15
-        buildingId,
16
-        startDate: fillTime(startDate, true),
17
-        endDate: fillTime(endDate, false),
18
-      }).then((res) => {
19
-        setReportInfo(res || {})
20
-      })
21
-    }
22
-  }, [buildingId, reportDateRange])
12
+    const [startDate, endDate] = reportDateRange
13
+    getChannelStatReport({
14
+      startDate: fillTime(startDate, true),
15
+      endDate: fillTime(endDate, false),
16
+    }).then((res) => {
17
+      setReportInfo(res || {})
18
+    })
19
+  }, [reportDateRange])
23 20
 
24 21
   return [reportDateRange, setReportDateRange, reportInfo]
25 22
 }

+ 3
- 15
src/pages/mine/partnerChannel/index.jsx Visa fil

@@ -29,11 +29,9 @@ export default withLayout((props) => {
29 29
   
30 30
   const [showPicker, setShowPicker] = useState(false)
31 31
   const pickerTrigger = useRef()
32
-  const [buildingId, setBuildingId] = useState()
33
-  const [buildingList, setBuildingList] = useState([])
34
-  const [,setRankDateRange, rankList] = useRank(buildingId)
35
-  const [,setReportDateRange, reportInfo] = useReport(buildingId)
36
-  const [statType, setStatType, custType, setCustType, chartData] = useChart(buildingId)
32
+  const [,setRankDateRange, rankList] = useRank()
33
+  const [,setReportDateRange, reportInfo] = useReport()
34
+  const [statType, setStatType, custType, setCustType, chartData] = useChart()
37 35
 
38 36
   const handleMore = () => {
39 37
     Taro.navigateTo({ url: '/pages/mine/myCustomer/index' })
@@ -59,16 +57,6 @@ export default withLayout((props) => {
59 57
     }
60 58
   }
61 59
 
62
-  useEffect(() => {
63
-    fetch({ url: API_GET_AGENT_BUILDINGS }).then((res) => {
64
-      const buildings = res || []
65
-      setBuildingList(buildings)
66
-      if (buildings.length) {
67
-        setBuildingId(buildings[0].buildingId)
68
-      }
69
-    })
70
-  }, [])
71
-
72 60
   return (
73 61
     <view className='Page partnerChannel'>
74 62
       <DateRangePicker visable={showPicker} close={() => setShowPicker(false)} change={handlePickerChange} />