Sfoglia il codice sorgente

Merge branch 'equipManage' into dev

huoyi 1 mese fa
parent
commit
9eb7d276c4

+ 36 - 36
src/components/UserSelect/index.vue

@@ -9,19 +9,17 @@
9 9
 </template>
10 10
 
11 11
 <script lang="ts" setup>
12
-import { onMounted, ref, watch, defineProps, defineEmits, onUnmounted } from 'vue'
12
+import { nextTick, onMounted, ref, watch, defineProps, defineEmits, onUnmounted } from 'vue'
13 13
 import { debounce } from 'lodash-es'
14 14
 import { listUser, getUser } from "@/api/system/user"
15
-import { unref } from 'vue'
16 15
 
17 16
 interface ListItem {
18
-  value: string
17
+  value: string | number
19 18
   label: string
20 19
 }
21 20
 
22
-// 定义组件属性
23 21
 const props = defineProps<{
24
-  modelValue: string | string[]
22
+  modelValue: string | string[] | number | number[]
25 23
   multiple?: boolean
26 24
   disabled?: boolean
27 25
   width?: string
@@ -29,19 +27,16 @@ const props = defineProps<{
29 27
   placeholder?: string
30 28
 }>()
31 29
 
32
-// 定义组件事件
33 30
 const emits = defineEmits(['update:modelValue'])
34 31
 
35 32
 const options = ref<ListItem[]>([])
36 33
 const loading = ref(false)
37
-const selectedValue = ref<string | string[]>(props.modelValue)
34
+const selectedValue = ref<string | string[] | number | number[]>(props.modelValue)
38 35
 
39
-// 根据用户ID列表获取用户信息
40
-const fetchUsersByIds = async (userIds: string[]) => {
36
+const fetchUsersByIds = async (userIds: (string | number)[]) => {
41 37
   if (!userIds || userIds.length === 0) return []
42 38
   try {
43
-    // 使用Promise.all并行获取每个用户的信息
44
-    const userPromises = userIds.map(userId => getUser(userId))
39
+    const userPromises = userIds.map(userId => getUser(String(userId)))
45 40
     const userResponses = await Promise.all(userPromises)
46 41
 
47 42
     return userResponses.map((response: any) => ({
@@ -54,17 +49,14 @@ const fetchUsersByIds = async (userIds: string[]) => {
54 49
   }
55 50
 }
56 51
 
57
-// 远程搜索方法
58 52
 const remoteMethod = async (query: string) => {
59 53
   if (query) {
60 54
     loading.value = true
61 55
     try {
62
-      // 调用远程接口获取数据
63 56
       const response = await listUser({ nickName: query })
64
-      // 假设接口返回的数据结构为 { data: [...] },根据实际情况调整
65 57
       options.value = response.rows.map((item) => ({
66
-        value: item.userId, // 根据实际接口返回字段调整
67
-        label: item.nickName // 根据实际接口返回字段调整
58
+        value: item.userId,
59
+        label: item.nickName
68 60
       }))
69 61
     } catch (error) {
70 62
       console.error('远程搜索出错:', error)
@@ -76,39 +68,47 @@ const remoteMethod = async (query: string) => {
76 68
   }
77 69
 }
78 70
 
79
-// 防抖处理远程搜索
80 71
 const debouncedRemoteMethod = debounce(remoteMethod, 300)
81
-
82
-// 标记是否正在初始化回显,避免循环更新
83 72
 const isInitializing = ref(false)
84 73
 
85
-// 监听modelValue变化,有值时执行回显逻辑
74
+const hasValue = (value: any): boolean => {
75
+  if (value === null || value === undefined) return false
76
+  if (typeof value === 'string') return value.length > 0
77
+  if (Array.isArray(value)) return value.length > 0
78
+  if (typeof value === 'number') return true
79
+  return false
80
+}
81
+
82
+const initSelection = async (value: any) => {
83
+  if (!hasValue(value)) return
84
+  
85
+  isInitializing.value = true
86
+  try {
87
+    const userIds = Array.isArray(value) ? value : [value]
88
+    const userOptions = await fetchUsersByIds(userIds as (string | number)[])
89
+    options.value = userOptions
90
+    
91
+    await nextTick()
92
+    selectedValue.value = value
93
+  } catch (error) {
94
+    console.error('初始化选中失败:', error)
95
+  } finally {
96
+    isInitializing.value = false
97
+  }
98
+}
99
+
86 100
 watch(() => props.modelValue, async (newValue, oldValue) => {
87
-  // 只有当值从无到有或值发生变化时才执行回显
88
-  if (newValue && newValue.length > 0 && newValue !== oldValue) {
89
-    isInitializing.value = true
90
-    try {
91
-      const userIds = Array.isArray(newValue) ? newValue : [newValue]
92
-      const userOptions = await fetchUsersByIds(userIds)
93
-      options.value = userOptions
94
-      
95
-      // 设置选中值,但不触发更新事件
96
-      selectedValue.value = newValue
97
-    } finally {
98
-      isInitializing.value = false
99
-    }
101
+  if (hasValue(newValue) && newValue !== oldValue) {
102
+    await initSelection(newValue)
100 103
   }
101 104
 }, { immediate: true })
102 105
 
103
-// 监听选中值变化并触发更新事件
104 106
 watch(selectedValue, (newValue) => {
105
-  // 只有在非初始化状态下才触发更新事件
106 107
   if (!isInitializing.value) {
107 108
     emits('update:modelValue', newValue)
108 109
   }
109 110
 })
110 111
 
111
-// 组件销毁时清空数据
112 112
 onUnmounted(() => {
113 113
   options.value = []
114 114
   selectedValue.value = props.multiple ? [] : ''

+ 30 - 16
src/views/equipManage/equipLedger/index.vue

@@ -6,6 +6,10 @@
6 6
         <el-form-item label="设备名称" prop="equipmentName">
7 7
           <el-input v-model="queryParams.equipmentName" placeholder="请输入设备名称" clearable style="width: 200px" />
8 8
         </el-form-item>
9
+
10
+        <el-form-item label="设备序列号" prop="equipmentSerialNumber">
11
+          <el-input v-model="queryParams.equipmentSerialNumber" placeholder="请输入设备序列号" clearable style="width: 200px" />
12
+        </el-form-item>
9 13
         <el-form-item label="使用状态" prop="usageStatus">
10 14
           <el-select v-model="queryParams.usageStatus" placeholder="请选择使用状态" clearable style="width: 200px">
11 15
             <el-option v-for="dict in equipment_usage_status" :key="dict.value" :label="dict.label"
@@ -53,11 +57,13 @@
53 57
         </template>
54 58
       </el-table-column>
55 59
       <el-table-column label="设备名称" prop="equipmentName" align="center" min-width="150" show-overflow-tooltip />
60
+      <el-table-column label="设备种类" prop="equipmentType" align="center" min-width="120" show-overflow-tooltip />
56 61
       <el-table-column label="设备序列号" prop="equipmentSerialNumber" align="center" min-width="150"
57 62
         show-overflow-tooltip />
58 63
       <el-table-column label="安装位置" prop="installationLocation" align="center" min-width="180" show-overflow-tooltip>
59 64
         <template #default="scope">
60
-          <span>{{ scope.row.terminlName }}{{scope.row.terminlName?'/':''}}{{ scope.row.regionalName }}{{scope.row.regionalName?'/':''}}{{ scope.row.channelName }}</span>
65
+          <span>{{ scope.row.terminlName }}{{ scope.row.terminlName ? '/' : '' }}{{ scope.row.regionalName
66
+            }}{{ scope.row.regionalName ? '/' : '' }}{{ scope.row.channelName }}</span>
61 67
         </template>
62 68
       </el-table-column>
63 69
       <el-table-column label="使用状态" prop="usageStatus" align="center" min-width="100">
@@ -72,8 +78,8 @@
72 78
         show-overflow-tooltip />
73 79
       <el-table-column label="定/自检小组组员2" prop="inspectionTeamMember2Name" align="center" min-width="120"
74 80
         show-overflow-tooltip />
75
-      <el-table-column label="最近定检/自检日期" prop="inspectionSelfCheckDate" align="center" min-width="120" />
76
-      <el-table-column label="操作" align="center" width="220" fixed="right">
81
+      <el-table-column label="最近定检/自检到期日期" prop="nextInspectionDueDate" align="center" min-width="120" />
82
+      <el-table-column label="操作" align="center" width="220" fixed="right" class-name="operation-column">
77 83
         <template #default="scope">
78 84
           <el-button link type="primary" icon="View" @click="handleDetail(scope.row)">详情</el-button>
79 85
           <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)">编辑</el-button>
@@ -87,7 +93,8 @@
87 93
       v-model:limit="queryParams.pageSize" @pagination="getList" />
88 94
 
89 95
     <!-- 编辑/详情弹窗 -->
90
-    <el-dialog :title="dialog.title" v-model="dialog.visible" width="1000px" :close-on-click-modal="false">
96
+    <el-dialog :title="dialog.title" v-model="dialog.visible" width="1000px" :close-on-click-modal="false"
97
+      destroy-on-close>
91 98
       <el-form :model="form" ref="formRef" :rules="rules" label-width="160px">
92 99
         <el-row :gutter="20">
93 100
           <el-col :span="12">
@@ -311,6 +318,8 @@ const queryParams = reactive({
311 318
   pageNum: 1,
312 319
   pageSize: 10,
313 320
   equipmentName: '',
321
+
322
+  equipmentSerialNumber: '',
314 323
   usageStatus: '',
315 324
   inspectionSelfCheckDate: '',
316 325
   inspectionTeamUserName: ''
@@ -338,9 +347,9 @@ const form = reactive({
338 347
   inspectionSelfCheckDate: '',
339 348
   inspectionSelfCheckCycle: 0,
340 349
   nextInspectionDueDate: '',
341
-  inspectionTeamLeaderId: '',
342
-  inspectionTeamMember1Id: '',
343
-  inspectionTeamMember2Id: '',
350
+  inspectionTeamLeaderId: null,
351
+  inspectionTeamMember1Id: null,
352
+  inspectionTeamMember2Id: null,
344 353
   initialAcceptanceStatus: '',
345 354
   baseAttachmentList: [],
346 355
   equipmentInspectionRecordList: []
@@ -421,9 +430,9 @@ function handleEdit(row) {
421 430
       regionalCode: response.data.regionalCode,
422 431
       channelCode: response.data.channelCode
423 432
     }
424
-    form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || ''
425
-    form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || ''
426
-    form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || ''
433
+    form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || null
434
+    form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || null;
435
+    form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || null;
427 436
     formDisabled.value = false
428 437
     dialog.title = '编辑设备'
429 438
     dialog.visible = true
@@ -449,9 +458,9 @@ function handleDetail(row) {
449 458
       regionalCode: response.data.regionalCode,
450 459
       channelCode: response.data.channelCode
451 460
     }
452
-    form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || ''
453
-    form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || ''
454
-    form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || ''
461
+    form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || null
462
+    form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || null;
463
+    form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || null;
455 464
     formDisabled.value = true
456 465
     dialog.title = '设备详情'
457 466
     dialog.visible = true
@@ -523,9 +532,9 @@ function resetForm() {
523 532
     inspectionSelfCheckDate: '',
524 533
     inspectionSelfCheckCycle: 0,
525 534
     nextInspectionDueDate: '',
526
-    inspectionTeamLeaderId: '',
527
-    inspectionTeamMember1Id: '',
528
-    inspectionTeamMember2Id: '',
535
+    inspectionTeamLeaderId: null,
536
+    inspectionTeamMember1Id: null,
537
+    inspectionTeamMember2Id: null,
529 538
     initialAcceptanceStatus: '',
530 539
     baseAttachmentList: [],
531 540
     equipmentInspectionRecordList: []
@@ -669,4 +678,9 @@ onMounted(() => {
669 678
 :deep(.row-yellow) {
670 679
   background-color: rgba(255, 206, 86, 0.3) !important;
671 680
 }
681
+
682
+:deep(.operation-column) {
683
+  background-color: transparent !important;
684
+
685
+}
672 686
 </style>