吉安感知网项目-前端
罗广辉
2026-06-06 2fa2c869c3613bc3d7af6baf13eb7fab2a9aa179
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<template>
  <div class="outcome-container">
    <el-form ref="searchRef" :model="searchParams" class="gd-search-form">
      <el-form-item label="巡查任务名称" prop="patrolTaskIds">
        <el-select
          class="gd-select"
              popper-class="gd-select-popper"
          collapse-tags
          collapse-tags-tooltip
          v-model="searchParams.patrolTaskIds"
          placeholder="请选择"
          clearable
 
          multiple
          @change="handleSearch"
        >
          <el-option
            v-for="item in patrolTaskList"
            :key="item.id"
            :label="item.patrolTaskName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
 
      <el-form-item >
        <el-button :icon="RefreshRight" @click="resetForm"></el-button>
        <el-button :icon="Search" color="#383874" @click="handleSearch"></el-button>
        <el-button :icon="Download" color="#4C34FF" :loading="exportLoading" :disabled="exportLoading" @click="handleBatchDownload">下载</el-button>
 
      </el-form-item>
    </el-form>
 
    <div class="gd-table-container" v-loading="loading">
      <div class="gd-table-content gd-table-content-bg">
        <el-table class="gd-table" :data="list" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="46" />
          <el-table-column type="index" label="序号" width="80" />
          <el-table-column label="图片/视频" >
            <template v-slot="{ row }">
                            <el-image
                                v-if="row.attachmentType === 1 || row.attachmentType === 2"
                                :src="row.attachmentType === 1 ? row.resultUrl : row.aiImg"
                                :preview-src-list="[row.attachmentType === 1 ? row.resultUrl : row.aiImg]"
                                fit="cover"
                    style="width: 80px; height: 80px"
                    preview-teleported
                            />
                            <div class="video-btn" v-if="row.attachmentType === 3 && row.resultUrl" @click="videoClick(row)">
                                <el-icon :size="30" color="#fff">
                                    <VideoPlay />
                                </el-icon>
                            </div>
            </template>
          </el-table-column>
          <el-table-column prop="patrolTaskName" show-overflow-tooltip label="巡查任务名称" />
          <el-table-column prop="shootTime" show-overflow-tooltip label="拍摄时间" />
          <el-table-column label="操作" class-name="operation-btns" width="120">
            <template v-slot="{ row }">
              <!-- <el-link type="primary" @click="handleDownload(row)">下载</el-link> -->
              <el-link type="primary" @click="handleDelete(row)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
 
      <div class="gd-pagination-parent">
        <el-pagination
          popper-class="gd-select-popper"
          v-model:current-page="searchParams.current"
          v-model:page-size="searchParams.size"
          layout="total, prev, pager, next, sizes"
          :total="total"
          @change="getList"
        />
      </div>
    </div>
  </div>
 <VideoPlayDialog
     ref="videoPlayDialogRef"
     v-if="VideoShow"
     v-model="VideoShow"
     :playUrl="currentVideo.resultUrl"
         >
 </VideoPlayDialog>
</template>
 
<script setup>
import {gdTaskResultPageApi, gdTaskResultDownloadApi, gdTaskResultRemoveApi,listByWorkOrderId}from './orderManageApi'
import { Search, RefreshRight, Download } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getAiImg, getDictLabel } from '@ztzf/utils'
import dayjs from 'dayjs'
import VideoPlayDialog from '@/components/VideoPlayDialog.vue'
 
const props = defineProps({
  workOrderId: {
    type: String,
    required: true
  }
})
 
const emit = defineEmits(['success'])
 
// 初始化查询参数
const initSearchParams = () => ({
  current: 1,
  size: 10,
  patrolTaskIds: []
})
 
const searchParams = ref(initSearchParams())
const total = ref(0)
const loading = ref(true)
const list = ref([])
const searchRef = ref(null)
const selectedRows = ref([])
const patrolTaskList = ref([])
const dictObj = inject('dictObj')
// 导出加载状态
const exportLoading = ref(false)
// 获取巡查任务列表
async function getPatrolTaskList() {
  try {
    const res = await listByWorkOrderId({ workOrderId: props.workOrderId })
    patrolTaskList.value = res?.data?.data || []
  } catch (error) {
    console.error('获取巡查任务列表失败:', error)
  }
}
 
// 获取成果数据列表
async function getList() {
  loading.value = true
  try {
    const res = await gdTaskResultPageApi({
      ...searchParams.value,
      workOrderId: props.workOrderId,
      patrolTaskIds: searchParams.value.patrolTaskIds.length
        ? searchParams.value.patrolTaskIds.join(',')
        : ''
    })
        list.value = await Promise.all(
            (res?.data?.data?.records ?? []).map(async item => {
                if (item.attachmentType !== 2) return item
                const aiImg = await getAiImg(item.resultUrl,item.geojson)
                return { ...item, aiImg }
            })
        )
    total.value = res?.data?.data?.total || 0
  } finally {
    loading.value = false
  }
}
 
// 搜索
function handleSearch() {
  searchParams.value.current = 1
  getList()
}
 
// 重置搜索
function resetForm() {
    searchRef.value?.resetFields()
    searchParams.value = { ...initSearchParams() }
    selectedRows.value = []
    getList()
}
 
// 选择变化
function handleSelectionChange(rows) {
  selectedRows.value = rows
}
 
// 下载
async function handleDownload(row) {
  if (!row.id) {
    ElMessage.warning('暂无数据可下载')
    return
  }
    exportLoading.value = true
  try {
    const res = await gdTaskResultDownloadApi({ ids: row.id })
    const blob = res.data
    const url = URL.createObjectURL(blob)
    const a = document.createElement('a')
    a.href = url
    a.download = `成果数据_${row.patrolTaskName}_${dayjs().format('YYYYMMDDHHmmss')}`
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    URL.revokeObjectURL(url)
    ElMessage.success('下载成功')
  } catch (error) {
    console.error('下载失败:', error)
    ElMessage.error('下载失败')
  }finally {
    exportLoading.value = false
  }
}
 
// 批量下载
async function handleBatchDownload() {
  if (selectedRows.value.length === 0) {
    ElMessage.warning('请选择要下载的数据')
    return
  }
  const ids = selectedRows.value.map(row => row.id).join(',')
  exportLoading.value = true
  try {
    const res = await gdTaskResultDownloadApi({ ids })
    const blob = res.data
    const url = URL.createObjectURL(blob)
    const a = document.createElement('a')
    a.href = url
    a.download = `成果数据_${dayjs().format('YYYYMMDDHHmmss')}`
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    URL.revokeObjectURL(url)
    ElMessage.success('下载完成')
  } catch (error) {
    console.error('下载失败:', error)
    ElMessage.error('下载失败')
  } finally {
    exportLoading.value = false
  }
}
 
// 删除
async function handleDelete(row) {
  await ElMessageBox.confirm('确认删除该条记录吗?', '提示', {
    type: 'warning',
    customClass: 'gd-confirm-custom',
    confirmButtonClass: 'gd-confirm-button',
    cancelButtonClass: 'gd-confirm-cancel-button',
  })
  try {
    const res = await gdTaskResultRemoveApi({ ids: row.id })
    if (res?.data?.success) {
      ElMessage.success('删除成功')
      getList()
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}
 
// 点击视频
let VideoShow = ref(false)
let currentVideo = ref({})
function videoClick(row) {
    VideoShow.value = true
  currentVideo.value = row
}
 
// 监听 workOrderId 变化
watch(
    () => props.workOrderId,
    (newWorkOrderId) => {
        if (newWorkOrderId) {
            resetForm()
            getList()
            getPatrolTaskList()
        }
    },
    { immediate: true }
)
 
onMounted(() => {
 
})
</script>
 
<style scoped lang="scss">
.outcome-container {
  height: 680px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
 
  .gd-table-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
 
    .gd-table-content {
      flex: 1;
      overflow: auto;
    }
        .video-btn {
            width: 80px;
            height: 80px;
            background-color: #9E9E9E;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            cursor: pointer;
        }
  }
 
 
}
</style>