无人机管理后台前端(已迁走)
shuishen
2025-04-15 df42fa7e97c4a93caa17b2aed5aecdc768d8bbd7
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2025-04-15 20:02:29
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2025-04-15 21:56:14
 * @FilePath: \drone-web-manage\src\views\tickets\orderLog.vue
 * @Description: 
 * 
 * Copyright (c) 2025 by shuishen, All Rights Reserved. 
-->
<template>
    <basic-container>
        <el-tabs v-model="activeTab" @tab-click="handleTabChange">
            <el-tab-pane v-for="tab in tabs" :key="tab.name" :label="`${tab.label} (${tab.count})`" :name="tab.name">
                <div class="tab-content">
                    <!-- 查询条件筛选栏 -->
                    <div class="filter-bar">
                        <el-input v-model="filters.key_word" placeholder="输入工单编号/名称/内容/姓名" class="filter-item" clearable
                            @keyup.enter="handleSearch" />
 
                        <el-select placeholder="请选择所属单位" v-model="filters.create_dept" @change="handleDepartmentChange"
                            class="filter-item" clearable>
                            <el-option v-for="dept in departments" :key="dept.value" :label="dept.label"
                                :value="dept.value" />
                        </el-select>
 
                        <el-date-picker v-model="filters.dateRange" type="datetimerange" range-separator="至"
                            start-placeholder="开始日期" end-placeholder="结束日期" class="filter-item" style="width: 100px" />
                        <el-select v-model="filters.file_id" placeholder="请选择关联航线" class="filter-item" clearable>
                            <el-option v-for="item in wayLineList" :key="item.wayline_id" :label="item.name"
                                :value="item.wayline_id" />
                        </el-select>
 
                        <el-select v-model="filters.ai_types" placeholder="关联算法" class="filter-item" clearable>
                            <el-option v-for="item in ai_types" :key="item.dictKey" :label="item.dictValue"
                                :value="item.dictKey" />
                        </el-select>
 
                        <el-select v-model="filters.type" placeholder="请选择工单类型" class="filter-item" clearable>
                            <el-option v-for="item in types" :key="item.dictValue" :label="item.dictValue"
                                :value="item.dictKey" />
                        </el-select>
 
                        <el-select v-model="filters.status" placeholder="请选择工单状态" class="filter-item" clearable>
                            <el-option v-for="item in statuses" :key="item.value" :label="item.label"
                                :value="item.value" />
 
                        </el-select>
                        <el-date-picker v-model="filters.cycleDateRange" type="datetimerange" range-separator="至"
                            start-placeholder="工单周期开始日期" end-placeholder="工单周期结束时间日期" class="filter-item"
                            style="width: 240px !important" />
                        <el-select v-model="filters.rep_fre_type" placeholder="请选择频次" class="filter-item">
                            <el-option v-for="item in cycles" :key="item" :label="item" :value="item" />
                        </el-select>
                        <el-time-picker style="width: 100px" v-model="filters.deal_time" placeholder="请选择执行时间"
                            prop="deal_time" value-format="HH:mm" :picker-options="{
                                selectableRange: '00:00 - 23:59',
                            }" />
                        <el-col :span="8">
                        </el-col>
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                        <el-button icon="el-icon-refresh" @click="handleReset">重置</el-button>
                    </div>
 
                    <!-- 表格部分 -->
                    <avue-crud :data="tableData" :option="option" v-model:page="page" ref="crud"
                        :table-loading="loading" @current-change="currentChange" @refresh-change="refreshChange"
                        @on-load="onLoad" @search-change="searchChange" @size-change="sizeChange">
                        <template #menu-left>
                            <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建工单</el-button>
                            <el-button type="success" plain icon="el-icon-download" @click="exportData">导出</el-button>
                        </template>
 
                        <template #menu="{ row }">
                            <div v-if="row.status == 1 && userInfo.user_id != row.create_user">
                                <el-button type="text" icon="el-icon-view" @click="handleViewDetail(row)">审核</el-button>
                            </div>
 
                            <div v-if="userInfo.user_id == row.create_user">
                                <!--待审核状态-->
                                <div v-if="row.status == 1">
                                    <el-button type="text" icon="el-icon-view"
                                        @click="orderLogRecall(row.id)">撤回</el-button>
                                </div>
                                <!--已驳回-->
                                <div v-if="row.status == 2">
                                    <el-button type="text" icon="el-icon-view"
                                        @click="rejectDetail(row.id)">驳回原因</el-button>
                                </div>
                                <el-button type="text" icon="el-icon-view" @click="handleViewDetail(row)">详情</el-button>
                            </div>
                        </template>
                        <template #status="{ row }">
                            <el-tag :type="getStatusTagType(row.status)">{{ mapStatus(row.status) }}</el-tag>
                        </template>
                        <template #keyData="{ row }">
                            <el-tooltip :content="row.address" placement="top" effect="light">
                                <span>{{ row.keyData }}</span>
                            </el-tooltip>
                        </template>
                    </avue-crud>
                </div>
            </el-tab-pane>
        </el-tabs>
 
        <!-- 新建工单对话框 -->
        <el-dialog v-model="dialogVisible" title="新建工单" width="70%" :close-on-click-modal="false" @close="resetForm">
            <el-form :model="form" :rules="rules" ref="form" label-width="100px">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="工单名称" prop="name">
                            <el-input v-model="form.name" placeholder="请输入工单名称"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="关联航线" prop="file_id">
                            <el-select v-model="form.file_id" placeholder="请选择航线" @change="getFlyingNestBy">
                                <el-option v-for="item in wayLineList" :key="item.wayline_id" :label="item.name"
                                    :value="item.wayline_id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="关联机巢" prop="device_sns">
                            <el-select v-model="form.device_sns" placeholder="请选择机巢" multiple>
                                <el-option v-for="item in device_sns" :key="item.device_sn" :label="item.nickname"
                                    :value="item.device_sn" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="关联算法" prop="ai_types">
                            <el-select v-model="form.ai_types" placeholder="请选择关联算法" multiple>
                                <el-option v-for="item in ai_types" :key="item.dictKey" :label="item.dictValue"
                                    :value="item.dictKey" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
 
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="工单内容" prop="content">
                            <el-input type="textarea" v-model="form.content" rows="4" placeholder="请输入工单内容"></el-input>
                        </el-form-item>
                    </el-col>
 
                    <el-col :span="6">
                        <el-form-item label="周期频次" prop="date_range">
                            <el-date-picker v-model="form.date_range" type="daterange" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期" class="date-picker" />
                        </el-form-item>
 
                        <el-button type="danger" @click="submitForm(1)">发布</el-button>
                        <el-button type="primary" @click="submitForm(0)">存草稿</el-button>
                    </el-col>
                    <el-col :span="3">
                        <el-select v-model="form.rep_fre_type" placeholder="请选择频次">
                            <el-option v-for="item in cycles" :key="item" :label="item" :value="item" />
                        </el-select>
                    </el-col>
 
                    <el-col :span="3">
                        <el-time-picker style="width: 100px" v-model="form.deal_time" prop="deal_time"
                            value-format="HH:mm" :picker-options="{
                                selectableRange: '00:00 - 23:59',
                            }" />
                    </el-col>
                </el-row>
 
                <el-row :gutter="20" style="height: 400px">
 
                    <el-col :span="24">
                        <map-container v-if='dialogVisible' ref="MapContainer"></map-container>
                    </el-col>
 
                </el-row>
            </el-form>
        </el-dialog>
 
        <!-- 工单详情对话框 -->
        <el-dialog v-model="detailVisible" title="工单详情" width="70%" :close-on-click-modal="false" @close="resetForm">
            <el-form :model="form" ref="form" label-width="100px">
                <div class="custom-steps-container">
                    <!-- 标题行 -->
                    <div class="steps-titles">
                        <div v-for="(record, index) in form.record_list" :class="{ active: record.user_id >= 0 }"
                            :key="index" class="step-title">
                            {{ record.status_str }}
                        </div>
                    </div>
 
                    <!-- Element Steps 组件 -->
                    <el-steps :active="form.active" align-center class="custom-steps">
                        <el-step v-for="(record, index) in form.record_list" :key="index">
                            <template #description>
 
                                <span class="step-description" style="position: relative; display: inline-block;">
                                    {{ record.user_name }}
                                </span>
                                <span style="
          position: absolute;
          left: 80%;  
          top: 50%;
          transform: translateY(-50%);
          width: 100px;
          margin-left: 4px;  
          color: #666;
          font-size: 12px;
        ">
                                    {{ record.interval_time_str }}
                                </span>
                                <div class="step-description">
                                    {{ record.create_time_str }}
                                </div>
                            </template>
                        </el-step>
                    </el-steps>
                </div>
 
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="工单名称" prop="name">
                            <el-input v-model="form.name" placeholder="请输入工单名称"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="关联航线" prop="file_id">
                            <el-select v-model="form.file_id" placeholder="请选择航线" @change="getFlyingNestBy">
                                <el-option v-for="item in wayLineList" :key="item.wayline_id" :label="item.name"
                                    :value="item.wayline_id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="关联机巢" prop="device_sns">
                            <el-select v-model="form.device_sns" placeholder="请选择机巢" multiple>
                                <el-option v-for="item in device_sns" :key="item.device_sn" :label="item.nickname"
                                    :value="item.device_sn" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="关联算法" prop="ai_types">
                            <el-select v-model="form.ai_types" placeholder="请选择关联算法" multiple>
                                <el-option v-for="item in ai_types" :key="item.dictKey" :label="item.dictValue"
                                    :value="item.dictKey" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
 
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="工单内容" prop="content">
                            <el-input type="textarea" v-model="form.content" rows="4" placeholder="请输入工单内容"></el-input>
                        </el-form-item>
                    </el-col>
 
                    <el-col :span="6">
                        <el-form-item label="周期频次" prop="date_range">
                            <el-date-picker v-model="form.date_range" type="daterange" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期" class="date-picker" />
                        </el-form-item>
 
 
                        <el-button type="danger"
                            v-if="form.status == 0 || (form.status == 2 && userInfo.user_id == form.create_user)"
                            @click="submitForm(1)">发布</el-button>
                        <el-button type="primary" v-if="form.status == 1 && userInfo.user_id != form.create_user"
                            @click="orderLogPass(form.id)">通过</el-button>
                        <el-button type="danger" v-if="form.status == 1 && userInfo.user_id != form.create_user"
                            @click="orderLogReject(form.id)">驳回</el-button>
                    </el-col>
                    <el-col :span="3">
                        <el-select v-model="form.rep_fre_type" placeholder="请选择频次">
                            <el-option v-for="item in cycles" :key="item" :label="item" :value="item" />
                        </el-select>
                    </el-col>
 
                    <el-col :span="3">
                        <el-time-picker style="width: 100px" v-model="form.deal_time" prop="deal_time"
                            value-format="HH:mm" :picker-options="{
                                selectableRange: '00:00 - 23:59',
                            }" />
                    </el-col>
                </el-row>
 
                <el-row :gutter="20" style="height: 400px">
 
                    <el-col :span="24">
                        <map-container v-if='detailVisible' ref="MapContainer"></map-container>
                    </el-col>
 
                </el-row>
            </el-form>
        </el-dialog>
    </basic-container>
</template>
 
<script>
import {
    getList,
    saveUpdateOrderLog,
    orderLogDetails,
    orderLogRecall,
    orderLogReject,
    orderLogPass,
    orderLogExport,
} from '@/api/tickets/orderLog'
import { getTicketInfo } from '@/api/tickets/ticket'
import { getDictionary } from '@/api/system/dictbiz'
import { getWaylineFileListByArea } from '@/api/resource/wayline'
import { export_json_to_excel } from '@/utils/exportExcel'
import { getFlyingNestBy } from '@/api/device/device'
import { mapGetters } from 'vuex'
import NProgress from 'nprogress'
import { downloadXls } from '@/utils/util'
import 'nprogress/nprogress.css'
import { analyzeKmzFile, removeTextKey, XMLToJSON } from '@/utils/cesium/kmz'
 
export default {
    name: 'TicketPage',
    data () {
        return {
            activeTab: 'all',
 
            tabs: [
                { label: '全部工单', name: 'all', value: null, count: 0 },
                { label: '待审核', name: 'pending', value: 1, count: 0 },
                { label: '已驳回', name: 'processing', value: 2, count: 0 },
                { label: '已通过', name: 'inProgress', value: 3, count: 0 },
                { label: '草稿', name: 'completed', value: 0, count: 0 },
            ],
            filters: {
                key_word: '',
                create_dept: '',
                start_date: null,
                end_date: null,
                file_id: '',
                ai_types: [],
                status: '',
                dateRange: [],
            },
            departments: [],
            types: [],
            device_sns: [],
            ai_types: [],
            wayLineList: [],
 
            statuses: [
                { label: '草稿', value: '0' },
                { label: '待审核', value: '1' },
                { label: '已驳回', value: '2' },
                { label: '已通过', value: '3' },
            ],
            //周期
            cycles: ['周一', '周二', '周三', '周四', '周五', '周六', '周末', '周天', '工作日', '每天'],
 
            tableData: [],
            option: {
                border: true,
                stripe: true,
                menuWidth: 150,
                searchShow: true,
                searchBtnText: '搜索',
                searchMenuSpan: 6,
                addBtnText: '新建工单',
                addBtn: false,
                viewBtn: false,
                editBtn: false,
                delBtn: false,
                menu: true,
                cancelBtn: true,
                cancelBtnText: '取消',
                column: [
                    { label: '序号', prop: 'id', width: 50, ellipsis: true },
                    { label: '工单编号', prop: 'job_info_num', width: 100, ellipsis: true, overHidden: true },
                    { label: '工单名称', prop: 'name', width: 100, ellipsis: true, overHidden: true },
                    { label: '所属单位', prop: 'dept_name', width: 100, ellipsis: true },
                    { label: '发起时间', prop: 'create_time', width: 100, ellipsis: true },
                    { label: '工单内容', prop: 'content', width: 160, ellipsis: true, overHidden: true },
                    { label: '关联航线', prop: 'wayline_name', width: 100, ellipsis: true, overHidden: true },
                    { label: '关联算法', prop: 'ai_type_str', width: 100, ellipsis: true, overHidden: true },
                    { label: '关联机巢', prop: 'device_names', width: 100, ellipsis: true, overHidden: true },
 
                    { label: '创建人', prop: 'creator_name', width: 50, ellipsis: true, overHidden: true },
                    { label: '关联机巢', prop: 'device_names', width: 80, ellipsis: true, overHidden: true },
                    {
                        label: '工单周期凭次',
                        prop: '',
                        width: 108,
                        formatter: row => this.formatCycleTime(row),
                        html: true,
                        ellipsis: true, overHidden: true
 
 
 
                    },
                    { label: '工单状态', prop: 'status', width: 60 },
                ],
            },
 
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            dialogVisible: false,
            detailVisible: false,
            currentDetail: {},
            form: {},
            rules: {
                name: [{ required: true, message: '请输入工单名称', trigger: 'blur' }],
                file_id: [{ required: true, message: '需要选择航线', trigger: 'change' }],
                device_sns: [{ required: true, message: '请选择机巢', trigger: 'change' }],
                ai_types: [{ required: true, message: '请选择算法', trigger: 'change' }],
                content: [{ required: true, message: '请输入工单内容', trigger: 'blur' }],
                date_range: [{ required: true, message: '请选择时间不能为空', trigger: 'blur' }],
                rep_fre_type: [{ required: true, message: '请选择周期', trigger: 'blur' }],
                deal_time: [{ required: true, message: '请选择执行时间', trigger: 'blur' }],
            },
            loading: false,
            globalCounts: {},
            mapLoaded: false,
        }
    },
    async created () {
        var response = await getDictionary({ code: 'SF' })
        var word_order_typeResponse = await getDictionary({ code: 'WORK_ORDER_TYPE' })
        this.ai_types = response.data.data
        this.types = word_order_typeResponse.data.data
        //获取航线
        this.asyncgetWaylineFileListByArea()
        const response2 = await getTicketInfo()
        const { dept_data, event_type, ai_type } = response2.data.data
        this.departments = dept_data.map(item => ({
            label: item.dept_name,
            value: item.id,
        }))
    },
    mounted () {
        this.fetchTableData()
    },
    computed: {
        ...mapGetters(['userInfo']),
    },
 
    methods: {
        searchChange (params, done) {
            console.log('searchChange')
            this.query = params
            this.parentId = ''
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            done()
        },
        async onLoad (page, params = {}) {
            this.loading = true
            getList(
                null,
                this.page.currentPage,
                this.page.pageSize,
                Object.assign(params, this.query)
            ).then(res => {
                this.tableData = res.data.data
                this.loading = false
                this.selectionClear()
            })
 
 
        },
        selectionClear () {
            this.selectionList = []
            this.$refs.crud.toggleSelection()
        },
        async loadAMapScripts () {
            try {
                // await loadAMap();
                // await loadAMapUI();
                this.mapLoaded = true
            } catch (error) {
                console.error('Failed to load AMap scripts:', error)
                this.$message.error('地图加载失败,请检查网络或API Key配置')
            }
        },
        formatCycleTime (row) {
            return row.begin_time + '-' + row.end_time + '<br/>'
                + row.rep_rule_type + row.rep_rule_val
        },
 
        async fetchTableData () {
            this.loading = true
            try {
                let params = this.getQueryParam()
                console.log('发送的参数:', params)
                const response = await getList(params, this.page.currentPage, this.page.pageSize)
                if (!response?.data?.data?.records) {
                    throw new Error('接口返回数据格式不正确')
                }
 
                const { total, records } = response.data.data
                this.tableData = records.map(item => {
                    return item
                })
 
                if (this.activeTab === 'all') {
                    this.updateGlobalCounts(records, total)
                }
 
                this.page.total = total || 0
                this.updateTabCounts()
            } catch (error) {
                console.error('获取数据失败:', error)
                this.$message.error(error.message || '获取数据失败')
                this.tableData = []
                this.page.total = 0
            } finally {
                this.loading = false
            }
        },
 
        getQueryParam () {
            const currentTab = this.tabs.find(tab => tab.name === this.activeTab)
            if (this.filters.dateRange) {
                console.log(
                    'this.formatDate(this.filters.dateRange[0])',
                    this.formatDate(this.filters.dateRange[0])
                )
            }
 
            const params = {
                key_word: this.filters.key_word || undefined,
                create_dept: this.filters.create_dept || undefined,
                ai_types:
                    this.filters.ai_types && this.filters.ai_types.length > 0
                        ? [this.filters.ai_types]
                        : null,
                file_id: this.filters.file_id || undefined,
                status: this.filters.status !== '' ? Number(this.filters.status) : currentTab?.value,
                dept_id: this.filters.department || undefined,
                creat_start_date: this.filters.dateRange?.[0]
                    ? this.formatDate(this.filters.dateRange[0])
                    : undefined,
                create_end_date: this.filters.dateRange?.[1]
                    ? this.formatDate(this.filters.dateRange[1]).replace('00:00:00', '23:59:59')
                    : undefined,
 
                start_date: this.filters.cycleDateRange?.[0]
                    ? this.formatDate(this.filters.cycleDateRange[0])
                    : undefined,
                end_date: this.filters.dateRacycleDateRangenge?.[1]
                    ? this.formatDate(this.filters.cycleDateRange[1]).replace('00:00:00', '23:59:59')
                    : undefined,
                rep_fre_type: this.filters.rep_fre_type || undefined,
                deal_time: this.filters.deal_time || undefined,
                current: this.page.currentPage,
                size: this.page.pageSize,
            }
            return params
        },
        sizeChange (pageSize) {
            this.page.pageSize = pageSize
        },
        async submitForm (status) {
            this.$refs.form.validate(async valid => {
                if (valid) {
                    let dateRange = this.form.date_range
                    console.log('dateRange' + dateRange)
 
                    this.form.begin_time = this.formatDate(dateRange[0])
                    this.form.end_time = this.formatDate(dateRange[1])
 
                    const submitData = {
                        ...this.form,
 
                        status: status,
                    }
                    await saveUpdateOrderLog(submitData)
                    let id = this.form.id
                    if (id) {
                        this.$message.success('工单发布成功')
                    } else {
                        this.$message.success('工单创建成功')
                    }
                    this.dialogVisible = false
                    this.detailVisible = false;
                    (this.device_sns = []), (this.wayLineList = []), this.fetchTableData()
                }
            })
        },
        //驳回原因显示
        async rejectDetail (id) {
            const response = await orderLogDetails(id)
            let data = response.data.data
            this.$confirm(data.remark, '驳回原因', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                this.form = {
                    ...response.data.data,
                }
                this.detailVisible = true
            })
        },
        formatDate (date) {
            if (!date) return undefined
            const d = new Date(date)
            return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(
                d.getDate()
            ).padStart(2, '0')} 00:00:00`
        },
 
        mapStatus (status) {
            const statusTextMap = {
                0: '草稿',
                1: '待审核',
                2: '已驳回',
                3: '已通过',
            }
            return statusTextMap[status] || '未知状态'
        },
 
        getStatusTagType (status) {
            const statusMap = {
                1: 'warning',
                2: 'info',
                3: 'primary',
                4: 'success',
                5: 'danger',
            }
            return statusMap[status] || 'info'
        },
 
        handleTabChange (tab) {
            this.activeTab = tab.props?.name || tab.name
            this.filters.status = ''
            this.page.currentPage = 1
            this.fetchTableData()
        },
 
        handleSearch () {
            this.page.currentPage = 1
            this.fetchTableData()
        },
 
        handleReset () {
            this.filters = {
                keyword: '',
                department: '',
                type: '',
                dateRange: [],
                status: '',
            }
            this.page.currentPage = 1
            this.fetchTableData()
        },
 
        currentChange (currentPage) {
            this.page.currentPage = currentPage
        },
 
        updateGlobalCounts (records, total) {
            const counts = {
                all: total,
                pending: 0,
                processing: 0,
                inProgress: 0,
                completed: 0,
                closed: 0,
                myTickets: 0,
            }
 
            records.forEach(item => {
                const tab = this.tabs.find(t => t.value === Number(item.status))
                if (tab) {
                    counts[tab.name] = (counts[tab.name] || 0) + 1
                }
            })
 
            this.globalCounts = counts
        },
 
        updateTabCounts () {
            if (this.activeTab === 'all') {
                this.tabs.forEach(tab => {
                    tab.count = this.globalCounts[tab.name] || 0
                })
            } else {
                this.tabs.forEach(tab => {
                    if (tab.name === this.activeTab) {
                        tab.count = this.tableData.length
                    } else {
                        tab.count = this.globalCounts[tab.name] || 0
                    }
                })
            }
        },
 
        handleAdd () {
            this.form = {}
            this.dialogVisible = true
            //航线列表
            this.asyncgetWaylineFileListByArea()
        },
 
        resetForm () {
            this.form = {
                name: '',
                type: '',
                handler: '',
                algorithm: '',
                location: '',
                address: '',
                content: '',
                photos: [],
            }
            if (this.$refs.form) {
                this.$refs.form.resetFields()
            }
        },
 
        formatLocation (location) {
            if (!Array.isArray(location)) {
                return '未知位置'
            }
            return `${location[0].toFixed(6)}, ${location[1].toFixed(6)}`
        },
 
        async handleViewDetail (row) {
            const response = await orderLogDetails(row.id)
            this.form = {
                ...response.data.data,
            }
            this.detailVisible = true
 
            //航线列表
            this.asyncgetWaylineFileListByArea()
            this.device_sns = response.data.data.deviceList
        },
        //导出
        async exportData () {
            this.$confirm('是否智飞工单数据?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                NProgress.start()
                let params = this.getQueryParam()
                orderLogExport(params).then(res => {
                    downloadXls(res.data, `智飞工单${this.$dayjs().format('YYYY-MM-DD')}.xlsx`)
                    NProgress.done()
                })
            })
        },
 
        refreshChange () {
            this.fetchTableData()
        },
        //获取航线列表
        async asyncgetWaylineFileListByArea (name) {
            var wayLineListResponse = await getWaylineFileListByArea(this.userInfo.detail.areaCode)
            this.wayLineList = wayLineListResponse.data.data
 
            this.initMapLine()
        },
 
        initMapLine () {
            let currentLine = this.wayLineList.find(item => item.wayline_id == this.form.file_id)
 
            if (!currentLine) return
 
            // 异步解析kmz文件
            const analysis = async url => {
                return new Promise(async resolve => {
                    const res = await analyzeKmzFile(`${url}?_t=${new Date().getTime()}`)
                    const templateXML = await res.fileInfoObj['wpmz/template.kml']
                    const templateXMLJSON = XMLToJSON(templateXML)?.['Document']
                    const templateXMLObj = removeTextKey(templateXMLJSON.Folder)
                    resolve(templateXMLObj)
                })
            }
 
            const drawLine = async () => {
                let prexUrl = ref(import.meta.env.VITE_APP_AIRLINE_URL + currentLine.object_key)
                const res = await analysis(prexUrl.value)
                if (!res.Placemark.length) return
                renderingLine(res)
            }
 
            const renderingLine = lineObj => {
                const positions = lineObj.Placemark.map(item => {
                    return item.Point.coordinates.split(',')
                })
 
                this.$nextTick(() => {
                    if (this.$refs.MapContainer && this.$refs.MapContainer.initAddEntity) {
                        this.$refs.MapContainer.initAddEntity('polyline', positions)
                    }
                })
            }
 
            drawLine()
        },
 
 
 
 
        //可飞行机巢列表
        async getFlyingNestBy (waylineId) {
            this.initMapLine()
 
            //按照航线来
            const params = {
                type: 0,
                waylineId: waylineId,
            }
            var wayLineListResponse = await getFlyingNestBy(params)
            this.device_sns = wayLineListResponse.data.data
        },
 
        //撤回
        async orderLogRecall (id) {
            this.$confirm('确定撤回则到草稿箱。', '是否撤回?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(async () => {
                let reposne = await orderLogRecall(id)
                this.handleSearch()
            })
        },
        onLoad () {
            this.fetchTableData()
        },
        /**
         * 通过
         */
        async orderLogPass (id) {
            let response = await orderLogPass(id)
            let data = response.data.data
            this.$message.success('审核通过')
            this.detailVisible = false
        },
        /**
         * 驳回
         */
        async orderLogReject (id) {
            this.$prompt('', '驳回原因', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(async ({ value }) => {
                let response = await orderLogReject(id, value)
                let data = response.data.data
                this.$message.success('驳回成果')
                this.detailVisible = false
            })
        },
    },
 
    watch: {
        tableData: {
            handler () {
                this.updateTabCounts()
            },
            deep: true,
        },
    },
}
</script>
 
<style lang="scss" scoped>
.tab-content {
    padding: 10px;
}
 
.filter-bar {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
 
    .filter-item {
        margin-right: 10px;
        margin-bottom: 10px;
        width: 200px;
    }
 
    .date-picker {
        width: 240px;
    }
}
 
.action-bar {
    margin-bottom: 16px;
}
 
.el-tabs {
    :deep(.el-tabs__content) {
        overflow: visible;
    }
}
 
.tab-content {
    min-height: 200px;
}
 
.detail-form {
    :deep(.el-form-item) {
        margin-bottom: 10px;
    }
 
    :deep(.el-form-item__label) {
        color: #606266;
        font-weight: normal;
    }
 
    :deep(.el-form-item__content) {
        color: #303133;
    }
}
 
.el-dialog {
    .el-form-item {
        margin-bottom: 20px;
    }
}
 
.el-upload {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
 
    :deep(.el-upload-list__item) {
        transition: all 0.3s ease;
    }
 
    :deep(.el-upload-list__item:hover) {
        background-color: #f5f7fa;
    }
}
 
.el-upload__tip {
    font-size: 12px;
    color: #909399;
    margin-top: 7px;
}
 
.custom-steps-container {
    width: 100%;
    margin: 20px 0;
}
 
.steps-titles {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    position: relative;
}
 
.step-title {
    text-align: center;
    flex: 1;
    font-size: 16px;
    color: #999;
    position: relative;
    padding-bottom: 10px;
}
 
.step-title.active {
    color: #409eff;
    font-weight: bold;
}
 
.custom-steps {
    margin-top: -20px;
    /* 向上移动与标题重叠 */
}
 
.el-step__head {
    margin-top: 0;
}
 
.el-step__description {
    margin-top: 8px;
    padding: 0 20px;
}
 
.step-description {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}
</style>