Преглед изворни кода

Merge branch 'master' of http://1.94.244.160:3000/shuzhihua/pms-iot-vue

Zimo пре 3 дана
родитељ
комит
df27a0c30e

+ 77 - 2
src/views/pms/constructionDailyReport/components/ConstructionDailyReportDrawer.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
 import { FiveIotProjectDailyReportApi } from '@/api/pms/fiveconstructiondailyreport'
 import dayjs from 'dayjs'
-import type { FormInstance } from 'element-plus'
+import type { FormInstance, FormRules } from 'element-plus'
 import ConstructionDailyReportFormSection from './ConstructionDailyReportFormSection.vue'
 import {
   createEmptyConstructionDailyReport,
@@ -23,6 +23,57 @@ 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) => {
+        const accidentTime = Number(form.value.accidentTime || 0)
+        if (accidentTime > 0 && !String(value || '').trim()) {
+          callback(new Error('工程质量大于0时,故障情况必填'))
+          return
+        }
+        callback()
+      },
+      trigger: ['blur', 'change']
+    }
+  ]
+})
 
 const drawerTitle = computed(() =>
   drawerMode.value === 'readonly' ? '查看施工日报' : '填报施工日报'
@@ -75,6 +126,7 @@ async function handleSubmit() {
 
   submitLoading.value = true
   try {
+    await formRef.value?.validate()
     const payload = {
       ...form.value,
       taskId: form.value.taskId ?? null
@@ -92,6 +144,29 @@ function handleModelChange(value: ConstructionDailyReportRow) {
   form.value = value
 }
 
+watch(
+  () => form.value.accidentTime,
+  () => {
+    if (!disabled.value) {
+      nextTick(() => {
+        formRef.value?.validateField('malfunction')
+      })
+    }
+  }
+)
+
+watch(
+  () => nonProductionFields.map((field) => form.value[field]),
+  () => {
+    if (!disabled.value) {
+      nextTick(() => {
+        formRef.value?.validateField(nonProductionFields as string[])
+      })
+    }
+  },
+  { deep: true }
+)
+
 defineExpose({ handleOpenForm })
 </script>
 
@@ -106,7 +181,7 @@ defineExpose({ handleOpenForm })
       <span class="text-xl font-bold text-[var(--el-text-color-primary)]">{{ drawerTitle }}</span>
     </template>
 
-    <el-form ref="formRef" :model="form" label-position="top" v-loading="loading">
+    <el-form ref="formRef" :model="form" :rules="rules" label-position="top" v-loading="loading">
       <div class="flex flex-col gap-6">
         <ConstructionDailyReportFormSection
           v-for="section in formSections"

+ 20 - 1
src/views/pms/constructionDailyReport/components/ConstructionDailyReportFormSection.vue

@@ -16,6 +16,25 @@ const emits = defineEmits<{
   (e: 'update:model', value: ConstructionDailyReportRow): void
 }>()
 
+const displayFields = computed(() => {
+  const fields = [...props.section.fields]
+  const productionStatusIndex = fields.findIndex((field) => field.prop === 'productionStatus')
+
+  if (productionStatusIndex === -1 || fields.some((field) => field.prop === 'malfunction')) {
+    return fields
+  }
+
+  fields.splice(productionStatusIndex + 1, 0, {
+    prop: 'malfunction',
+    label: '故障情况',
+    type: 'textarea',
+    span: 2,
+    editableInEdit: true
+  })
+
+  return fields
+})
+
 function isNumberField(value: unknown) {
   return value === null || value === undefined || typeof value === 'number'
 }
@@ -93,7 +112,7 @@ function getFieldClass(field: ConstructionDailyReportField) {
     </div>
     <div class="grid gap-4" :class="getGridColumnsClass()">
       <el-form-item
-        v-for="field in props.section.fields"
+        v-for="field in displayFields"
         :key="`${props.section.title}-${String(field.prop)}-${field.label}`"
         :label="field.label"
         :prop="field.prop"

+ 2 - 0
src/views/pms/constructionDailyReport/components/report-config.ts

@@ -38,6 +38,7 @@ export interface ConstructionDailyReportRow {
   nptReason?: string
   singleWellWorkload?: number | string | null
   productionStatus?: string
+  malfunction?: string
   planWorkingLayers?: number | null
   weather?: string
   temperature?: string
@@ -342,6 +343,7 @@ export function createEmptyConstructionDailyReport(): ConstructionDailyReportRow
     otherNptTime: null,
     otherNptReason: '',
     singleWellWorkload: null,
+    malfunction: '',
     planWorkingLayers: null
   }
 }