Ver código fonte

pms 保养计划 保养项 排序

zhangcl 1 mês atrás
pai
commit
98ab954193

+ 1 - 0
src/views/pms/device/personlog/ConfigDevicePerson.vue

@@ -443,6 +443,7 @@ const submitRelations = async () => {
       return relation.deviceIds.map(deviceId => ({
         deviceId,
         userIds: relation.userIds,
+        userNames: relation.userNames,
         reason: relation.reason
       }))
     })

+ 37 - 2
src/views/pms/maintenance/IotMaintenancePlanEdit.vue

@@ -559,7 +559,8 @@ const deviceChoose = async(selectedDevices) => {
       list.value.push(item)
     }
   })
-
+  // 排序保养项
+  applySorting()
   // 新增数据后自动跳转到第一页
   currentPage.value = 1
 }
@@ -726,6 +727,38 @@ const validateTableData = (): boolean => {
   return isValid
 }
 
+// 修改后的排序应用方法
+const applySorting = () => {
+  // 创建新数组并排序
+  const sortedList = sortDeviceList(list.value)
+
+  // 使用Vue的响应式方法更新数组
+  list.value = sortedList
+
+  // 重置分页到第一页
+  currentPage.value = 1
+}
+
+// 保养项排序函数
+const sortDeviceList = (devices: IotMaintenanceBomVO[]) => {
+  // 使用slice()创建数组副本,避免修改原数组
+  return devices.slice().sort((a, b) => {
+    // 处理可能的空值
+    const aCode = a.deviceCode || ''
+    const bCode = b.deviceCode || ''
+    const aName = a.name || ''
+    const bName = b.name || ''
+
+    // 设备编码排序
+    if (aCode !== bCode) {
+      return aCode.localeCompare(bCode)
+    }
+
+    // 保养项名称排序
+    return aName.localeCompare(bName)
+  })
+};
+
 /** 重置表单 */
 const resetForm = () => {
   formData.value = {
@@ -773,9 +806,9 @@ onMounted(async () => {
       if (Array.isArray(data)) {
         list.value = data.map(item => ({
           ...item,
-          // 这里可以添加必要的字段转换(如果有日期等需要格式化的字段)
           lastNaturalDate: item.lastNaturalDate
         }))
+        applySorting()
       }
     }
   } else {
@@ -798,6 +831,8 @@ const handleDelete = async (str: string) => {
     const index = list.value.findIndex((item) => (item.deviceId+'-'+item.bomNodeId) === str)
     if (index !== -1) {
       list.value.splice(index, 1)
+      // 删除保养项后对保养项重新排序
+      applySorting()
       deviceIds.value = []
     }
     // 更新设备ID列表(需要检查是否还有该设备的其他项)

+ 1 - 1
src/views/pms/maintenance/index.vue

@@ -13,7 +13,7 @@
           :model="queryParams"
           ref="queryFormRef"
           :inline="true"
-          label-width="68px"
+          label-width="80px"
         >
           <el-form-item :label="t('main.planCode')" prop="serialNumber">
             <el-input