zjk
2026-06-09 3c770a6deeada7ddfea03120285c8a9ba2ed8720
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
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
<script setup lang="tsx">
import type { DataTableColumns, FormInst } from 'naive-ui'
import { NButton, NEllipsis, NSpace } from 'naive-ui'
import { onActivated, watch } from 'vue'
import { useRouter } from 'vue-router'
import dayjs from 'dayjs'
import { useBoolean } from '@/hooks'
import { downloadFile } from '@/utils'
import { batchOperation, batchSetElectronic, deleteVehicle, exportVehicleExcel, getVehicleById, getVehicleImportTemplate, getVehiclePageList, importVehicleExcel } from '@/service/api/vehicle'
import { fetchElectronicFenceAreaList } from '@/service/api/point'
import SearchPanel from '@/components/custom/SearchPanel.vue'
import OperationLogModal from '@/components/custom/OperationLogModal.vue'
import CompleteVehicleInfoModal from './components/CompleteVehicleInfoModal.vue'
import EditVehicleModal from './components/EditVehicleModal.vue'
import ConfirmDialog from '@/components/ConfirmDialog/index.vue'
 
const router = useRouter()
const dialog = useDialog()
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
 
const initialModel = {
  vehicleCode: '', // 车辆编码
  plateNumber: '', // 车牌号
  vehicleVin: '', // VIN码
  status: null, // 状态
  entryTime: null, // 入库时间
  vehicleAttribute: null, // 车辆属性
}
const model = ref({ ...initialModel })
 
const count = ref(0)
const listData = ref<any[]>([])
const pagination = reactive({
  page: 1,
  pageSize: 10,
})
 
function handleResetSearch() {
  model.value = { ...initialModel }
  pagination.page = 1
  pagination.pageSize = 10
  handleSearch()
}
 
function handleSearch() {
  pagination.page = 1
  getVehicleList()
}
 
// 车辆状态选项
const vehicleStatusOptions = [
  { label: '待完善信息', value: '1' },
  { label: '待运营', value: '2' },
  { label: '保险/年检过期', value: '3' },
]
 
// 车辆属性选项
const vehicleAttributeOptions = [
  { label: '测试', value: 1 },
  { label: '运营', value: 2 },
]
 
const isVehicleStatusSelectOpen = ref(false)
const isVehicleAttributeSelectOpen = ref(false)
 
const filterItems = computed(() => [
  {
    label: '车辆编码',
    path: 'vehicleCode',
    render: () => <n-input v-model:value={model.value.vehicleCode} placeholder="请输入车辆编码" />,
  },
  {
    label: '车牌号',
    path: 'plateNumber',
    render: () => <n-input v-model:value={model.value.plateNumber} placeholder="请输入车牌号" />,
  },
  {
    label: 'VIN码',
    path: 'vehicleVin',
    render: () => <n-input v-model:value={model.value.vehicleVin} placeholder="请输入VIN码" />,
  },
  {
    label: '状态',
    path: 'status',
    render: () => (
      <n-select
        v-model:value={model.value.status}
        options={vehicleStatusOptions}
        clearable
        placeholder="请选择状态"
        onUpdate:show={(val: any) => isVehicleStatusSelectOpen.value = val}
      >
        {{
          arrow: () => (
            <img
              src="https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e120f81c-9f15-4e1a-9938-22252898edf9.png"
              class={`arrow-icon ${isVehicleStatusSelectOpen.value ? 'arrow-icon--open' : ''}`}
              style={{ width: '16px', height: '16px' }}
              alt="arrow"
            />
          ),
          empty: () => (
            <div class="flex-center">
              <img
                src="/src/assets/element-img/no-data.png"
                style={{ width: '50%' }}
              />
            </div>
          ),
        }}
      </n-select>
    ),
  },
  {
    label: '入库时间',
    path: 'entryTime',
    render: () => (
      <n-date-picker
        v-model:value={model.value.entryTime}
        type="daterange"
        clearable
        actions={[]}
        format="yyyy/MM/dd"
        close-on-select={true}
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        separator="-"
      />
    ),
  },
  {
    label: '车辆属性',
    path: 'vehicleAttribute',
    render: () => (
      <n-select
        v-model:value={model.value.vehicleAttribute}
        options={vehicleAttributeOptions}
        clearable
        placeholder="请选择车辆属性"
        onUpdate:show={(val: any) => isVehicleAttributeSelectOpen.value = val}
      >
        {{
          arrow: () => (
            <img
              src="https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e120f81c-9f15-4e1a-9938-22252898edf9.png"
              class={`arrow-icon ${isVehicleAttributeSelectOpen.value ? 'arrow-icon--open' : ''}`}
              style={{ width: '16px', height: '16px' }}
              alt="arrow"
            />
          ),
          empty: () => (
            <div class="flex-center">
              <img
                src="/src/assets/element-img/no-data.png"
                style={{ width: '50%' }}
              />
            </div>
          ),
        }}
      </n-select>
    ),
  },
])
 
// 文件导入相关
const fileInputRef = ref<HTMLInputElement | null>(null)
 
// 状态映射
const statusMap: Record<string, { bgColor: string, color: string, text: string }> = {
  1: { bgColor: '#FFF8E6', color: '#FF9000', text: '待完善信息' },
  2: { bgColor: '#FFF8E6', color: '#FF9000', text: '待运营' },
  3: { bgColor: '#FFECE6', color: '#E12F1F', text: '保险/年检过期' },
}
 
// 运营区域选项
const operationAreaOptions = ref<{ label: string, value: string | number }[]>([])
 
// 获取运营区域列表
async function getOperationAreaList() {
  try {
    const { data } = await fetchElectronicFenceAreaList()
    if (data) {
      // 过滤出 areaType 为 1 的运营区域
      operationAreaOptions.value = data
        .filter((item: any) => item.areaType === 1)
        .map((item: any) => ({
          label: item.areaName,
          value: item.electronicId,
        }))
    }
  }
  catch (error) {
    console.error('获取运营区域失败:', error)
  }
}
 
onMounted(() => {
  getOperationAreaList()
})
 
// 设置运营区域弹窗
const showAreaModal = ref(false)
const areaFormRef = ref<FormInst | null>(null)
const areaFormModel = ref({
  operationArea: null as string | null,
})
const selectedVehicles = ref<any[]>([])
const showOperationLogModal = ref(false)
 
// 完善车辆信息弹窗
const showCompleteInfoModal = ref(false)
const currentVehicle = ref<any>(null)
const infoModalType = ref<'complete' | 'update'>('complete') // complete: 完善信息, update: 更新信息
 
// 编辑车辆弹窗
const showEditModal = ref(false)
const editVehicle = ref<any>(null)
const editMode = ref<'add' | 'edit'>('edit')
 
// 通用二次确认对话框
const showConfirmDialog = ref(false)
const confirmDialogConfig = ref({
  title: '',
  description: '',
  cancelText: '取消',
  confirmText: '确定',
  onConfirm: async () => {},
  onCancel: () => {
    showConfirmDialog.value = false
  },
})
// 表单验证规则
const areaFormRules = {
  operationArea: {
    required: true,
    message: '请选择运营区域',
    trigger: ['blur', 'change'],
  },
}
 
// 表格列定义
const columns = computed<DataTableColumns<any>>(() => [
  {
    type: 'selection',
    width: 30,
    fixed: 'left',
    align: 'center',
  },
  {
    title: '序号',
    key: 'index',
    fixed: 'left',
    width: 60,
    align: 'left',
    resizable: true,
    render: (row, index) => <span>{index + 1}</span>,
  },
  {
    title: '车辆编码',
    align: 'left',
    width: 120,
    key: 'vehicleCode',
    ellipsis: true,
    fixed: 'left',
    resizable: true,
    render: row => (
      <NEllipsis style="width: 100%;cursor: pointer;" tooltip>
        {row.vehicleCode || '-'}
      </NEllipsis>
    ),
  },
  {
    title: '车牌号',
    align: 'left',
    width: 120,
    key: 'plateNumber',
    resizable: true,
    render: row => (
      <span style="color: #0068FF;cursor: pointer;" onClick={() => handleDetail(row)}>
        {row.plateNumber || '-'}
        {' '}
      </span>
    ),
  },
  {
    title: 'VIN码',
    align: 'left',
    width: 120,
    key: 'vehicleVin',
    resizable: true,
  },
  {
    title: '型号',
    align: 'left',
    width: 120,
    key: 'vehicleModelName',
    resizable: true,
  },
  {
    title: '车辆属性',
    align: 'left',
    width: 120,
    key: 'vehicleAttribute',
    resizable: true,
    render: (row) => {
      const option = vehicleAttributeOptions.find(opt => String(opt.value) === String(row.vehicleAttribute))
      return option ? option.label : (row.vehicleAttribute || '-')
    },
  },
  {
    title: '采购来源',
    align: 'left',
    width: 120,
    key: 'procurementSource',
    resizable: true,
    ellipsis: true,
  },
  {
    title: '运营区域',
    align: 'left',
    width: 120,
    key: 'electronicId',
    resizable: true,
    render: (row) => {
      if (row.electronicName)
        return row.electronicName
      const option = operationAreaOptions.value.find(opt => String(opt.value) === String(row.electronicId))
      return option ? option.label : (row.electronicId || '-')
    },
  },
  {
    title: '状态',
    align: 'left',
    key: 'status',
    width: 120,
    resizable: true,
    render: (row) => {
      const status = statusMap[String(row.status)] || { bgColor: '#FFF8E6', color: '#FF9000', text: row.status }
      return (
        <n-tag
          type={row.status === 3 ? 'error' : 'warning'}
          bordered={false}
        >
          {status.text || ''}
        </n-tag>
      )
      // return <span style={`background-color: ${status.bgColor}; color: ${status.color}; padding: 1px 8px; border-radius: 4px;font-size: 12px;`}>{status.text}</span>
    },
  },
  {
    title: '入库时间',
    align: 'left',
    width: 160,
    key: 'warehousingTime',
    render: row => row.warehousingTime ? dayjs(row.warehousingTime).format('YYYY/MM/DD HH:mm') : '-',
  },
  {
    title: '操作',
    align: 'left',
    key: 'actions',
    fixed: 'right',
    width: 140,
    // resizable: true,
    render: (row) => {
      return (
        <NSpace wrap={false} size={8}>
          {row.status == '1' && (
            <NButton
              text
              v-permission="50116"
              type="primary"
              onClick={() => handleCompleteInfo(row)}
            >
              完善信息
            </NButton>
          )}
          {row.status == '2' && (
            <NButton
              text
              v-permission="50117"
              type="primary"
              onClick={() => handleStartOperation(row)}
            >
              开始运营
            </NButton>
          )}
          {row.status == '3' && (
            <NButton
              text
              v-permission="50118"
              type="primary"
              onClick={() => handleUpdateInfo(row)}
            >
              更新信息
            </NButton>
          )}
          <NButton
            text
            v-permission="50119"
            type="primary"
            onClick={() => handleDetail(row)}
          >
            详情
          </NButton>
          {/* <NButton
            text
            v-permission="50120"
            type="primary"
            onClick={() => handleEdit(row)}
          >
            编辑
          </NButton> */}
          <NButton
            text
            v-permission="50121"
            type="primary"
            onClick={() => handleDelete(row!)}
          >
            删除
          </NButton>
        </NSpace>
      )
    },
  },
])
 
const tableScrollX = computed(() => {
  const widthList = columns.value.map((col: any) => {
    const width = col?.width ?? col?.minWidth ?? 0
    return typeof width === 'number' ? width : 0
  })
  const totalWidth = widthList.reduce((sum, w) => sum + w, 0)
  return Math.min(totalWidth, 1600)
})
 
async function getVehicleList() {
  startLoading()
  try {
    const params = {
      ...model.value,
      pageNum: pagination.page,
      pageSize: pagination.pageSize,
      vehicleAttribute: model.value.vehicleAttribute || 0,
      startTime: '',
      endTime: '',
    }
 
    // 处理时间范围
    if (model.value.entryTime && model.value.entryTime.length === 2) {
      params.startTime = dayjs(model.value.entryTime[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
      params.endTime = dayjs(model.value.entryTime[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
    }
    delete params.entryTime
 
    const { data } = await getVehiclePageList(params)
    if (data) {
      listData.value = data.records || []
      count.value = data.total || 0
    }
  }
  finally {
    endLoading()
  }
}
 
function handleAdd() {
  router.push('/assetManagement/vehicleManagement/inventoryVehicle/add')
}
 
function handleBatchSetArea() {
  // 检查是否有选中的车辆
  if (selectedVehicles.value.length === 0) {
    window.$message.warning('请先选择要设置运营区域的车辆')
    return
  }
 
  // 重置表单
  areaFormModel.value.operationArea = null
  showAreaModal.value = true
}
 
function handleAreaModalConfirm() {
  areaFormRef.value?.validate(async (errors) => {
    if (!errors) {
      const res = await batchSetElectronic({
        electronicId: areaFormModel.value.operationArea!,
        ids: selectedVehicles.value.map(item => item.id),
      })
      // 只要 code == 200 即表示成功
      if (res && (res as any).code === 200) {
        window.$message.success('批量设置运营区域成功')
        showAreaModal.value = false
        selectedVehicles.value = []
        checkedRowKeys.value = []
        getVehicleList()
      }
    }
  })
}
 
function handleAreaModalCancel() {
  showAreaModal.value = false
}
 
async function handleBatchOperation() {
  if (selectedVehicles.value.length === 0) {
    window.$message.warning('请先选择要操作的车辆')
    return
  }
  const idStr = selectedVehicles.value.map(item => item.id).join(',')
  dialog.warning({
    title: '确认开始运营',
    content: () => `确认对选中的 ${selectedVehicles.value.length} 辆车辆执行开始运营吗?`,
    negativeText: '取消',
    positiveText: '确定',
    // confirmText: '确定',
    maskClosable: false,
    autoFocus: false,
    onPositiveClick: async () => {
      const res = await batchOperation(idStr)
      if (res && (res as any).code === 200) {
        window.$message.success('批量运营成功')
        selectedVehicles.value = []
        checkedRowKeys.value = []
        getVehicleList()
      }
      else {
        // window.$message.error((res as any).message || '批量运营失败')
      }
      showConfirmDialog.value = false
    },
    onNegativeClick: () => {
      showConfirmDialog.value = false
    },
  })
  // showConfirmDialog.value = true
}
 
// 下载模板
async function handleDownloadTemplate() {
  try {
    const response = await getVehicleImportTemplate()
    if (response instanceof Blob) {
      downloadFile(response, `车辆导入模板_${new Date().getTime()}.xlsx`)
      window.$message.success('下载成功')
    }
    else {
      window.$message.error('下载失败:接口未返回正确的文件模板')
    }
  }
  catch (error) {
    console.error('下载模板失败:', error)
  }
}
 
function handleImport() {
  fileInputRef.value?.click()
}
 
// 处理文件选择
async function handleFileChange(event: Event) {
  const target = event.target as HTMLInputElement
  const file = target.files?.[0]
  if (!file)
    return
 
  try {
    const { code } = await importVehicleExcel(file)
    if (code === 200) {
      window.$message.success('导入成功')
      handleSearch()
    }
    // else {
    //   window.$message.error(message || '导入失败')
    // }
  }
  catch (error) {
    console.error('导入失败:', error)
  }
  finally {
    // 清空 input 方便下次选择同一个文件
    target.value = ''
  }
}
 
async function handleExport() {
  const params = {
    ...model.value,
  }
  // 处理时间范围
  if (model.value.entryTime && model.value.entryTime.length === 2) {
    params.startTime = dayjs(model.value.entryTime[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
    params.endTime = dayjs(model.value.entryTime[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
  }
  delete params.entryTime
 
  const response = await exportVehicleExcel(params)
  if (response instanceof Blob) {
    downloadFile(response, `在库车辆列表_${new Date().getTime()}.xlsx`)
    window.$message.success('导出成功')
  }
}
 
function handleCompleteInfo(row: any) {
  currentVehicle.value = row
  infoModalType.value = 'complete'
  showCompleteInfoModal.value = true
}
 
function handleCompleteInfoSuccess() {
  // 刷新列表
  handleSearch()
}
 
async function handleStartOperation(row: any) {
  if (!row?.id) {
    window.$message.warning('车辆信息不完整,无法开始运营')
    return
  }
  dialog.warning({
    title: '确认开始运营',
    content: () => {
      return (
        <div>
          确认对车辆
          <span style="color:#0068FF">{row.plateNumber || row.vehicleCode || row.id}</span>
          {' '}
          执行开始运营吗?
        </div>
      )
    },
    negativeText: '取消',
    positiveText: '确定',
    maskClosable: false,
    autoFocus: false,
    onPositiveClick: async () => {
      const res = await batchOperation(String(row.id))
      if (res && (res as any).code === 200) {
        window.$message.success(`开始运营: ${row.plateNumber}`)
        getVehicleList()
      }
      showConfirmDialog.value = false
    },
  })
  // showConfirmDialog.value = true
}
 
function handleUpdateInfo(row: any) {
  currentVehicle.value = row
  infoModalType.value = 'update'
  showCompleteInfoModal.value = true
}
 
function handleOpenOperationLog() {
  showOperationLogModal.value = true
}
 
function handleDetail(row: any) {
  router.push({
    name: 'inventoryVehicleDetail',
    query: {
      id: row.id,
      type: 'inventory',
    },
  })
}
 
function handleEdit(row: any) {
  editMode.value = 'edit'
  editVehicle.value = row
  showEditModal.value = true
}
 
function handleEditSuccess() {
  // 刷新列表
  handleSearch()
}
 
function handleDelete(row: any) {
  window.$dialog.warning({
    title: '是否确认删除',
    content: () => {
      return (
        <div>
          确认删除车辆
          <span style="color:#0068FF">{row.plateNumber}</span>
          {' '}
          吗?
        </div>
      )
    },
    positiveText: '确定',
    negativeText: '取消',
    onPositiveClick: async () => {
      const { code } = await deleteVehicle(row.id)
      if (code === 200) {
        window.$message.success('删除车辆成功')
        getVehicleList() // 刷新列表
      }
    },
  })
}
 
// let handlingQueryAction = false
async function consumeActionQuery() {
  // if (handlingQueryAction)
  //   return
 
  const query = { ...router.currentRoute.value.query } as any
  if (!query.id || !query.action)
    return
 
  // handlingQueryAction = true
  try {
    let targetVehicle = null
    // if (!targetVehicle) {
    const res = await getVehicleById(String(query.id))
 
    if (res && (res as any).code === 200 && (res as any).data)
      targetVehicle = (res as any).data
    // }
 
    if (targetVehicle) {
      if (query.action === 'completeInfo')
        handleCompleteInfo(targetVehicle)
      else if (query.action === 'updateInfo')
        handleUpdateInfo(targetVehicle)
      else if (query.action === 'edit')
        handleEdit(targetVehicle)
    }
  }
  finally {
    // handlingQueryAction = false
  }
}
 
onMounted(() => {
  getOperationAreaList()
  getVehicleList()
  consumeActionQuery()
})
 
onActivated(() => {
  if (window.sessionStorage.getItem('inventoryVehicleNeedRefresh') === '1') {
    window.sessionStorage.removeItem('inventoryVehicleNeedRefresh')
    getVehicleList()
  }
})
 
// watch(
//   () => router.currentRoute.value.query,
//   () => {
//     consumeActionQuery()
//   },
//   { immediate: true },
// )
 
// delete query.id
// delete query.action
// router.replace({ query })
 
watch(
  () => showCompleteInfoModal,
  (val) => {
    if (!val.value) {
      const query = { ...router.currentRoute.value.query } as any
      delete query.id
      delete query.action
      router.replace({ query })
    }
  },
  { deep: true },
)
watch(
  () => showEditModal,
  (val) => {
    if (!val.value) {
      const query = { ...router.currentRoute.value.query } as any
      delete query.id
      delete query.action
      router.replace({ query })
    }
  },
  { deep: true },
)
 
function changePage(page: number, pageSize: number) {
  pagination.page = page
  pagination.pageSize = pageSize
  getVehicleList()
}
 
// 表格行选择
const checkedRowKeys = ref<Array<string | number>>([])
function handleCheck(rowKeys: Array<string | number>, rows: any[]) {
  checkedRowKeys.value = rowKeys
  selectedVehicles.value = rows
}
</script>
 
<template>
  <div class="roboTaxi w-full h-full">
    <div class="flex-1 flex flex-col">
      <div class="roboTaxi-form-card mb-12px">
        <n-form
          ref="formRef"
          :model="model"
          label-placement="left"
          inline
          :show-feedback="false"
        >
          <SearchPanel :default-collapsed="false">
            <n-gi v-for="item in filterItems" :key="item.path">
              <n-form-item :label="item.label" :path="item.path">
                <component :is="item.render" />
              </n-form-item>
            </n-gi>
            <template #action>
              <NButton @click="handleResetSearch">
                {{ $t("common.reset") }}
              </NButton>
              <NButton type="primary" @click="getVehicleList">
                {{ $t("common.search") }}
              </NButton>
            </template>
          </SearchPanel>
        </n-form>
      </div>
 
      <n-card class="flex-1 robotaxi-table-card">
        <template #header>
          <n-flex justify="space-between" align="center">
            <div class="flex gap-2 items-center">
              <NButton v-permission="50122" @click="handleOpenOperationLog">
                操作日志
              </NButton>
              <span
                v-if="checkedRowKeys.length > 0"
                style="color: rgba(23, 31, 38, 0.6); font-weight: 400"
              >
                {{
                  $t("accountManagement.messages.selectedRecords", {
                    count: checkedRowKeys.length,
                  })
                }}
              </span>
              <NButton
                v-permission="50112"
                style="color: #171f26"
                :disabled="checkedRowKeys.length === 0"
                @click="handleBatchSetArea"
              >
                批量设置运营区域
              </NButton>
              <NButton
                v-permission="50113"
                style="color: #171f26"
                :disabled="checkedRowKeys.length === 0"
                @click="handleBatchOperation"
              >
                批量运营
              </NButton>
            </div>
            <NSpace>
              <NButton
                v-permission="50114"
                style="color: #171f26"
                @click="handleDownloadTemplate"
              >
                下载模板
              </NButton>
              <NButton
                v-permission="50114"
                style="color: #171f26"
                @click="handleImport"
              >
                导入
              </NButton>
              <NButton
                v-permission="50115"
                style="color: #171f26"
                @click="handleExport"
              >
                导出
              </NButton>
              <NButton
                v-permission="50111"
                type="primary"
                secondary
                @click="handleAdd"
              >
                新增
              </NButton>
            </NSpace>
          </n-flex>
        </template>
        <div class="flex-1 flex flex-col h-full">
          <n-data-table
            v-model:checked-row-keys="checkedRowKeys"
            class="flex-1"
            :columns="columns"
            :data="listData"
            :loading="loading"
            :scroll-x="tableScrollX"
            :row-key="(row: any) => row.id"
            flex-height
            :bordered="false"
            :header-height="18"
            :row-height="18"
            @update:checked-row-keys="handleCheck"
          >
            <template #empty>
              <div class="flex-center">
                <img
                  src="/src/assets/element-img/no-data.png"
                  style="width: 123px; height: 125px"
                >
              </div>
            </template>
          </n-data-table>
          <Pagination
            :count="count"
            :page="pagination.page"
            :page-size="pagination.pageSize"
            class="robotaxi-pagination mt-12px"
            @change="changePage"
          />
        </div>
      </n-card>
    </div>
 
    <!-- 通用确认弹窗 -->
    <ConfirmDialog
      v-model:visible="showConfirmDialog"
      :title="confirmDialogConfig.title"
      :description="confirmDialogConfig.description"
      :cancel-text="confirmDialogConfig.cancelText"
      :confirm-text="confirmDialogConfig.confirmText"
      @confirm="confirmDialogConfig.onConfirm"
      @cancel="confirmDialogConfig.onCancel"
    />
    <OperationLogModal v-model:show="showOperationLogModal" />
 
    <!-- 批量设置运营区域弹窗 -->
    <n-modal
      v-model:show="showAreaModal"
      preset="card"
      title="批量设置运营区域"
      style="width: 400px"
      :mask-closable="false"
      :segmented="{
        content: true,
        action: true,
      }"
      :content-style="{
        padding: '16px 24px 24px 24px',
      }"
    >
      <n-form
        ref="areaFormRef"
        :model="areaFormModel"
        :rules="areaFormRules"
        label-placement="top"
        require-mark-placement="left"
        class="area-form"
      >
        <n-form-item
          label="选择运营区域"
          path="operationArea"
          style="margin-bottom: 0"
        >
          <n-select
            v-model:value="areaFormModel.operationArea"
            :options="operationAreaOptions"
            placeholder="请选择"
            filterable
            clearable
            style="width: 100%"
          >
            <template #arrow>
              <img
                src="https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e120f81c-9f15-4e1a-9938-22252898edf9.png"
                class="arrow-icon"
                style="width: 16px; height: 16px"
                alt="arrow"
              >
            </template>
            <template #empty>
              <div class="flex-center">
                <img
                  src="/src/assets/element-img/no-data.png"
                  style="width: 50%"
                  alt="no-data"
                >
              </div>
            </template>
          </n-select>
        </n-form-item>
      </n-form>
 
      <template #action>
        <NSpace justify="end" :size="8">
          <NButton
            style="padding: 7px 29px; border-radius: 4px"
            @click="handleAreaModalCancel"
          >
            取消
          </NButton>
          <NButton
            type="primary"
            style="padding: 7px 29px; border-radius: 4px"
            @click="handleAreaModalConfirm"
          >
            保存
          </NButton>
        </NSpace>
      </template>
    </n-modal>
 
    <!-- 完善车辆信息弹窗 -->
    <CompleteVehicleInfoModal
      v-model:show="showCompleteInfoModal"
      :type="infoModalType"
      :vehicle-data="currentVehicle"
      @success="handleCompleteInfoSuccess"
    />
 
    <!-- 编辑车辆弹窗 -->
    <EditVehicleModal
      v-model:show="showEditModal"
      :vehicle-data="editVehicle"
      :mode="editMode"
      @success="handleEditSuccess"
    />
 
    <input
      ref="fileInputRef"
      type="file"
      style="display: none"
      accept=".xlsx, .xls"
      @change="handleFileChange"
    >
  </div>
</template>
 
<style scoped lang="scss">
.area-form :deep(.n-form-item-label) {
  padding-bottom: 8px !important;
  font-size: 13px;
  color: #333;
  font-weight: 400;
}
 
.area-form :deep(.n-form-item-label__asterisk) {
  color: #ff4d4f;
}
 
:deep(.n-card__action) {
  background-color: transparent !important;
}
</style><!-- index.vue -->