charles
2024-04-29 b95cf940af8e01e4eca30b2599b029c2f645bd1e
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
134
135
136
137
138
139
140
141
142
<template>
  <div class="channel-collapse">
    <el-collapse v-model="activeChannel">
      <el-collapse-item v-for="(channel, channelNumber) in channels" :key="channelNumber" :name="String(channelNumber)">
        <template #title>
          <div style="width: 100%; text-align: left" @click="selectChannel(channelNumber)">
            {{ CHANNEL_NAME_MAP[channelNumber] + ' 通道' + ' (' + (channel?.TaskCount ?? 0) + ')' }}
          </div>
        </template>
        <TaskInfo
          v-for="task in channel.Tasks"
          :key="task.Procedure.ID"
          :active="task.Procedure.ID === tasksStore.activeTask?.Procedure.ID"
          :task="task"
          style="margin-bottom: 16px"
          @click="selectTask(task)"
        ></TaskInfo>
 
        <div
          v-show="channel.Tasks?.length && tasksStore.moreBtnStatus?.[channelNumber]"
          class="btn more"
          @click="tasksStore.moreChannelTasksBtn(channelNumber)"
        >
          查看更多
          <el-icon style="margin-left: 6px"><ArrowDownBold /></el-icon>
        </div>
 
        <div
          v-show="channel.TaskCount > 3 && channel.Tasks?.length && !tasksStore.moreBtnStatus?.[channelNumber]"
          class="btn fold"
          @click="tasksStore.foldChannelTasksBtn(channelNumber)"
        >
          收起
          <el-icon style="margin-left: 6px"><ArrowUpBold /></el-icon>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import type { Task, TasksGroupByChannel } from '@/api/task'
import TaskInfo from './TaskInfo.vue'
import { CHANNEL_NAME_MAP } from '@/common/constants'
import { useTasksStore } from '@/stores/tasks'
import { ArrowDownBold, ArrowUpBold } from '@element-plus/icons-vue'
import { isNumber } from 'lodash-es'
import { getTaskInfo } from '@/api'
import type { TaskInfoParams } from '@/api'
import { storeToRefs } from 'pinia'
 
export interface ChannelCollapseProps {
  channels: TasksGroupByChannel
}
 
const props = defineProps<ChannelCollapseProps>()
const activeChannel = ref<string[]>([])
 
const tasksStore = useTasksStore()
const { activeTask } = storeToRefs(tasksStore)
 
watchEffect(() => {
  // 通道数据变化后
  const channelNumbers = Object.keys(props?.channels ?? {}).sort((a, b) => +a - +b)
  activeChannel.value = [...channelNumbers]
})
 
function selectChannel(channelNumber: number) {
  tasksStore.setActiveTask(undefined)
  tasksStore.setActiveChannel(+channelNumber)
}
 
function selectTask(task: Task | undefined) {
  console.log(task, 'iiiiiii')
 
  const params: TaskInfoParams = {
    deviceID: localStorage.getItem('currentDeviceID') || '',
    procedureID: Number(task?.Procedure.ID)
  }
  return getTaskInfo(params)
    .then((res) => {
      tasksStore.setActiveTask(res.data)
      let channel = tasksStore?.activeTask?.Channel
      if (isNumber(channel)) {
        tasksStore.setActiveChannel(channel)
      }
      // taskStore.activeTask?.value = res.data
    })
    .catch((err) => {
      console.error(err)
    })
    .finally(() => {})
  // tasksStore.setActiveTask(task)
}
</script>
 
<style scoped lang="scss">
.channel-collapse {
  color: #fff;
  background-color: transparent;
}
:deep(.el-collapse) {
  border: none;
}
:deep(.el-collapse-item) {
  border: none;
}
:deep(.el-collapse-item__header) {
  color: #fff;
  background-color: transparent;
  font-size: 18px;
  font-weight: 600;
  border: none;
}
:deep(.el-collapse-item__wrap) {
  color: #fff;
  background-color: transparent;
  font-size: 16px;
  border: none;
  font-weight: 600;
}
:deep(.el-collapse-item__content) {
  color: #fff;
  background-color: transparent;
  font-size: 16px;
  font-weight: 600;
}
 
.btn {
  width: 70%;
  height: 50px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(to right, rgb(29, 96, 212) 0%, rgb(47, 122, 251), rgb(29, 96, 212) 100%);
}
</style>