Riku
2025-06-09 2547159bbd781c8e1a41ecc939385396c85f9766
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 allTask = ref(null)
  const onFetchAllTask = []
  // 总任务信息
  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
 
        allTask.value = res.data
        if (onFetchAllTask.length > 0) {
          onFetchAllTask.forEach((e) => {
            e(allTask.value)
          })
        }
 
        const data = res.data[0]
        // 存储为全局数据
        setSummary(data)
        // 绘制地图标记
        marks.createLabelMarks(scene_1, unref(data.subTaskSummary), (v) => {
          mapStore.focusMarker = v
        })
        mapUtil.setFitView()
      })
      .finally(() => (subtaskLoading.value = false))
  }
 
  function onAllTaskRefreshed(callback) {
    if (allTask.value != null) {
      callback(taskInfo.value)
    }
    onFetchAllTask.push(callback)
  }
 
  // 设置新的值
  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) {
      callback(summaryMap.value)
      
    }
    onFetchMap.push(callback)
  }
 
  return {
    // taskInfo,
    // summaryList,
    // summaryMap,
    subtaskLoading,
    fetchTopTaskProgress,
    onAllTaskRefreshed,
    setSummary,
    getTaskInfo,
    getSummaryList,
    getSummaryMap
  }
})