瀏覽代碼

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

1002884655 3 年之前
父節點
當前提交
9dc8763086

+ 10
- 8
src/components/Chart/index.jsx 查看文件

1
-import React, { useEffect, useRef, useMemo } from 'react'
1
+import React, { useEffect, useState, useMemo } from 'react'
2
 import * as echarts from '@/native/ec-canvas/echarts';
2
 import * as echarts from '@/native/ec-canvas/echarts';
3
 
3
 
4
 function initChart(canvas, width, height, dpr) {
4
 function initChart(canvas, width, height, dpr) {
13
 
13
 
14
 export default (props) => {
14
 export default (props) => {
15
   const { options } = props
15
   const { options } = props
16
-  const chartRef = useRef()
16
+  
17
+  const [chart, setChart] = useState()
18
+
17
   const ec = useMemo(() => {
19
   const ec = useMemo(() => {
18
     const onInit = (...args) => {
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
     return { onInit }
26
     return { onInit }
25
   }, [])
27
   }, [])
26
 
28
 
27
   useEffect(() => {
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
   return (
35
   return (
34
     <ec-canvas ec={ec} />
36
     <ec-canvas ec={ec} />

+ 11
- 14
src/pages/mine/partnerChannel/hooks/useChart.js 查看文件

4
 
4
 
5
 const now = new Date()
5
 const now = new Date()
6
 
6
 
7
-export default function useReport(buildingId) {
7
+export default function useReport() {
8
   const [statType, setStatType] = useState('day')
8
   const [statType, setStatType] = useState('day')
9
   const [custType, setCustType] = useState('new')
9
   const [custType, setCustType] = useState('new')
10
   const [chartData, setChartData] = useState([])
10
   const [chartData, setChartData] = useState([])
11
 
11
 
12
   useEffect(() => {
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
   return [statType, setStatType, custType, setCustType, chartData]
24
   return [statType, setStatType, custType, setCustType, chartData]
28
 }
25
 }

+ 9
- 12
src/pages/mine/partnerChannel/hooks/useRank.js 查看文件

4
 
4
 
5
 const now = new Date()
5
 const now = new Date()
6
 
6
 
7
-export default function useRank(buildingId) {
7
+export default function useRank() {
8
   const [rankDateRange, setRankDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
8
   const [rankDateRange, setRankDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
9
   const [rankList, setRankList] = useState([])
9
   const [rankList, setRankList] = useState([])
10
 
10
 
11
   useEffect(() => {
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
   return [rankDateRange, setRankDateRange, rankList]
21
   return [rankDateRange, setRankDateRange, rankList]
25
 }
22
 }

+ 9
- 12
src/pages/mine/partnerChannel/hooks/useReport.js 查看文件

4
 
4
 
5
 const now = new Date()
5
 const now = new Date()
6
 
6
 
7
-export default function useReport(buildingId) {
7
+export default function useReport() {
8
   const [reportDateRange, setReportDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
8
   const [reportDateRange, setReportDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
9
   const [reportInfo, setReportInfo] = useState({})
9
   const [reportInfo, setReportInfo] = useState({})
10
 
10
 
11
   useEffect(() => {
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
   return [reportDateRange, setReportDateRange, reportInfo]
21
   return [reportDateRange, setReportDateRange, reportInfo]
25
 }
22
 }

+ 3
- 15
src/pages/mine/partnerChannel/index.jsx 查看文件

29
   
29
   
30
   const [showPicker, setShowPicker] = useState(false)
30
   const [showPicker, setShowPicker] = useState(false)
31
   const pickerTrigger = useRef()
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
   const handleMore = () => {
36
   const handleMore = () => {
39
     Taro.navigateTo({ url: '/pages/mine/myCustomer/index' })
37
     Taro.navigateTo({ url: '/pages/mine/myCustomer/index' })
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
   return (
60
   return (
73
     <view className='Page partnerChannel'>
61
     <view className='Page partnerChannel'>
74
       <DateRangePicker visable={showPicker} close={() => setShowPicker(false)} change={handlePickerChange} />
62
       <DateRangePicker visable={showPicker} close={() => setShowPicker(false)} change={handlePickerChange} />