Selaa lähdekoodia

完善检验录入保存功能

yangguanjin 1 viikko sitten
vanhempi
commit
b44cfa39b9

+ 38 - 4
src/components/SpreadDesigner/spreadDesigner.vue

@@ -559,6 +559,7 @@ function getDefaultSchema(designerInstance) {
 }
 
 let dataCount = 0
+let prefixFields = new Set()
 function setDataSource(designerInstance, schemaData, dataSourceValues) {
   dataSourceValues =
     !is(dataSourceValues, 'Object') && is(dataSourceValues, 'String')
@@ -571,13 +572,18 @@ function setDataSource(designerInstance, schemaData, dataSourceValues) {
 
   const formatterSource = generateDefaultData(schemaData)
   const resultDataSource = deepMergeSchemaValue(formatterSource, dataSourceValues)
+  console.log("@@@resultDataSource......", resultDataSource)
 
   const spreadInstance = designerInstance.getWorkbook()
   const {
     dataSource: continuePageProceedDataSource,
     sheetToRecordRowCount,
+    prefixFieldSet,
     totalDataCount,
   } = processContinueDataSource(spreadInstance, resultDataSource)
+
+  console.log("@@@@xxxxxxxxx111111....", continuePageProceedDataSource)
+  prefixFields = prefixFieldSet
   dataCount = totalDataCount
   processContinuePage(
     spreadInstance,
@@ -585,6 +591,7 @@ function setDataSource(designerInstance, schemaData, dataSourceValues) {
     sheetToRecordRowCount,
     totalDataCount,
   )
+  console.log("@@@@@xxxxxxxx2222222....", continuePageProceedDataSource)
   registerCellValuesChangeEventHandlerForEverySheet(spreadInstance.sheets)
   for (const sheet of spreadInstance.sheets) {
     const tables = sheet.tables?.all() || []
@@ -623,7 +630,7 @@ function getDataSource(designerInstance) {
 
 function processContinueDataSource(spreadInstance, dataSource) {
   if (!props.copyConfig?.isContinuePage) {
-    return dataSource
+    return {dataSource}
   }
   console.log('@@@@@datasource', dataSource)
   dataSource = { ...dataSource }
@@ -716,7 +723,7 @@ function processContinueDataSource(spreadInstance, dataSource) {
   }
   console.log('@@@flatDataSource.....', dataSource)
 
-  return { dataSource, sheetToRecordRowCount, totalDataCount }
+  return { dataSource, prefixFieldSet, sheetToRecordRowCount, totalDataCount }
 }
 
 // 续页生成,超出一览表(第一页),把续页(第二页)从隐藏改成显示,超出续页(第二页),拷贝续页,copyRange范围内的bindingPath做递增修改
@@ -1330,7 +1337,34 @@ function handleDataJson(dataJson) {
   if (!props.copyConfig?.isContinuePage) {
     return dataJson
   }
-  
+
+  const prefixFieldData = {}
+  for (const prefixField of prefixFields) {
+    if(prefixField.startsWith('yearInspectionConclusion')) {
+      continue
+    }
+    const cellDataList = []
+    for (let i = 0; i < dataCount; i++) {
+      const cellData = dataJson[`${prefixField}_${i+1}`]
+      cellDataList.push(cellData)
+    }
+    prefixFieldData[`${prefixField}_1`] = JSON.stringify(cellDataList)
+    
+
+    for (const key in dataJson) {
+      if(key.startsWith(prefixField)) {
+        delete dataJson[key]
+      }
+      if(key.startsWith("yearInspectionConclusion")) {
+        const yc = dataJson[key]
+        if(yc == null || yc == "") {
+          delete dataJson[key]
+        }
+      }
+    }
+  }
+
+  return Object.assign(dataJson, prefixFieldData)
 }
 
 function saveRecord() {
@@ -1352,7 +1386,7 @@ function saveRecord() {
       instId: props.checkItemData.instId,
       reportUrl: props.checkItemData.reportUrl || '',
       bindingPathSchema: schemaJSON,
-      prepareJson: dataJSON,
+      prepareJson: handleDataJson(dataJSON),
       reportName: props.checkItemData.reportName,
       checkItemId: props.checkItemData.checkItemId,
       images,

+ 4 - 4
src/pages/editor/equipCheckRecordEditor.vue

@@ -73,11 +73,11 @@ const init = async () => {
 const fetchCopyConfig = async () => {
   // TODO: 调用后端接口获取续页配置
   const resp = await getDynamicTb({id: templateId})
-  if (resp.data?.copyConfig) {
-    copyConfig.value = resp.data.copyConfig
+  const cc = resp.data?.copyConfig
+  if (cc && Object.keys(cc).length != 0) {
+    copyConfig.value = cc
   }
   console.log("copyConfig.....", copyConfig.value)
-  // copyConfig.value = null
 }
 
 const handleGetCheckItemDetail = async (
@@ -312,7 +312,7 @@ const handleSave = async (data: any) => {
         reqData['Illustration'] = JSON.stringify(illustractionList)
       }
 
-      // console.log("reqD....", reqData)
+      console.log("reqD....", reqData)
       const result = await saveDynamicTbVal({ params: reqData, instId })
       if (result?.code === 0 && result?.data) {
         uni.showToast({ title: '保存成功', icon: 'success' })