Bladeren bron

pms 编辑保养计划 保养计划详情 累计运行里程 兼容 运行记录模板包含多个累计类型的属性

zhangcl 1 maand geleden
bovenliggende
commit
8a695a28a1

+ 32 - 0
src/views/pms/maintenance/IotMaintenancePlan.vue

@@ -959,6 +959,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 = {

+ 92 - 55
src/views/pms/maintenance/IotMaintenancePlanDetail.vue

@@ -20,19 +20,6 @@
               <el-input type="text" v-model="formData.serialNumber" disabled/>
             </el-form-item>
           </el-col>
-          <!--
-          <el-col :span="8">
-            <el-form-item label="责任人" prop="responsiblePerson">
-              <el-select v-model="formData.responsiblePerson" filterable clearable style="width: 100%" disabled>
-                <el-option
-                  v-for="item in deptUsers"
-                  :key="item.id"
-                  :label="item.nickname"
-                  :value="item.id"
-                />
-              </el-select>
-            </el-form-item>
-          </el-col> -->
           <el-col :span="24">
             <el-form-item :label="t('form.remark')" prop="remark">
               <el-input v-model="formData.remark" type="textarea" :placeholder="t('deviceForm.remarkHolder')" disabled/>
@@ -55,8 +42,18 @@
         />
         <el-table-column :label="t('monitor.deviceCode')" align="center" prop="deviceCode" />
         <el-table-column :label="t('monitor.deviceName')" align="center" prop="deviceName" />
-        <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter"/>
-        <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter"/>
+        <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter">
+          <template #default="{ row }">
+            {{ row.totalRunTime ?? row.tempTotalRunTime }}
+          </template>
+        </el-table-column>
+        <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter">
+          <template #default="{ row }">
+            {{ row.totalMileage ?? row.tempTotalMileage }}
+          </template>
+        </el-table-column>
+        <el-table-column label="tempTotalRunTime" align="center" prop="tempTotalRunTime" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
+        <el-table-column label="tempTotalMileage" align="center" prop="tempTotalMileage" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
         <el-table-column :label="t('bomList.bomNode')" align="center" prop="name" />
         <el-table-column :label="t('main.mileage')" key="mileageRule" width="80">
           <template #default="scope">
@@ -68,13 +65,6 @@
             />
           </template>
         </el-table-column>
-        <!--
-        <el-table-column label="里程周期(H)" align="center" prop="nextRunningKilometers" :formatter="erpPriceTableColumnFormatter">
-          <template #default="scope">
-            <el-input v-model="scope.row.nextRunningKilometers" />
-          </template>
-        </el-table-column>
-        -->
         <el-table-column :label="t('main.runTime')" key="runningTimeRule" width="90">
           <template #default="scope">
             <el-switch
@@ -85,13 +75,6 @@
             />
           </template>
         </el-table-column>
-        <!--
-        <el-table-column label="时间周期(H)" align="center" prop="nextRunningTime" :formatter="erpPriceTableColumnFormatter">
-          <template #default="scope">
-            <el-input v-model="scope.row.nextRunningTime" />
-          </template>
-        </el-table-column>
-        -->
         <el-table-column :label="t('main.date')" key="naturalDateRule" width="80">
           <template #default="scope">
             <el-switch
@@ -102,28 +85,10 @@
             />
           </template>
         </el-table-column>
-        <!--
-        <el-table-column label="自然日期(D)" align="center" prop="nextNaturalDate" :formatter="erpPriceTableColumnFormatter">
-          <template #default="scope">
-            <el-input v-model="scope.row.nextNaturalDate" />
-          </template>
-        </el-table-column>
-        -->
         <el-table-column :label="t('workplace.operation')" align="center" min-width="120px">
           <template #default="scope">
             <div style="display: flex; justify-content: center; align-items: center; width: 100%">
               <div>
-                <!--
-                <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
-                <el-button
-                  style="vertical-align: middle"
-                  link
-                  type="danger"
-                  @click="handleDelete(scope.row.id+'-'+scope.row.bomNodeId)"
-                >
-                  移除
-                </el-button>
-                -->
               </div>
               <!-- 新增配置按钮 -->
               <div style="margin-left: 12px">
@@ -310,6 +275,70 @@
           />
         </el-form-item>
       </div>
+
+      <!-- 运行记录模板中 多个 累计运行时长 累计运行里程 属性匹配-->
+      <div class="form-group"
+           v-if="(configDialog.current?.runningTimeRule === 0 || configDialog.current?.mileageRule === 0)
+            && (configDialog.current?.timeAccumulatedAttrs?.length || configDialog.current?.mileageAccumulatedAttrs?.length)
+            && !configDialog.current.totalRunTime && !configDialog.current.totalMileage" >
+        <div class="group-title">{{ t('mainPlan.accumulatedParams') }}</div>
+        <!-- 累计运行时长 -->
+        <el-form-item
+          v-if="configDialog.current?.runningTimeRule === 0
+          && configDialog.current?.timeAccumulatedAttrs?.length && !configDialog.current.totalRunTime"
+          :label="t('mainPlan.accumulatedRunTime')"
+          prop="accumulatedTimeOption"
+          :rules="[{
+            required: configDialog.current?.runningTimeRule === 0 && configDialog.current?.timeAccumulatedAttrs?.length,
+            message: '请选择累计运行时长',
+            trigger: 'change'
+          }]"
+        >
+          <el-select
+            v-model="configDialog.form.accumulatedTimeOption"
+            placeholder="请选择累计运行时长"
+            style="width: 80%"
+            clearable
+            @change="handleAccumulatedTimeChange"
+            disabled
+          >
+            <el-option
+              v-for="(item, index) in configDialog.current.timeAccumulatedAttrs"
+              :key="`time-${item.pointName}-${index}`"
+              :label="item.pointName"
+              :value="item.pointName"
+            />
+          </el-select>
+        </el-form-item>
+        <!-- 累计运行公里数 -->
+        <el-form-item
+          v-if="configDialog.current?.mileageRule === 0
+          && configDialog.current?.mileageAccumulatedAttrs?.length && !configDialog.current.totalMileage"
+          :label="t('mainPlan.accumulatedMileage')"
+          prop="accumulatedMileageOption"
+          :rules="[{
+            required: configDialog.current?.mileageRule === 0 && configDialog.current?.mileageAccumulatedAttrs?.length,
+            message: '请选择累计运行公里数',
+            trigger: 'change'
+          }]"
+        >
+          <el-select
+            v-model="configDialog.form.accumulatedMileageOption"
+            placeholder="请选择累计运行公里数"
+            style="width: 80%"
+            clearable
+            @change="handleAccumulatedMileageChange"
+            disabled
+          >
+            <el-option
+              v-for="(item, index) in configDialog.current.mileageAccumulatedAttrs"
+              :key="`mileage-${item.pointName}-${index}`"
+              :label="item.pointName"
+              :value="item.pointName"
+            />
+          </el-select>
+        </el-form-item>
+      </div>
     </el-form>
     <template #footer>
       <el-button @click="configDialog.visible = false">{{ t('common.cancel') }}</el-button>
@@ -326,7 +355,6 @@ import { ref } from 'vue'
 import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
 import { IotMaintenancePlanApi, IotMaintenancePlanVO } from '@/api/pms/maintenance'
 import { useTagsViewStore } from '@/store/modules/tagsView'
-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";
@@ -381,7 +409,10 @@ const configDialog = reactive({
     // 提前量
     kiloCycleLead: 0,
     timePeriodLead: 0,
-    naturalDatePeriodLead: 0
+    naturalDatePeriodLead: 0,
+    // 多个累计时长 累计里程 匹配
+    accumulatedTimeOption: null,    // 累计运行时长选项
+    accumulatedMileageOption: null, // 累计运行公里数选项
   }
 })
 
@@ -412,6 +443,10 @@ const openConfigDialog = (row: IotMaintenanceBomVO) => {
     timePeriodLead: row.timePeriodLead || 0,
     naturalDatePeriodLead: row.naturalDatePeriodLead || 0
   }
+
+  configDialog.form.accumulatedTimeOption = row.code || null;
+  configDialog.form.accumulatedMileageOption = row.type || null;
+
   configDialog.visible = true
 }
 
@@ -541,6 +576,14 @@ const close = () => {
   push({ name: 'IotMaintenancePlan', params:{}})
 }
 
+// 累计运行时长变更
+const handleAccumulatedTimeChange = (option) => {
+}
+
+// 累计运行公里数变更
+const handleAccumulatedMileageChange = (option) => {
+}
+
 /** 提交表单 */
 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
 const submitForm = async () => {
@@ -737,12 +780,6 @@ onMounted(async () => {
       lastNaturalDate: item.lastNaturalDate ? dayjs(item.lastNaturalDate).format('YYYY-MM-DD') : null
     }))
   }
-  /* } else {
-    formType.value = 'create';
-    const { wsCache } = useCache()
-    const userInfo = wsCache.get(CACHE_KEY.USER)
-    formData.value.responsiblePerson = userInfo.user.id;
-  } */
 })
 const handleDelete = async (str: string) => {
   try {

+ 213 - 8
src/views/pms/maintenance/IotMaintenancePlanEdit.vue

@@ -59,8 +59,18 @@
         <el-table-column label="设备id" align="center" prop="deviceId" v-if="false"/>
         <el-table-column :label="t('iotMaintain.deviceCode')" align="center" prop="deviceCode" />
         <el-table-column :label="t('iotMaintain.deviceName')" align="center" prop="deviceName" />
-        <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter"/>
-        <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter"/>
+        <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter">
+          <template #default="{ row }">
+            {{ row.totalRunTime ?? row.tempTotalRunTime }}
+          </template>
+        </el-table-column>
+        <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter">
+          <template #default="{ row }">
+            {{ row.totalMileage ?? row.tempTotalMileage }}
+          </template>
+        </el-table-column>
+        <el-table-column label="tempTotalRunTime" align="center" prop="tempTotalRunTime" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
+        <el-table-column label="tempTotalMileage" align="center" prop="tempTotalMileage" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
         <el-table-column :label="t('bomList.bomNode')" align="center" prop="name" />
         <el-table-column :label="t('main.mileage')" key="mileageRule" width="80">
           <template #default="scope">
@@ -68,6 +78,7 @@
               v-model="scope.row.mileageRule"
               :active-value="0"
               :inactive-value="1"
+              @change="handleRuleChange(scope.row, 'mileage')"
             />
           </template>
         </el-table-column>
@@ -77,6 +88,7 @@
               v-model="scope.row.runningTimeRule"
               :active-value="0"
               :inactive-value="1"
+              @change="handleRuleChange(scope.row, 'runningTime')"
             />
           </template>
         </el-table-column>
@@ -295,6 +307,69 @@
           />
         </el-form-item>
       </div>
+
+      <!-- 运行记录模板中 多个 累计运行时长 累计运行里程 属性匹配-->
+      <div class="form-group"
+           v-if="(configDialog.current?.runningTimeRule === 0 || configDialog.current?.mileageRule === 0)
+            && (configDialog.current?.timeAccumulatedAttrs?.length || configDialog.current?.mileageAccumulatedAttrs?.length)
+            && !configDialog.current.totalRunTime && !configDialog.current.totalMileage" >
+        <div class="group-title">{{ t('mainPlan.accumulatedParams') }}</div>
+        <!-- 累计运行时长 -->
+        <el-form-item
+          v-if="configDialog.current?.runningTimeRule === 0
+          && configDialog.current?.timeAccumulatedAttrs?.length && !configDialog.current.totalRunTime"
+          :label="t('mainPlan.accumulatedRunTime')"
+          prop="accumulatedTimeOption"
+          :rules="[{
+            required: configDialog.current?.runningTimeRule === 0 && configDialog.current?.timeAccumulatedAttrs?.length,
+            message: '请选择累计运行时长',
+            trigger: 'change'
+          }]"
+        >
+          <el-select
+            v-model="configDialog.form.accumulatedTimeOption"
+            placeholder="请选择累计运行时长"
+            style="width: 80%"
+            clearable
+            @change="handleAccumulatedTimeChange"
+          >
+            <el-option
+              v-for="(item, index) in configDialog.current.timeAccumulatedAttrs"
+              :key="`time-${item.pointName}-${index}`"
+              :label="item.pointName"
+              :value="item.pointName"
+            />
+          </el-select>
+        </el-form-item>
+        <!-- 累计运行公里数 -->
+        <el-form-item
+          v-if="configDialog.current?.mileageRule === 0
+          && configDialog.current?.mileageAccumulatedAttrs?.length && !configDialog.current.totalMileage"
+          :label="t('mainPlan.accumulatedMileage')"
+          prop="accumulatedMileageOption"
+          :rules="[{
+            required: configDialog.current?.mileageRule === 0 && configDialog.current?.mileageAccumulatedAttrs?.length,
+            message: '请选择累计运行公里数',
+            trigger: 'change'
+          }]"
+        >
+          <el-select
+            v-model="configDialog.form.accumulatedMileageOption"
+            placeholder="请选择累计运行公里数"
+            style="width: 80%"
+            clearable
+            @change="handleAccumulatedMileageChange"
+          >
+            <el-option
+              v-for="(item, index) in configDialog.current.mileageAccumulatedAttrs"
+              :key="`mileage-${item.pointName}-${index}`"
+              :label="item.pointName"
+              :value="item.pointName"
+            />
+          </el-select>
+        </el-form-item>
+      </div>
+
     </el-form>
     <template #footer>
       <el-button @click="configDialog.visible = false">{{ t('common.cancel') }}</el-button>
@@ -392,7 +467,10 @@ const configDialog = reactive({
     // 提前量
     kiloCycleLead: 0,
     timePeriodLead: 0,
-    naturalDatePeriodLead: 0
+    naturalDatePeriodLead: 0,
+    // 多个累计时长 累计里程 匹配
+    accumulatedTimeOption: null,    // 累计运行时长选项
+    accumulatedMileageOption: null, // 累计运行公里数选项
   }
 })
 
@@ -424,8 +502,24 @@ const openConfigDialog = (row: IotMaintenanceBomVO) => {
     // 提前量
     kiloCycleLead: row.kiloCycleLead || 0,
     timePeriodLead: row.timePeriodLead || 0,
-    naturalDatePeriodLead: row.naturalDatePeriodLead || 0
+    naturalDatePeriodLead: row.naturalDatePeriodLead || 0,
+    // 多个累计时长 累计里程 匹配
+    accumulatedTimeOption: null,    // 累计运行时长选项
+    accumulatedMileageOption: null, // 累计运行公里数选项
   }
+
+  // 初始化累计参数选择
+  /* configDialog.form.accumulatedTimeOption = row.isRuntimeFromTemp
+    ? row.code
+    : null;
+
+  configDialog.form.accumulatedMileageOption = row.isMileageFromTemp
+    ? row.type
+    : null; */
+
+  configDialog.form.accumulatedTimeOption = row.code || null;
+  configDialog.form.accumulatedMileageOption = row.type || null;
+
   configDialog.visible = true
 }
 
@@ -435,6 +529,21 @@ const saveConfig = () => {
     if (!valid) return
     if (!configDialog.current) return
 
+    // 累计运行时长配置 校验逻辑
+    if (configDialog.current.runningTimeRule === 0 &&
+      configDialog.current.timeAccumulatedAttrs?.length &&
+      !configDialog.form.accumulatedTimeOption) {
+      message.error('请选择累计运行时长');
+      return;
+    }
+    // 累计运行公里数配置 校验逻辑
+    if (configDialog.current.mileageRule === 0 &&
+      configDialog.current.mileageAccumulatedAttrs?.length &&
+      !configDialog.form.accumulatedMileageOption) {
+      message.error('请选择累计运行公里数');
+      return;
+    }
+
     // 动态校验逻辑
     const requiredFields = []
     if (configDialog.current.mileageRule === 0) {
@@ -476,12 +585,53 @@ const saveConfig = () => {
       ? dayjs(configDialog.form.lastNaturalDate).valueOf()
       : null // 改为null而不是0
 
-    // 更新当前行的数据
-    Object.assign(configDialog.current, {
+    const updateData = {
       ...configDialog.form,
-      // Date对象 -> 时间戳
       lastNaturalDate: finalDate,
-    })
+    };
+
+    // 关闭保养规则,无论是否有选择值,都清除相关数据
+    // 处理累计运行时长
+    if (configDialog.current.runningTimeRule !== 0) {
+      configDialog.current.code = null;
+      configDialog.current.totalRunTime = null;
+      configDialog.form.accumulatedTimeOption = null; // 清除选择值
+    } else if (configDialog.form.accumulatedTimeOption) {
+      // 查找选中的累计运行时长项
+      const selectedTimeOption = configDialog.current.timeAccumulatedAttrs?.find(
+        item => item.pointName === configDialog.form.accumulatedTimeOption
+      );
+      if (selectedTimeOption) {
+        configDialog.current.code = selectedTimeOption.pointName;
+        // 优先使用接口值,没有则使用临时值
+        configDialog.current.tempTotalRunTime = selectedTimeOption.totalRunTime;
+        configDialog.current.isRuntimeFromTemp = true;
+        // 只有接口未提供值时才使用临时值
+        if (!configDialog.current.totalRunTime) {
+        }
+      }
+    }
+    // 处理累计运行公里数
+    if (configDialog.current.mileageRule !== 0) {
+      configDialog.current.type = null;
+      configDialog.current.totalMileage = null;
+      configDialog.form.accumulatedMileageOption = null; // 清除选择值
+    } else if (configDialog.form.accumulatedMileageOption) {
+      // 查找选中的累计运行公里数项
+      const selectedMileageOption = configDialog.current.mileageAccumulatedAttrs?.find(
+        item => item.pointName === configDialog.form.accumulatedMileageOption
+      );
+      if (selectedMileageOption) {
+        configDialog.current.type = selectedMileageOption.pointName;
+        configDialog.current.tempTotalMileage = selectedMileageOption.totalRunTime;
+        configDialog.current.isMileageFromTemp = true;
+        if (!configDialog.current.totalMileage) {
+        }
+      }
+    }
+
+    // 更新当前行的数据
+    Object.assign(configDialog.current, updateData);
     configDialog.visible = false
   })
 }
@@ -492,6 +642,53 @@ const queryParams = reactive({
   bomFlag: 'b'
 })
 
+// 处理保养规则变化 取消保养规则 时 清空已经设置的相应保养规则数据
+const handleRuleChange = (row: IotMaintenanceBomVO, ruleType: 'mileage' | 'runningTime') => {
+  // 当规则关闭时(inactive-value=1)
+  console.log('执行了保养规则变化事件' + row.totalRunTime + ' - ' + row.totalMileage)
+  // 当前保养项行已经返回了 totalRunTime totalMileage 数据 不需要再清空 累计运行时长 累计公里数
+
+  // 选择完设备匹配了保养项后 不能直接置空 因为可能是正常的累计时长 累计公里数
+  if (ruleType === 'runningTime' && row.runningTimeRule === 1) {
+    // 清除临时来源的值
+    if (row.isRuntimeFromTemp) {
+      row.totalRunTime = null;
+      row.tempTotalRunTime = null;
+      row.code = null;
+      // row.isRuntimeFromTemp = false;
+    }
+    // 强制清除配置对话框中的值(如果打开的是当前行)
+    if (configDialog.current?.deviceId === row.deviceId
+      && configDialog.current?.bomNodeId === row.bomNodeId) {
+      configDialog.form.accumulatedTimeOption = null;
+    }
+  } else if (ruleType === 'mileage' && row.mileageRule === 1) {
+    if (row.isMileageFromTemp) {
+      row.totalMileage = null;
+      row.tempTotalMileage = null;
+      row.type = null;
+      // row.isMileageFromTemp = false;
+    }
+    // 强制清除配置对话框中的值(如果打开的是当前行)
+    if (configDialog.current?.deviceId === row.deviceId &&
+      configDialog.current?.bomNodeId === row.bomNodeId) {
+      configDialog.form.accumulatedMileageOption = null;
+    }
+  }
+
+  // 如果配置对话框打开的是当前行,同步清除对话框中的选择值
+  if (configDialog.visible && configDialog.current &&
+    configDialog.current.deviceId === row.deviceId &&
+    configDialog.current.bomNodeId === row.bomNodeId) {
+
+    if (ruleType === 'runningTime') {
+      configDialog.form.accumulatedTimeOption = null;
+    } else if (ruleType === 'mileage') {
+      configDialog.form.accumulatedMileageOption = null;
+    }
+  }
+}
+
 const deviceChoose = async(selectedDevices) => {
   const newIds = selectedDevices.map(device => device.id)
   deviceIds.value = [...new Set([...deviceIds.value, ...newIds])]
@@ -767,6 +964,14 @@ const sortDeviceList = (devices: IotMaintenanceBomVO[]) => {
   })
 };
 
+// 累计运行时长变更
+const handleAccumulatedTimeChange = (option) => {
+}
+
+// 累计运行公里数变更
+const handleAccumulatedMileageChange = (option) => {
+}
+
 /** 重置表单 */
 const resetForm = () => {
   formData.value = {