吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<template>
    <el-dialog
        class="gd-dialog"
        v-model="visible"
        :title="titleEnum[dialogMode]"
        @closed="visible = false"
        width="80%"
        destroy-on-close
        :close-on-click-modal="false"
    >
        <div class="content" style="display: flex">
            <div class="processBox" v-if="dialogMode !== 'add'">
                <div class="detail-title">工单记录</div>
                <div class="process">
                    <OrderStepBar :processList="processList" />
                </div>
            </div>
            <div class="leftBox">
                <div v-if="dialogReadonly">
                    <div class="detail-title">工单详情</div>
                    <el-row class="detail-row-view">
                        <el-col :span="12">
                            <div class="label">工单名称</div>
                            <div class="val">{{ formData.workOrderName }}</div>
                        </el-col>
                        <el-col :span="12">
                            <div class="label">工单类型</div>
                            <div class="val">{{ getDictLabel(formData.workOrderType, dictObj.workOrderType) }}</div>
                        </el-col>
                        <el-col :span="12">
                            <div class="label">执行时间范围</div>
                            <div class="val">
                                {{ dayjs(formData.executeStartTime).format('YYYY-MM-DD') }} ~
                                {{ dayjs(formData.executeEndTime).format('YYYY-MM-DD') }}
                            </div>
                        </el-col>
                        <el-col :span="12">
                            <div class="label">设备需求</div>
                            <div class="val">{{ getDictLabel(formData.deviceLoadDemand, dictObj.deviceLoadDemand) }}</div>
                        </el-col>
                        <el-col :span="24">
                            <div class="label">工单备注</div>
                            <div class="val">{{ formData.remark }}</div>
                        </el-col>
                    </el-row>
                    <div class="detail-title" :style="{ marginTop: pxToRem(20) }">已选设备</div>
                    <el-table class="setHeight gd-dialog-table" ref="deviceTableRef" :data="deviceList" row-key="id">
                        <el-table-column type="index" label="序号" />
                        <el-table-column prop="nickname" label="设备名称" />
                        <el-table-column prop="deviceName" label="设备型号" />
                        <el-table-column prop="devicePayload" label="设备负载" />
                    </el-table>
                    <template v-if="hasPatrolTaskList">
                        <div class="detail-title" :style="{ marginTop: pxToRem(20) }">巡查任务名称</div>
                        <el-table class="setHeight gd-dialog-table" :data="patrolTaskList" row-key="id">
                            <el-table-column prop="patrolTaskName" show-overflow-tooltip label="巡查任务名称" />
                            <el-table-column prop="patrolTaskType" show-overflow-tooltip label="巡查任务类型">
                                <template v-slot="{ row }">
                                    {{ getDictLabel(row.patrolTaskType, dictObj.workOrderType) }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="taskStatus" show-overflow-tooltip label="任务状态">
                                <template v-slot="{ row }">
                                    {{ getDictLabel(row.taskStatus, dictObj.taskStatus) }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="executeTime" show-overflow-tooltip label="任务执行时间" />
                            <el-table-column prop="recommendFlyerName" show-overflow-tooltip label="选择飞手" />
                            <el-table-column prop="deviceName" show-overflow-tooltip label="选择设备" />
                        </el-table>
                    </template>
                </div>
                <el-form
                    class="gd-dialog-form"
                    v-else
                    ref="formRef"
                    :model="formData"
                    :rules="rules"
                    :disabled="dialogReadonly"
                    label-width="90px"
                >
                    <div class="detail-title">工单详情</div>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="工单名称" prop="workOrderName">
                                <el-input class="gd-input" v-model="formData.workOrderName" placeholder="请输入" clearable />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工单类型" prop="workOrderType">
                                <el-select
                                    class="gd-select"
                                    popper-class="gd-select-popper"
                                    v-model="formData.workOrderType"
                                    placeholder="请选择"
                                    clearable
                                >
                                    <el-option
                                        v-for="item in dictObj.workOrderType"
                                        :key="item.dictKey"
                                        :label="item.dictValue"
                                        :value="item.dictKey"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="执行时间" prop="executeStartTime">
                                <el-date-picker
                                    class="gd-date-picker"
                                    v-model="dateRange"
                                    type="daterange"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备需求" prop="deviceLoadDemand">
                                <el-select
                                    class="gd-select"
                                    popper-class="gd-select-popper"
                                    v-model="formData.deviceLoadDemand"
                                    placeholder="请选择"
                                    clearable
                                    @change="loadDemandChange"
                                >
                                    <el-option
                                        v-for="item in dictObj.deviceLoadDemand"
                                        :key="item.dictKey"
                                        :label="item.dictValue"
                                        :value="item.dictKey"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="工单备注" prop="remark">
                                <el-input
                                    class="gd-input"
                                    type="textarea"
                                    :rows="3"
                                    v-model="formData.remark"
                                    placeholder="请输入"
                                    clearable
                                />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="detail-title" :style="{ marginTop: pxToRem(20) }">
                    <span class="required-star" v-if="!dialogReadonly">*</span>
                    工单执行范围
                </div>
                <CommonCesiumMap
                    ref="mapRef"
                    class="gd-cesium"
                    :active="visible"
                    :flat-mode="false"
                    :terrain="true"
                    :layer-mode="4"
                    :boundary="false"
                    :zoomToBoundary="false"
                    @ready="mapReady"
                />
            </div>
            <div class="rightBox" v-if="!dialogReadonly">
                <div class="detail-title">
                    <span class="required-star" v-if="!dialogReadonly">*</span>
                    推荐设备
                </div>
                <el-table
                    class="separateTable"
                    :empty-text="
                        formData.deviceLoadDemand && pointList.length ? '暂无数据' : '请先选择设备需求并在地图上绘制工单范围'
                    "
                    ref="deviceTableRef"
                    :data="formData.deviceLoadDemand && pointList.length ? deviceList : []"
                    row-key="id"
                    @selection-change="handleDeviceSelectionChange"
                >
                    <el-table-column type="selection" width="55" :reserve-selection="true" />
                    <el-table-column prop="nickname" label="设备名称" />
                    <el-table-column prop="deviceName" label="设备型号" />
                    <el-table-column prop="devicePayload" label="设备负载" />
                </el-table>
            </div>
        </div>
 
        <template #footer>
            <el-button v-if="['11', '21', '23', '31', '60'].includes(gdStatus)" @click="viewDescription" color="#F2F3F5">
                {{ gdStatusObj[gdStatus]?.reason }}
            </el-button>
 
            <template v-if="!suddenlyEdit">
                <el-button
                    @click="addDescription"
                    v-if="['20'].includes(gdStatus) && permission.order_applyCancel"
                    color="#F2F3F5"
                >
                    申请取消
                </el-button>
                <el-button
                    color="#4C34FF"
                    @click="requestModification"
                    v-if="['20'].includes(gdStatus) && permission.order_applyEdit"
                >
                    申请修改
                </el-button>
            </template>
            <el-button
                v-if="(['11'].includes(gdStatus) || suddenlyEdit || !formData.id) && permission.order_release"
                :loading="submitting"
                :disabled="submitting"
                color="#4C34FF"
                @click="handleSubmit"
            >
                {{ gdStatus === '11' || !gdStatus ? '发布' : '提交修改' }}
            </el-button>
            <el-button v-if="gdStatus === '50' && permission.order_settlement" @click="addDescription" color="#F2F3F5">
                结算
            </el-button>
            <template v-if="permission.order_controlOrder">
                <el-button v-if="gdStatus === '10'" @click="addDescription" color="#F2F3F5">拒绝接单</el-button>
                <el-button v-if="gdStatus === '10'" @click="statusChange(1)" color="#4C34FF">接单</el-button>
            </template>
            <template v-if="permission.order_controlEdit">
                <el-button v-if="gdStatus === '22'" @click="statusChange(8)" color="#F2F3F5">驳回</el-button>
                <el-button v-if="gdStatus === '22'" @click="statusChange(7)" color="#4C34FF">同意</el-button>
            </template>
            <template v-if="permission.order_controlCancel">
                <el-button v-if="gdStatus === '21'" @click="statusChange(6)" color="#F2F3F5">驳回</el-button>
                <el-button v-if="gdStatus === '21'" @click="statusChange(5)" color="#4C34FF">通过</el-button>
            </template>
            <el-button v-if="gdStatus === '30' && permission.order_applyNegotiation" @click="addDescription" color="#4C34FF">
                协商修改
            </el-button>
            <el-button
                v-if="gdStatus === '31' && permission.order_controlNegotiation"
                @click="statusChange(10)"
                color="#4C34FF"
            >
                同意
            </el-button>
        </template>
 
        <RefuseOrderDialog
            ref="refuseOrderDialogRef"
            v-if="rejectVisible"
            v-model="rejectVisible"
            @success="rejectSuccess"
        />
    </el-dialog>
</template>
 
<script setup>
import { computed, ref, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import { dateRangeFormat, fieldRules, flyVisual, geomAnalysis, getDictLabel } from '@ztzf/utils'
import {
    gdWorkOrderDetailApi,
    gdWorkOrderFlowListApi,
    gdWorkOrderHandleStatusApi,
    gdWorkOrderSaveApi,
} from './orderManageApi'
import { gdManageDeviceListApi } from './gdManageDeviceApi'
import { cartesian3Convert } from '@/utils/cesium/mapUtil'
import * as Cesium from 'cesium'
import { DrawPolygon } from '@ztzf/utils'
import { pxToRem } from '@/utils/rem'
import dayjs from 'dayjs'
import RefuseOrderDialog from '@/views/orderView/orderManage/orderManage/RefuseOrderDialog.vue'
import CommonCesiumMap from '@/components/map-container/common-cesium-map.vue'
import { gdPatrolTaskPageApi } from '@/views/orderView/orderManage/inspectionRequest/inspectionRequestApi'
import { Check } from '@element-plus/icons-vue'
import droneIcon from '@/assets/images/orderView/orderManage/drone.png'
import droneActiveIcon from '@/assets/images/orderView/orderManage/droneActive.png'
import { useStore } from 'vuex'
import OrderStepBar from '@/views/orderView/orderManage/orderManage/OrderStepBar.vue'
const store = useStore()
const permission = computed(() => store.state.user.permission)
 
// 初始化表单数据
const initForm = () => ({
    workOrderName: '',
    workOrderType: '',
    executeStartTime: '',
    executeEndTime: '',
    deviceLoadDemand: '',
    remark: '',
    geom: '',
    recommendDeviceIds: '',
})
 
const mapRef = ref(null)
const rejectVisible = ref(false)
const dictObj = inject('dictObj')
const dateRange = ref([])
const patrolTaskList = ref([])
const emit = defineEmits(['success'])
const formRef = ref(null) // 表单实例
const formData = ref(initForm()) // 表单数据
const visible = defineModel() // 弹框显隐
const dialogMode = ref('add') // 弹框模式
const submitting = ref(false) // 提交中
const dialogReadonly = computed(() => dialogMode.value === 'view')
const titleEnum = ref({ edit: '编辑', view: '查看', add: '新增' })
const deviceList = ref([]) // 设备列表
const selectedDevices = ref([]) // 选中的设备
const deviceTableRef = ref(null) // 设备表格实例
const refuseOrderDialogRef = ref(null)
let viewer
let drawPolygonExample
let pointList = ref([])
const suddenlyEdit = ref(false)
const processList = ref([])
let viewPlane
const hasPatrolTaskList = computed(() => ['30', '40', '50', '60'].includes(String(formData.value.workOrderStatus)))
 
const gdStatusObj = {
    '10': { reason: '拒单原因', operationType: '2', title: '拒绝接单' },
    '11': { reason: '拒单原因' },
    '20': { reason: '原因', operationType: '3', title: '申请取消' },
    '21': { reason: '取消原因' },
    '23': { reason: '取消原因' },
    '30': { reason: '修改原因', operationType: '9', title: '协商修改' },
    '31': { reason: '修改原因' },
    '40': { reason: '' },
    '50': { reason: '情况说明', operationType: '11', title: '结算' },
    '60': { reason: '情况说明' },
}
 
// 工单状态:0草稿、10发布中_接单中、11发布中_拒绝接单、20响应中_待拆分、21响应中_申请取消、22响应中_申请修改、23响应中_已取消、
// 30执行中_待全部完成、31执行中_协商修改、40完成待验_待全部验收、50验收通过_待结算、60结算完成_已结算
const gdStatus = computed(() => formData.value?.workOrderStatus)
 
const rules = {
    workOrderName: fieldRules(true, 50),
    workOrderType: fieldRules(true),
    executeStartTime: fieldRules(true),
    deviceLoadDemand: fieldRules(true),
}
 
// 操作类型:1接单,2拒接接单,3申请取消,4申请修改, 5同意取消
// 6不同意取消 7.同意修改 8.不同意修改 9.协商修改,10:同意协商修改,11.结算
function statusChange(operationType) {
    gdWorkOrderHandleStatusApi({
        operationType: operationType,
        workOrderId: formData.value.id,
    }).then(res => {
        visible.value = false
        emit('success')
    })
}
 
// 申请修改按钮
async function requestModification() {
    suddenlyEdit.value = true
    dialogMode.value = 'edit'
    await getDeviceList()
    nextTick(() => {
        syncSelection()
        viewPlane && viewer.entities.remove(viewPlane)
        editPolygon()
    })
}
 
// 填写说明弹框回调
function rejectSuccess() {
    visible.value = false
    emit('success')
}
 
// 填写说明
function addDescription() {
    rejectVisible.value = true
    nextTick(() => {
        refuseOrderDialogRef.value.open({
            mode: 'add',
            row: formData.value,
            type: gdStatusObj[gdStatus.value].operationType,
            formLabel: gdStatusObj[gdStatus.value].reason,
            title: gdStatusObj[gdStatus.value]?.title || '新增',
        })
    })
}
 
// 查看说明
function viewDescription() {
    rejectVisible.value = true
    nextTick(() => {
        refuseOrderDialogRef.value.open({
            mode: 'view',
            row: formData.value,
            formLabel: gdStatusObj[gdStatus.value].reason,
        })
    })
}
 
// 获取推荐设备列表
async function getDeviceList() {
    try {
        const str = [...pointList.value, pointList.value[0]].map(item => `${item.longitude} ${item.latitude}`).join(',')
        let geom = `POLYGON((${str}))`
        const res = await gdManageDeviceListApi({
            deviceIds: dialogMode.value === 'add' ? '' : formData.value.recommendDeviceIds,
            devicePayload: formData.value?.deviceLoadDemand,
            geom: geom,
        })
        deviceList.value = res?.data?.data ?? []
    } catch (error) {
        console.error('获取设备列表失败:', error)
    }
}
 
// 设备需求变化
async function loadDemandChange() {
    formData.value.recommendDeviceIds = ''
    selectedDevices.value = []
    await getDeviceList()
    syncSelection()
}
 
// 设备选择变化
function handleDeviceSelectionChange(rows) {
    selectedDevices.value = rows
    formData.value.recommendDeviceIds = rows.map(item => item.id).join(',')
}
 
// 提交新增/编辑
async function handleSubmit() {
    const isValid = await formRef.value?.validate().catch(() => false)
    if (!isValid) return
    if (!pointList.value.length) {
        return ElMessage.warning('请绘制范围')
    }
    if (!formData.value.recommendDeviceIds) {
        return ElMessage.warning('请选择设备')
    }
    submitting.value = true
    try {
        const str = [...pointList.value, pointList.value[0]].map(item => `${item.longitude} ${item.latitude}`).join(',')
        formData.value.geom = `POLYGON((${str}))`
        if (!formData.value.id) {
            formData.value.workOrderStatus = '10'
        }
        await gdWorkOrderSaveApi(formData.value)
        ElMessage.success(dialogMode.value === 'add' ? '新增成功' : '更新成功')
        visible.value = false
        emit('success')
    } finally {
        submitting.value = false
    }
}
 
// 加载时间线list
function loadList() {
    gdWorkOrderFlowListApi({ workOrderId: formData.value.id, type: '0' }).then(res => {
        processList.value = res.data.data
    })
}
 
// 加载详情
async function loadDetail() {
    if (!formData.value.id) return
    loadList()
    const res = await gdWorkOrderDetailApi({ id: formData.value.id })
    formData.value = res?.data?.data ?? {}
    dateRange.value = [formData.value.executeStartTime, formData.value.executeEndTime]
}
 
// 新增模式绘制
function addPolygon() {
    drawPolygonExample = new DrawPolygon(viewer)
    drawPolygonExample.initHandler(viewer)
    drawPolygonExample.subscribe('getPolygonPositions', drawFinished)
}
 
// 绘制完成回调
const drawFinished = async data => {
    pointList.value = _.cloneDeep(data).map(item => {
        const val = cartesian3Convert(item, viewer)
        return { ...val, lng: val.longitude, lat: val.latitude }
    })
    formData.value.recommendDeviceIds = ''
    selectedDevices.value = []
    await getDeviceList()
    syncSelection()
}
 
// 编辑面
function editPolygon() {
    if (!formData.value?.geom) return
    pointList.value = geomAnalysis(formData.value.geom)
    drawPolygonExample?.destroy()
    drawPolygonExample = new DrawPolygon(viewer)
    let noClosedList = _.cloneDeep(pointList.value)
    noClosedList.pop()
    drawPolygonExample.initPolygon(
        viewer,
        noClosedList.map(item => ({ lng: item.longitude, lat: item.latitude }))
    )
    drawPolygonExample.subscribe('getPolygonPositions', drawFinished)
}
 
// 查看面
function viewPolygon() {
    if (!formData.value?.geom) return
    pointList.value = geomAnalysis(formData.value.geom)
    const result = pointList.value.map(item => [item.longitude, item.latitude]).flat()
    viewPlane = viewer.entities?.add({
        customType: 'control_group',
        position: Cesium.Cartesian3.fromDegrees(result[0], result[1]),
        polygon: {
            hierarchy: Cesium.Cartesian3.fromDegreesArray(result),
            material: Cesium.Color.fromBytes(45, 140, 240, 99),
            outline: false,
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        },
        polyline: {
            positions: Cesium.Cartesian3.fromDegreesArray(result),
            clampToGround: true,
            width: 2,
            material: Cesium.Color.fromBytes(45, 140, 240, 255),
        },
    })
    flyVisual({
        positionsData: pointList.value.map(i => [i.longitude, i.latitude, i.height || 0]),
        viewer,
    })
}
 
// 回显选中设备
function syncSelection() {
    if (!deviceTableRef.value) return
    deviceTableRef.value.clearSelection()
    const deviceIds = formData.value.recommendDeviceIds.split(',')
    deviceList.value.forEach(device => {
        if (deviceIds.includes(String(device.id))) {
            deviceTableRef.value?.toggleRowSelection(device, true)
        }
    })
}
 
// 获取巡检任务
function gdPatrolTaskPage() {
    gdPatrolTaskPageApi({ current: 1, size: 1000, workOrderId: formData.value.id }).then(res => {
        patrolTaskList.value = res.data.data.records || []
    })
}
 
//  渲染
function renderingAllDevice(list) {
    list.forEach(item => {
        if (!item.longitude || !item.latitude) return
        const position = Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude)
        viewer.entities.add({
            position: position,
            billboard: {
                image: droneIcon,
                width: 30,
                height: 30,
                verticalOrigin: Cesium.VerticalOrigin.CENTER,
            },
            label: {
                text: item.nickname,
                font: '12px/1.5 Microsoft YaHei',
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                outlineWidth: 2,
                outlineColor: Cesium.Color.WHITE,
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                pixelOffset: new Cesium.Cartesian2(0, -20),
            },
        })
    })
}
 
// 打开弹框
async function open({ mode = 'add', row } = {}) {
    dialogMode.value = mode
    initMap()
    const allDeviceRes = await gdManageDeviceListApi()
    formData.value = dialogMode.value === 'add' ? initForm() : row
    renderingAllDevice(allDeviceRes?.data?.data || [])
    if (dialogMode.value === 'add') {
        addPolygon()
    } else {
        await loadDetail()
        hasPatrolTaskList.value && gdPatrolTaskPage()
        dialogMode.value === 'edit' ? editPolygon() : viewPolygon()
    }
 
    await nextTick()
    await getDeviceList()
    syncSelection()
    highlightSelectedDevices()
}
 
// 初始化地图实例
function initMap() {
    if (viewer) return
    const map = mapRef.value?.getMap()
    viewer = map?.viewer || null
}
 
// 高亮选中的设备
function highlightSelectedDevices() {
    const selectedIds = (formData.value.recommendDeviceIds || '').split(',').filter(Boolean)
    if (!viewer?.entities) return
    viewer.entities.values.forEach(entity => {
        const image = entity.billboard?.image?._value
        if ((image === droneIcon || image === droneActiveIcon) && entity.label) {
            const device = deviceList.value.find(d => d.nickname === entity.label.text._value)
            entity.billboard.image = device && selectedIds.includes(String(device.id)) ? droneActiveIcon : droneIcon
        }
    })
}
 
watch(() => formData.value.recommendDeviceIds, highlightSelectedDevices)
 
watch(
    () => dateRange.value,
    newVal => {
        const range = dateRangeFormat(dateRange.value)
        formData.value.executeStartTime = range[0]
        formData.value.executeEndTime = range[1]
    }
)
 
// 地图加载完毕
function mapReady() {
    dialogMode.value === 'add' && mapRef.value.flyBoundary()
}
 
defineExpose({ open })
</script>
 
<style lang="scss" scoped>
.separateTable {
    height: 0;
    flex: 1;
    :deep() {
        .el-scrollbar__view {
            height: 100%;
        }
        .el-table__empty-text {
            line-height: normal;
        }
    }
}
.content {
    display: flex;
    gap: 0 20px;
    height: 680px;
 
    .leftBox {
        width: 0;
        flex: 1;
        display: flex;
        overflow: auto;
        flex-direction: column;
 
        .gd-cesium {
            width: 100%;
            min-height: 360px;
            flex: 1;
        }
    }
 
    .rightBox {
        width: 350px;
        display: flex;
        flex-direction: column;
        .title {
            font-weight: 500;
            font-size: 14px;
            color: #272e37;
        }
    }
 
    .processBox {
        display: flex;
        flex-direction: column;
 
        .process {
            height: 100%;
            padding: 12px 16px 24px 16px;
            width: 312px;
            border: 1px solid #e4e4e4;
            border-radius: 8px;
            background: #fff;
            overflow: auto;
        }
    }
}
 
.tipSelect {
    text-align: center;
    height: 200px;
    line-height: 200px;
}
 
.required-star {
    color: #f56c6c;
    margin-right: 4px;
}
</style>