Эх сурвалжийг харах

🦄 refactor(瑞都日报非生产时间): 根据平台井逻辑调整,填报添加时效按钮

Zimo 3 өдөр өмнө
parent
commit
90acc64350

+ 177 - 19
src/views/pms/iotrddailyreport/FillDailyReportForm.vue

@@ -197,7 +197,7 @@
                 v-model="formData.platformId"
                 placeholder="请选择平台井"
                 style="width: 100%"
-                :disabled="isReadonlyMode"
+                :disabled="isReadonlyMode && formData.auditStatus !== 20"
               >
                 <el-option
                   v-for="platform in platformOptions"
@@ -220,7 +220,7 @@
                   @click="openDeviceDialog"
                   type="primary"
                   size="small"
-                  :disabled="formLoading"
+                  :disabled="formLoading || isReadonlyMode"
                 >
                   选择设备
                 </el-button>
@@ -458,6 +458,7 @@
               v-model="formData[field.key]"
               :controls="false"
               align="left"
+              :disabled="isReadonlyMode && formData.auditStatus !== 20"
             />
           </el-form-item>
         </div>
@@ -465,7 +466,11 @@
         <el-row>
           <el-col :span="24">
             <el-form-item label="其他非生产原因" prop="otherNptReason">
-              <el-input v-model="formData.otherNptReason" placeholder="请输入其他非生产原因" />
+              <el-input
+                v-model="formData.otherNptReason"
+                placeholder="请输入其他非生产原因"
+                :disabled="isReadonlyMode && formData.auditStatus !== 20"
+              />
             </el-form-item>
           </el-col>
         </el-row>
@@ -819,7 +824,9 @@ const isDetailMode = computed(() => params.mode === 'detail')
 const isEditMode = computed(() => params.mode === 'fill' || !params.mode) // 默认为编辑模式
 
 // 只读模式判断:审批模式或详情模式都为只读
-const isReadonlyMode = computed(() => isApprovalMode.value || isDetailMode.value)
+const isReadonlyMode = computed(
+  () => isApprovalMode.value || isDetailMode.value || formData.value.auditStatus === 20
+)
 
 // 在表单数据定义附近添加
 const platformWellPairs = ref<any[]>([]) // 存储各平台井的工作量数据
@@ -955,7 +962,20 @@ const initPlatformData = (reportData: any) => {
             wellName: platform.wellName,
             rdStatus: platform.rdStatus || '', // 初始为空
             techniqueIds: techniqueIds, // 初始为空数组
-            extProperty: platform.extProperty || [] // 初始为空数组
+            extProperty: platform.extProperty || [], // 初始为空数组
+            repairTime: reportData.repairTime ?? 0,
+            selfStopTime: reportData.selfStopTime ?? 0,
+            accidentTime: reportData.accidentTime ?? 0,
+            complexityTime: reportData.complexityTime ?? 0,
+            rectificationTime: reportData.rectificationTime ?? 0,
+            waitingStopTime: reportData.waitingStopTime ?? 0,
+            partyaDesign: reportData.partyaDesign ?? 0,
+            partyaPrepare: reportData.partyaPrepare ?? 0,
+            partyaResource: reportData.partyaResource ?? 0,
+            relocationTime: reportData.relocationTime ?? 0,
+            winterBreakTime: reportData.winterBreakTime ?? 0,
+            otherNptTime: reportData.otherNptTime ?? 0,
+            otherNptReason: reportData.otherNptReason || ''
           }
         )
       })
@@ -1026,7 +1046,7 @@ const parseTimeArrayToDate = (timeArray: number[], baseDate: number) => {
 const fileUploadRef = ref()
 
 // 表单数据
-const formData = ref({
+const formData = ref<any>({
   id: undefined,
   deptId: undefined,
   taskId: undefined,
@@ -1351,14 +1371,14 @@ const initDeviceData = (reportData: any) => {
   }
 }
 
-const validateOtherReason = (_rule: any, value: any, callback: any) => {
-  const time = formData.value.otherNptTime || 0
-  if (time > 0 && !value) {
-    callback(new Error('填写了其他时间,必须说明原因'))
-  } else {
-    callback()
-  }
-}
+// const validateOtherReason = (_rule: any, value: any, callback: any) => {
+//   const time = formData.value.otherNptTime || 0
+//   if (time > 0 && !value) {
+//     callback(new Error('填写了其他时间,必须说明原因'))
+//   } else {
+//     callback()
+//   }
+// }
 
 const formRules = computed(() => {
   // 判断是否为虚拟项目
@@ -1369,7 +1389,7 @@ const formRules = computed(() => {
     timeRange: [{ required: true, message: '时间节点不能为空', trigger: 'change' }],
     productionStatus: [{ required: true, message: '当日生产动态不能为空', trigger: 'blur' }],
     nextPlan: [{ required: true, message: '下步工作计划不能为空', trigger: 'blur' }],
-    otherNptReason: [{ validator: validateOtherReason, trigger: ['blur', 'change'] }],
+    // otherNptReason: [{ validator: validateOtherReason, trigger: ['blur', 'change'] }],
     dailyFuel: [
       {
         required: true,
@@ -1470,6 +1490,71 @@ const submitForm = async () => {
     saveCurrentPlatformData(currentPlatformId.value)
   }
 
+  let validationPassed = true
+  const validationErrors: string[] = []
+
+  // 检查所有平台井数据
+  for (const pair of platformWellPairs.value) {
+    // 计算所有时间字段的总和
+    const totalTime =
+      (pair.repairTime || 0) +
+      (pair.selfStopTime || 0) +
+      (pair.accidentTime || 0) +
+      (pair.complexityTime || 0) +
+      (pair.rectificationTime || 0) +
+      (pair.waitingStopTime || 0) +
+      (pair.partyaDesign || 0) +
+      (pair.partyaPrepare || 0) +
+      (pair.partyaResource || 0) +
+      (pair.relocationTime || 0) +
+      (pair.winterBreakTime || 0) +
+      (pair.otherNptTime || 0)
+
+    // 检查总和是否超过24小时
+    if (totalTime > 24) {
+      validationPassed = false
+      validationErrors.push(`${pair.wellName || '平台井'}的时间总和不能超过24小时`)
+    }
+
+    // 检查otherNptTime>0时是否填写了otherNptReason
+    if ((pair.otherNptTime || 0) > 0 && !pair.otherNptReason) {
+      validationPassed = false
+      validationErrors.push(`${pair.wellName || '平台井'}的其他时间大于0时必须填写原因`)
+    }
+  }
+
+  // 检查非平台井模式
+  if (dailyReportData.value.platformWell !== 1) {
+    // 计算所有时间字段的总和
+    const totalTime =
+      (formData.value.repairTime || 0) +
+      (formData.value.selfStopTime || 0) +
+      (formData.value.accidentTime || 0) +
+      (formData.value.complexityTime || 0) +
+      (formData.value.rectificationTime || 0) +
+      (formData.value.waitingStopTime || 0) +
+      (formData.value.partyaDesign || 0) +
+      (formData.value.partyaPrepare || 0) +
+      (formData.value.partyaResource || 0) +
+      (formData.value.relocationTime || 0) +
+      (formData.value.winterBreakTime || 0) +
+      (formData.value.otherNptTime || 0)
+
+    // 检查总和是否超过24小时
+    if (totalTime > 24) {
+      validationPassed = false
+      validationErrors.push('时间总和不能超过24小时')
+    }
+  }
+
+  // 如果验证失败,显示错误信息
+  if (!validationPassed) {
+    validationErrors.forEach((error) => {
+      message.error(error)
+    })
+    return
+  }
+
   // 打印 platformWellPairs
   console.log('platformWellPairs:', JSON.stringify(platformWellPairs.value, null, 2))
 
@@ -1519,6 +1604,8 @@ const submitForm = async () => {
     dailyFuel: formData.value.dailyFuel ? parseFloat(formData.value.dailyFuel) : 0
   }
 
+  console.log('baseSubmitData:', baseSubmitData)
+
   // 删除不需要复制的字段
   const {
     id: currentId,
@@ -1531,13 +1618,14 @@ const submitForm = async () => {
     ...baseData
   } = baseSubmitData
 
-  const submitDatas = []
+  const submitDatas: any[] = []
 
   if (dailyReportData.value.platformWell === 1 && platformWellPairs.value.length > 0) {
     // 平台井模式:处理所有平台井数据
     platformWellPairs.value.forEach((pair) => {
+      console.log('pair:', pair)
       // 复制基础数据
-      const platformData = { ...baseData }
+      const platformData: any = { ...baseData }
 
       // 设置平台井特定字段
       platformData.id = pair.reportId // 使用 platformWellPairs 中的 reportId
@@ -1546,6 +1634,20 @@ const submitForm = async () => {
       platformData.techniqueIds = pair.techniqueIds || []
       platformData.extProperty = pair.extProperty || []
 
+      platformData.repairTime = pair.repairTime || 0
+      platformData.selfStopTime = pair.selfStopTime || 0
+      platformData.accidentTime = pair.accidentTime || 0
+      platformData.complexityTime = pair.complexityTime || 0
+      platformData.rectificationTime = pair.rectificationTime || 0
+      platformData.waitingStopTime = pair.waitingStopTime || 0
+      platformData.partyaDesign = pair.partyaDesign || 0
+      platformData.partyaPrepare = pair.partyaPrepare || 0
+      platformData.partyaResource = pair.partyaResource || 0
+      platformData.relocationTime = pair.relocationTime || 0
+      platformData.winterBreakTime = pair.winterBreakTime || 0
+      platformData.otherNptTime = pair.otherNptTime || 0
+      platformData.otherNptReason = pair.otherNptReason || ''
+
       // 处理附件:复制并修改 bizId 为当前 pair 的 reportId
       platformData.attachments = (baseData.attachments || []).map((attachment) => ({
         ...attachment, // 深拷贝单个附件
@@ -1883,7 +1985,20 @@ const saveCurrentPlatformData = (platformId: number) => {
       ...platformWellPairs.value[index],
       rdStatus: formData.value.rdStatus,
       techniqueIds: [...formData.value.techniqueIds],
-      extProperty: getCurrentExtProperties()
+      extProperty: getCurrentExtProperties(),
+      repairTime: formData.value.repairTime ?? 0,
+      selfStopTime: formData.value.selfStopTime ?? 0,
+      accidentTime: formData.value.accidentTime ?? 0,
+      complexityTime: formData.value.complexityTime ?? 0,
+      rectificationTime: formData.value.rectificationTime ?? 0,
+      waitingStopTime: formData.value.waitingStopTime ?? 0,
+      partyaDesign: formData.value.partyaDesign ?? 0,
+      partyaPrepare: formData.value.partyaPrepare ?? 0,
+      partyaResource: formData.value.partyaResource ?? 0,
+      relocationTime: formData.value.relocationTime ?? 0,
+      winterBreakTime: formData.value.winterBreakTime ?? 0,
+      otherNptTime: formData.value.otherNptTime ?? 0,
+      otherNptReason: formData.value.otherNptReason || ''
     }
   } else {
     // 如果找不到对应的平台井,添加新的记录
@@ -1895,7 +2010,20 @@ const saveCurrentPlatformData = (platformId: number) => {
         wellName: platform.wellName,
         rdStatus: formData.value.rdStatus,
         techniqueIds: [...formData.value.techniqueIds],
-        extProperty: getCurrentExtProperties()
+        extProperty: getCurrentExtProperties(),
+        repairTime: formData.value.repairTime ?? 0,
+        selfStopTime: formData.value.selfStopTime ?? 0,
+        accidentTime: formData.value.accidentTime ?? 0,
+        complexityTime: formData.value.complexityTime ?? 0,
+        rectificationTime: formData.value.rectificationTime ?? 0,
+        waitingStopTime: formData.value.waitingStopTime ?? 0,
+        partyaDesign: formData.value.partyaDesign ?? 0,
+        partyaPrepare: formData.value.partyaPrepare ?? 0,
+        partyaResource: formData.value.partyaResource ?? 0,
+        relocationTime: formData.value.relocationTime ?? 0,
+        winterBreakTime: formData.value.winterBreakTime ?? 0,
+        otherNptTime: formData.value.otherNptTime ?? 0,
+        otherNptReason: formData.value.otherNptReason || ''
       })
     }
   }
@@ -1903,6 +2031,7 @@ const saveCurrentPlatformData = (platformId: number) => {
 
 // 从 platformWellPairs 加载平台井数据到表单
 const loadPlatformData = (platformId: number) => {
+  console.log('11 :>> ', 11)
   const platformData = platformWellPairs.value.find((item) => item.taskId === platformId)
   if (platformData) {
     // 更新表单字段
@@ -1937,11 +2066,39 @@ const loadPlatformData = (platformId: number) => {
     } else {
       formData.value.dynamicFields = {}
     }
+
+    formData.value.repairTime = platformData.repairTime ?? 0
+    formData.value.selfStopTime = platformData.selfStopTime ?? 0
+    formData.value.accidentTime = platformData.accidentTime ?? 0
+    formData.value.complexityTime = platformData.complexityTime ?? 0
+    formData.value.rectificationTime = platformData.rectificationTime ?? 0
+    formData.value.waitingStopTime = platformData.waitingStopTime ?? 0
+    formData.value.partyaDesign = platformData.partyaDesign ?? 0
+    formData.value.partyaPrepare = platformData.partyaPrepare ?? 0
+    formData.value.partyaResource = platformData.partyaResource ?? 0
+    formData.value.relocationTime = platformData.relocationTime ?? 0
+    formData.value.winterBreakTime = platformData.winterBreakTime ?? 0
+    formData.value.otherNptTime = platformData.otherNptTime ?? 0
+    formData.value.otherNptReason = platformData.otherNptReason || ''
   } else {
     // 如果没有找到数据,初始化默认值
     formData.value.rdStatus = ''
     formData.value.techniqueIds = []
     formData.value.dynamicFields = {}
+    // 初始化其他时间字段
+    formData.value.repairTime = 0
+    formData.value.selfStopTime = 0
+    formData.value.accidentTime = 0
+    formData.value.complexityTime = 0
+    formData.value.rectificationTime = 0
+    formData.value.waitingStopTime = 0
+    formData.value.partyaDesign = 0
+    formData.value.partyaPrepare = 0
+    formData.value.partyaResource = 0
+    formData.value.relocationTime = 0
+    formData.value.winterBreakTime = 0
+    formData.value.otherNptTime = 0
+    formData.value.otherNptReason = ''
 
     // 在详情或审批模式下,清空 dailyFuel
     if (isDetailMode.value || isApprovalMode.value) {
@@ -2055,6 +2212,7 @@ const initFormData = (reportData: any) => {
     endTime: reportData.endTime || undefined,
     companyId: reportData.companyId || '',
     dynamicFields: {}, // 确保有初始值
+    auditStatus: reportData.auditStatus,
     // 初始化附件数据
     attachments: formattedAttachments,
     repairTime: reportData.repairTime ?? 0,

+ 9 - 0
src/views/pms/iotrddailyreport/fillDailyReport.vue

@@ -103,6 +103,15 @@
               >
                 查看
               </el-button>
+              <el-button
+                link
+                type="warning"
+                @click="openForm('fill', scope.row.id)"
+                v-hasPermi="['pms:iot-rd-daily-report:non-productive']"
+                v-if="scope.row.auditStatus === 20"
+              >
+                时效
+              </el-button>
             </template>
           </el-table-column>
           <el-table-column