riku
2025-04-28 3acec796e54dc2f5e7d93e8ca72db7da9ec46f60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { ref, unref } from 'vue'
import { defineStore } from 'pinia'
import timeUtil from '@/utils/time-util'
import { useMapStore } from '@/stores/map.js'
import taskApi from '@/api/fysp/taskApi.js'
import marks from '@/utils/map/marks.js'
import mapUtil from '@/utils/map/util.js'
import scene_1 from '@/assets/icon/scene_1.png'
 
const mapStore = useMapStore()
 
// 巡查任务
export const useSubtaskStore = defineStore('subtask', () => {
  // 总任务信息
  const taskInfo = ref(null)
  // 当期所有巡查统计信息
  const summaryList = ref([])
  // 每日的巡查统计信息
  const summaryMap = ref(new Map())
  const subtaskLoading = ref(false)
  const onFetchInfo = []
  const onFetchList = []
  const onFetchMap = []
 
  function fetchTopTaskProgress(area) {
    subtaskLoading.value = true
    taskApi.fetchTopTaskProgress(area).then((res) => {
      if (res.data.length == 0) return
      const data = res.data[0]
      // 存储为全局数据
      setSummary(data)
      subtaskLoading.value = false
      // 绘制地图标记
      marks.createLabelMarks(scene_1, unref(data.subTaskSummary), (v) => {
        mapStore.focusMarker = v
      })
      mapUtil.setFitView()
    })
  }
 
  // 设置新的值
  function setSummary(data) {
    taskInfo.value = data
    summaryList.value = data.subTaskSummary
    summaryMap.value.clear()
    data.subTaskSummary.forEach((e) => {
      const tag = timeUtil.formatYMD(e.subtask.planstarttime)
      if (!summaryMap.value.has(tag)) {
        summaryMap.value.set(tag, [])
      }
      summaryMap.value.get(tag).push(e)
    })
    if (onFetchList.length > 0) {
      onFetchList.forEach((e) => {
        if (e.tag) {
          e.fun(summaryMap.value.get(e.tag))
        } else {
          e.fun(summaryList.value)
        }
      })
    }
    if (onFetchMap.length > 0) {
      onFetchMap.forEach((e) => {
        e(summaryMap.value)
      })
    }
    if (onFetchInfo.length > 0) {
      onFetchInfo.forEach((e) => {
        e(taskInfo.value)
      })
    }
  }
 
  function getTaskInfo(callback) {
    if (taskInfo.value == null) {
      onFetchInfo.push(callback)
    } else {
      callback(taskInfo.value)
    }
  }
 
  function getSummaryList(timeTag, callback) {
    if (summaryMap.value.size === 0) {
      onFetchList.push({ tag: timeTag, fun: callback })
    } else {
      if (timeTag) {
        callback(summaryMap.value.get(timeTag))
      } else {
        callback(summaryList.value)
      }
    }
  }
 
  function getSummaryMap(callback) {
    if (summaryMap.value.size === 0) {
      onFetchMap.push(callback)
    } else {
      callback(summaryMap.value)
    }
  }
 
  return {
    // taskInfo,
    // summaryList,
    // summaryMap,
    subtaskLoading,
    fetchTopTaskProgress,
    setSummary,
    getTaskInfo,
    getSummaryList,
    getSummaryMap
  }
})