Browse Source

pms 保养计划明细 功能优化

zhangcl 3 months ago
parent
commit
40b3ece9df
1 changed files with 46 additions and 8 deletions
  1. 46 8
      src/views/pms/maintenance/IotMaintenancePlan.vue

+ 46 - 8
src/views/pms/maintenance/IotMaintenancePlan.vue

@@ -186,11 +186,12 @@
         label="上次保养自然日期(D)"
         prop="lastNaturalDate"
       >
-        <el-input-number
+        <el-date-picker
           v-model="configDialog.form.lastNaturalDate"
-          :precision="1"
-          :min="0"
-          controls-position="right"
+          type="date"
+          placeholder="选择日期"
+          format="YYYY-MM-DD"
+          value-format="YYYY-MM-DD"
         />
       </el-form-item>
     </el-form>
@@ -214,6 +215,7 @@ import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
 import MainPlanDeviceList from "@/views/pms/maintenance/MainPlanDeviceList.vue";
 import * as DeptApi from "@/api/system/dept";
 import {erpPriceTableColumnFormatter} from "@/utils";
+import dayjs from 'dayjs'
 
 /** 保养计划 表单 */
 defineOptions({ name: 'IotAddMainPlan' })
@@ -255,17 +257,28 @@ const configDialog = reactive({
   form: {
     lastRunningKilometers: 0,
     lastRunningTime: 0,
-    lastNaturalDate: 0
+    lastNaturalDate: ''
   }
 })
 
 // 打开配置对话框
 const openConfigDialog = (row: IotMaintenanceBomVO) => {
   configDialog.current = row
+
+  // 处理日期初始化(核心修改)
+  let initialDate = ''
+  if (row.lastNaturalDate) {
+    // 如果已有值:时间戳 -> 日期字符串
+    initialDate = dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
+  } else {
+    // 如果无值:设置默认值避免1970问题
+    initialDate = ''
+  }
+
   configDialog.form = {
     lastRunningKilometers: row.lastRunningKilometers || 0,
     lastRunningTime: row.lastRunningTime || 0,
-    lastNaturalDate: row.lastNaturalDate || 0
+    lastNaturalDate: initialDate
   }
   configDialog.visible = true
 }
@@ -273,8 +286,32 @@ const openConfigDialog = (row: IotMaintenanceBomVO) => {
 // 保存配置
 const saveConfig = () => {
   if (!configDialog.current) return
+
+  // 强制校验逻辑
+  if (configDialog.current.naturalDateRule === 0) {
+    if (!configDialog.form.lastNaturalDate) {
+      message.error('必须选择自然日期')
+      return
+    }
+
+    // 验证日期有效性
+    const dateValue = dayjs(configDialog.form.lastNaturalDate)
+    if (!dateValue.isValid()) {
+      message.error('日期格式不正确')
+      return
+    }
+  }
+
+  // 转换逻辑(关键修改)
+  const finalDate = configDialog.form.lastNaturalDate
+    ? dayjs(configDialog.form.lastNaturalDate).valueOf()
+    : null // 改为null而不是0
+
   // 更新当前行的数据
-  Object.assign(configDialog.current, configDialog.form)
+  Object.assign(configDialog.current, {
+    ...configDialog.form,
+    lastNaturalDate: finalDate
+  })
   configDialog.visible = false
 }
 
@@ -318,6 +355,7 @@ const deviceChoose = async(selectedDevices) => {
     nextRunningKilometers: 0,
     nextRunningTime: 0,
     nextNaturalDate: 0,
+    lastNaturalDate: null, // 初始化为null而不是0
   }))
   // 获取选择的设备相关的id数组
   newItems.forEach(item => {
@@ -439,7 +477,7 @@ const validateTableData = (): boolean => {
     }
     // 自然日期校验逻辑
     if (row.naturalDateRule === 0) {
-      if (!row.nextNaturalDate || row.nextNaturalDate <= 0) {
+      if (!row.nextNaturalDate) {
         errorMessages.push(`第 ${rowNumber} 行:开启自然日期规则必须填写有效的自然日期周期`)
         isValid = false
       }