Explorar o código

Merge branch 'qhse_file' of shuzhihua/pms-iot-vue into master

yanghao hai 3 días
pai
achega
37344e3832

+ 48 - 0
src/views/pms/constructionDailyReport/components/ConstructionDailyReportDrawer.vue

@@ -23,7 +23,43 @@ const submitLoading = ref(false)
 const drawerMode = ref<'edit' | 'readonly'>('edit')
 const form = ref<ConstructionDailyReportRow>(createEmptyConstructionDailyReport())
 const message = useMessage()
+const nonProductionFields: Array<keyof ConstructionDailyReportRow> = [
+  'accidentTime',
+  'repairTime',
+  'selfStopTime',
+  'complexityTime',
+  'relocationTime',
+  'rectificationTime',
+  'waitingStopTime',
+  'winterBreakTime',
+  'partyaDesign',
+  'partyaPrepare',
+  'partyaResource',
+  'otherNptTime'
+]
+
+function getNonProductionTimeTotal() {
+  return nonProductionFields.reduce((sum, field) => sum + Number(form.value[field] || 0), 0)
+}
+
 const rules = reactive<FormRules>({
+  ...Object.fromEntries(
+    nonProductionFields.map((field) => [
+      field,
+      [
+        {
+          validator: (_rule, _value, callback) => {
+            if (getNonProductionTimeTotal() > 24) {
+              callback(new Error('非生产时间总和不能超过24H'))
+              return
+            }
+            callback()
+          },
+          trigger: ['blur', 'change']
+        }
+      ]
+    ])
+  ),
   malfunction: [
     {
       validator: (_rule, value, callback) => {
@@ -119,6 +155,18 @@ watch(
   }
 )
 
+watch(
+  () => nonProductionFields.map((field) => form.value[field]),
+  () => {
+    if (!disabled.value) {
+      nextTick(() => {
+        formRef.value?.validateField(nonProductionFields as string[])
+      })
+    }
+  },
+  { deep: true }
+)
+
 defineExpose({ handleOpenForm })
 </script>