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

pms 瑞都 日报 填报 保存平台井关联的任务井

zhangcl 4 өдөр өмнө
parent
commit
2691d549da

+ 5 - 0
src/api/pms/iotrddailyreport/index.ts

@@ -70,6 +70,11 @@ export const IotRdDailyReportApi = {
     return await request.put({ url: `/pms/iot-rd-daily-report/update`, data })
   },
 
+  // 批量更新瑞都日报 平台井
+  saveBatch: async (data: any) => {
+    return await request.post({ url: `/pms/iot-rd-daily-report/saveBatch`, data })
+  },
+
   // 审批瑞都日报
   approveRdDailyReport: async (data: IotRdDailyReportVO) => {
     return await request.put({ url: `/pms/iot-rd-daily-report/approval`, data })

+ 205 - 2
src/views/pms/iotrddailyreport/FillDailyReportForm.vue

@@ -589,6 +589,10 @@ const isEditMode = computed(() => params.mode === 'fill' || !params.mode) // 默
 // 只读模式判断:审批模式或详情模式都为只读
 const isReadonlyMode = computed(() => isApprovalMode.value || isDetailMode.value)
 
+// 在表单数据定义附近添加
+const platformWellPairs = ref<any[]>([]) // 存储各平台井的工作量数据
+const currentPlatformId = ref<number>() // 当前选中的平台井ID
+
 // 页面标题计算
 const pageTitle = computed(() => {
   if (isApprovalMode.value) {
@@ -642,8 +646,27 @@ const initPlatformData = (reportData: any) => {
   // 设置平台井下拉选项
   if (reportData.platforms && Array.isArray(reportData.platforms)) {
     platformOptions.value = reportData.platforms
+
+    // 初始化 platformWellPairs,确保包含所有平台井的完整数据
+    if (reportData.platformWell === 1) {
+      // 初始化 platformWellPairs,包含所有平台井的完整数据
+      platformWellPairs.value = reportData.platforms.map((platform: any) => {
+        // 查找是否已有该平台井的数据
+        const existingData = reportData.platformWellPairs?.find((p: any) => p.taskId === platform.id)
+
+        return existingData || {
+          taskId: platform.id,
+          reportId: platform.reportId, // 使用接口返回的 reportId
+          wellName: platform.wellName,
+          rdStatus: '', // 初始为空
+          techniqueIds: [], // 初始为空数组
+          extProperty: [] // 初始为空数组
+        }
+      })
+    }
   } else {
     platformOptions.value = []
+    platformWellPairs.value = []
   }
 
   // 设置默认选中的平台井
@@ -654,6 +677,10 @@ const initPlatformData = (reportData: any) => {
     )
     if (defaultPlatform) {
       formData.value.platformId = defaultPlatform.id
+      currentPlatformId.value = defaultPlatform.id
+
+      // 加载默认平台井的数据到表单
+      loadPlatformData(defaultPlatform.id)
     }
   }
 }
@@ -1023,6 +1050,14 @@ const submitForm = async () => {
     return
   }
 
+  // 保存当前平台井的数据
+  if (currentPlatformId.value) {
+    saveCurrentPlatformData(currentPlatformId.value)
+  }
+
+  // 打印 platformWellPairs
+  console.log('platformWellPairs:', JSON.stringify(platformWellPairs.value, null, 2))
+
   // 处理时间范围数据
   if (formData.value.timeRange && formData.value.timeRange.length === 2) {
     // 将时间范围转换为 LocalTime 格式的字符串
@@ -1052,18 +1087,56 @@ const submitForm = async () => {
   })
 
   // 准备提交数据,包含动态字段
-  const submitData = {
+  const baseSubmitData = {
     ...formData.value,
     // 将动态字段组装成 extProperty 数组
     extProperty: extProperties,
     deviceIds: formData.value.deviceIds, // 设备ID集合
   }
 
+  // 删除不需要复制的字段
+  const { id: currentId, platformId, rdStatus, techniqueIds, extProperty, ...baseData } = baseSubmitData
+
+  const submitDatas = []
+
+  if (dailyReportData.value.platformWell === 1 && platformWellPairs.value.length > 0) {
+    // 平台井模式:处理所有平台井数据
+    platformWellPairs.value.forEach(pair => {
+      // 复制基础数据
+      const platformData = { ...baseData }
+
+      // 设置平台井特定字段
+      platformData.id = pair.reportId // 使用 platformWellPairs 中的 reportId
+      platformData.platformId = pair.taskId // 使用 platformWellPairs 中的 taskId
+      platformData.rdStatus = pair.rdStatus || ''
+      platformData.techniqueIds = pair.techniqueIds || []
+      platformData.extProperty = pair.extProperty || []
+
+      // 重新构建 dynamicFields(如果需要)
+      const dynamicFields = {}
+      if (platformData.extProperty && platformData.extProperty.length > 0) {
+        platformData.extProperty.forEach(prop => {
+          if (prop.identifier) {
+            dynamicFields[prop.identifier] = prop.actualValue || ''
+          }
+        })
+      }
+      platformData.dynamicFields = dynamicFields
+
+      submitDatas.push(platformData)
+    })
+
+    console.log('平台井模式提交数据:', JSON.stringify(submitDatas, null, 2))
+  } else {
+    // 非平台井模式:只提交当前数据
+    submitDatas = [baseSubmitData]
+  }
+
   // 提交请求
   formLoading.value = true
   try {
     // 调用更新接口
-    await IotRdDailyReportApi.updateIotRdDailyReport(submitData)
+    await IotRdDailyReportApi.saveBatch(submitDatas)
     message.success(t('common.updateSuccess'))
     close()
     // 发送操作成功的事件
@@ -1223,12 +1296,136 @@ const loadDynamicAttrs = async (newTechniqueIds: string[], oldTechniqueIds?: str
 watch(() => formData.value.techniqueIds, async (newTechniqueIds, oldTechniqueIds) => {
   if (newTechniqueIds && newTechniqueIds.length > 0) {
     await loadDynamicAttrs(newTechniqueIds, oldTechniqueIds)
+
+    // 动态属性加载完成后,更新当前平台井的 extProperty
+    if (currentPlatformId.value) {
+      updateCurrentPlatformExtProperty()
+    }
   } else {
     dynamicAttrs.value = []
     formData.value.dynamicFields = {}
+
+    // 清空当前平台井的 extProperty
+    if (currentPlatformId.value) {
+      updateCurrentPlatformExtProperty()
+    }
   }
 }, { deep: true })
 
+// 更新当前平台井的 extProperty
+const updateCurrentPlatformExtProperty = () => {
+  if (!currentPlatformId.value) return
+
+  const index = platformWellPairs.value.findIndex(item => item.taskId === currentPlatformId.value)
+  if (index !== -1) {
+    platformWellPairs.value[index].extProperty = getCurrentExtProperties()
+  }
+}
+
+// 监听平台井选择变化
+watch(() => formData.value.platformId, (newPlatformId, oldPlatformId) => {
+  if (newPlatformId && newPlatformId !== oldPlatformId) {
+    // 保存当前平台井的数据到 platformWellPairs
+    if (oldPlatformId) {
+      saveCurrentPlatformData(oldPlatformId)
+    }
+
+    // 加载新平台井的数据到表单
+    loadPlatformData(newPlatformId)
+    currentPlatformId.value = newPlatformId
+  }
+})
+
+// 监听动态字段变化,实时更新到 platformWellPairs
+watch(() => formData.value.dynamicFields, (newFields) => {
+  if (currentPlatformId.value) {
+    updateCurrentPlatformExtProperty()
+  }
+}, { deep: true })
+
+// 监听施工状态变化
+watch(() => formData.value.rdStatus, (newStatus) => {
+  if (currentPlatformId.value) {
+    const index = platformWellPairs.value.findIndex(item => item.taskId === currentPlatformId.value)
+    if (index !== -1) {
+      platformWellPairs.value[index].rdStatus = newStatus
+    }
+  }
+})
+
+// 保存当前平台井数据到 platformWellPairs
+const saveCurrentPlatformData = (platformId: number) => {
+  const index = platformWellPairs.value.findIndex(item => item.taskId === platformId)
+  if (index !== -1) {
+    platformWellPairs.value[index] = {
+      ...platformWellPairs.value[index],
+      rdStatus: formData.value.rdStatus,
+      techniqueIds: [...formData.value.techniqueIds],
+      extProperty: getCurrentExtProperties()
+    }
+  } else {
+    // 如果找不到对应的平台井,添加新的记录
+    const platform = platformOptions.value.find(p => p.id === platformId)
+    if (platform) {
+      platformWellPairs.value.push({
+        taskId: platformId,
+        reportId: undefined, // 新记录没有 reportId
+        wellName: platform.wellName,
+        rdStatus: formData.value.rdStatus,
+        techniqueIds: [...formData.value.techniqueIds],
+        extProperty: getCurrentExtProperties()
+      })
+    }
+  }
+}
+
+// 从 platformWellPairs 加载平台井数据到表单
+const loadPlatformData = (platformId: number) => {
+  const platformData = platformWellPairs.value.find(item => item.taskId === platformId)
+  if (platformData) {
+    // 更新表单字段
+    formData.value.rdStatus = platformData.rdStatus || ''
+    formData.value.techniqueIds = platformData.techniqueIds ? [...platformData.techniqueIds] : []
+
+    // 更新动态属性
+    if (platformData.extProperty && platformData.extProperty.length > 0) {
+      const dynamicFields: Record<string, any> = {}
+      platformData.extProperty.forEach((prop: any) => {
+        if (prop.identifier) {
+          dynamicFields[prop.identifier] = prop.actualValue || ''
+        }
+      })
+      formData.value.dynamicFields = dynamicFields
+    } else {
+      formData.value.dynamicFields = {}
+    }
+  } else {
+    // 如果没有找到数据,初始化默认值
+    formData.value.rdStatus = ''
+    formData.value.techniqueIds = []
+    formData.value.dynamicFields = {}
+  }
+}
+
+// 获取当前动态属性数据
+const getCurrentExtProperties = () => {
+  return dynamicAttrs.value.map(attr => {
+    return {
+      name: attr.name,
+      sort: attr.sort,
+      unit: attr.unit,
+      actualValue: formData.value.dynamicFields[attr.identifier] || '',
+      dataType: attr.dataType,
+      maxValue: attr.maxValue,
+      minValue: attr.minValue,
+      required: attr.required,
+      accessMode: attr.accessMode,
+      identifier: attr.identifier,
+      defaultValue: attr.defaultValue
+    }
+  })
+}
+
 // 初始化表单数据
 const initFormData = (reportData: any) => {
   // 处理附件数据格式转换
@@ -1278,6 +1475,12 @@ const initFormData = (reportData: any) => {
 
   // 初始化平台井数据
   initPlatformData(reportData)
+
+  // 如果是平台井模式且有数据,初始化 platformWellPairs 中的第一个平台井数据
+  if (reportData.platformWell === 1 && formData.value.platformId) {
+    loadPlatformData(formData.value.platformId)
+  }
+
 }
 
 onMounted(async () => {