瀏覽代碼

pms 保养工单 保养距离

zhangcl 2 月之前
父節點
當前提交
99a90f3838
共有 2 個文件被更改,包括 84 次插入4 次删除
  1. 33 3
      src/views/pms/iotmainworkorder/IotMainWorkOrder.vue
  2. 51 1
      src/views/pms/iotmainworkorder/index.vue

+ 33 - 3
src/views/pms/iotmainworkorder/IotMainWorkOrder.vue

@@ -787,6 +787,12 @@ const getMaterialCount = (bomNodeId: number) => {
   return materialList.value.filter(item => item.bomNodeId === bomNodeId).length
 }
 
+const hasDelay = (row) => {
+  return row.delayKilometers > 0 ||
+    row.delayNaturalDate > 0 ||
+    row.delayDuration > 0
+}
+
 const close = () => {
   delView(unref(currentRoute))
   push({ name: 'IotMainWorkOrder', params:{}})
@@ -856,10 +862,8 @@ const configFormRules = reactive({
 const validateTableData = (): boolean => {
   let isValid = true
   const errorMessages: string[] = []
-  const noRulesErrorMessages: string[] = []  // 未设置任何保养项规则 的错误提示信息
-  const noRules: string[] = []  // 行记录中设置了保养规则的记录数量
-  const configErrors: string[] = []   // 保养规则配置弹出框
   let shouldBreak = false;
+  const materialRequiredErrors: string[] = []  // 物料必填错误
 
   if (list.value.length === 0) {
     errorMessages.push('工单明细不存在')
@@ -869,6 +873,26 @@ const validateTableData = (): boolean => {
     return isValid
   }
 
+  // 新增物料必填校验(仅在非委外模式下检查)
+  if (formData.value.outsourcingFlag !== 1) { // 非委外模式
+    list.value.forEach((row, index) => {
+      const rowNumber = index + 1
+      const deviceIdentifier = `${row.deviceCode}-${row.name}`
+
+      // 检查是否设置了推迟保养
+      const hasDelay =
+        (row.delayKilometers || 0) > 0 ||
+        (row.delayNaturalDate || 0) > 0 ||
+        (row.delayDuration || 0) > 0
+
+      // 未设置推迟保养且未选择物料
+      if (!hasDelay && getMaterialCount(row.bomNodeId) === 0) {
+        materialRequiredErrors.push(`第${rowNumber}行【${deviceIdentifier}】必须选择物料`)
+        isValid = false
+      }
+    })
+  }
+
   list.value.forEach((row, index) => {
     if (shouldBreak) return;
     const rowNumber = index + 1 // 用户可见的行号从1开始
@@ -881,9 +905,15 @@ const validateTableData = (): boolean => {
   if (errorMessages.length > 0) {
     message.error('设备状态错误')
   }
+  // 合并错误信息
+  if (materialRequiredErrors.length > 0) {
+    message.error(materialRequiredErrors.join('\n'))
+  }
   return isValid
 }
 
+
+
 /** 重置表单 */
 const resetForm = () => {
   formData.value = {

+ 51 - 1
src/views/pms/iotmainworkorder/index.vue

@@ -83,7 +83,13 @@
           <dict-tag :type="DICT_TYPE.PMS_MAIN_WORK_ORDER_RESULT" :value="scope.row.result" />
         </template>
       </el-table-column>
-      <el-table-column label="距离保养" align="center" prop="maintenanceInterval" />
+      <el-table-column label="距离保养" align="center">
+        <template #default="scope">
+          <span :class="getDistanceClass(scope.row.mainDistance)">
+            {{ scope.row.mainDistance }}
+          </span>
+        </template>
+      </el-table-column>
       <el-table-column label="工单类型" align="center" prop="type" >
         <template #default="scope">
           <dict-tag :type="DICT_TYPE.PMS_MAIN_WORK_ORDER_TYPE" :value="scope.row.type" />
@@ -212,6 +218,31 @@ const resultOptions = computed(() => [
   ...getStrDictOptions(DICT_TYPE.PMS_MAIN_WORK_ORDER_RESULT)
 ])
 
+const getDistanceClass = (distance: number | string | null) => {
+  if (distance === null || distance === undefined) return '';
+
+  // 如果是数字类型,直接处理
+  if (typeof distance === 'number') {
+    return distance < 0 ? 'negative-distance' :
+      distance > 0 ? 'positive-distance' : '';
+  }
+
+  // 如果是字符串,提取数字部分
+  if (typeof distance === 'string') {
+    // 使用正则提取数字部分(包括负号、小数点和科学计数法)
+    const numericPart = distance.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/)?.[0];
+
+    // 如果提取到数字部分,转换为数值
+    if (numericPart) {
+      const num = parseFloat(numericPart);
+      return num < 0 ? 'negative-distance' :
+        num > 0 ? 'positive-distance' : '';
+    }
+  }
+
+  return '';
+};
+
 /** 添加/修改操作 */
 const formRef = ref()
 const openForm = (type: string, id?: number) => {
@@ -261,3 +292,22 @@ onMounted(() => {
   getList()
 })
 </script>
+<style scoped>
+/* 正数样式 - 淡绿色 */
+.positive-distance {
+  color: #67c23a;  /* element-plus 成功色 */
+  background-color: rgba(103, 194, 58, 0.1); /* 10% 透明度的淡绿色背景 */
+  padding: 2px 8px;
+  border-radius: 4px;
+  display: inline-block;
+}
+
+/* 负数样式 - 淡红色 */
+.negative-distance {
+  color: #f56c6c;  /* element-plus 危险色 */
+  background-color: rgba(245, 108, 108, 0.1); /* 10% 透明度的淡红色背景 */
+  padding: 2px 8px;
+  border-radius: 4px;
+  display: inline-block;
+}
+</style>