Przeglądaj źródła

fix: 成本审核财务表详情模版下载、单记录、固定表、动态表修改

shiyanyu 4 tygodni temu
rodzic
commit
2b9cfa4a9a

+ 8 - 1
src/components/task/cbjsInfo.vue

@@ -15,7 +15,14 @@
         @tab-click="handleTabClick"
       >
         <el-tab-pane label="报送资料" name="submitData">
-          <submit-data :id="id" ref="submitDataRef" :disabled="true" />
+          <submit-data
+            :id="id"
+            ref="submitDataRef"
+            :disabled="true"
+            :audited-unit-id="auditedUnitId"
+            :catalog-id="catalogId"
+            :task-id="taskId"
+          />
         </el-tab-pane>
         <el-tab-pane label="成本调查表" name="costSurvey">
           <cost-survey

+ 168 - 11
src/components/task/components/submitData.vue

@@ -147,51 +147,83 @@
 
     <survey-form-dialog
       :visible.sync="singleDialogVisible"
-      :survey-data="{}"
+      :survey-data="{ ...(currentTemplateRow || {}), ...surveyDetailData }"
       :is-view-mode="true"
+      :request-type="2"
       :audited-unit-id="
-        (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
+        auditedUnitId ||
+        (currentTemplateRow && currentTemplateRow.auditedUnitId) ||
+        ''
+      "
+      :upload-id="
+        (currentTemplateRow &&
+          (currentTemplateRow.uploadId || currentTemplateRow.id)) ||
+        ''
       "
-      :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
       :survey-template-id="
         (currentTemplateRow &&
           (currentTemplateRow.templateId ||
             currentTemplateRow.surveyTemplateId)) ||
         ''
       "
-      :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
+      :catalog-id="
+        catalogId || (currentTemplateRow && currentTemplateRow.catalogId) || ''
+      "
     />
 
     <fixed-table-dialog
       :visible.sync="fixedDialogVisible"
       :is-view-mode="true"
+      :request-type="2"
       :audited-unit-id="
-        (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
+        auditedUnitId ||
+        (currentTemplateRow && currentTemplateRow.auditedUnitId) ||
+        ''
+      "
+      :upload-id="
+        (currentTemplateRow &&
+          (currentTemplateRow.uploadId || currentTemplateRow.id)) ||
+        ''
       "
-      :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
       :survey-template-id="
         (currentTemplateRow &&
           (currentTemplateRow.templateId ||
             currentTemplateRow.surveyTemplateId)) ||
         ''
       "
-      :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
+      :catalog-id="
+        catalogId || (currentTemplateRow && currentTemplateRow.catalogId) || ''
+      "
+      :fixed-fields="fixedFields || ''"
+      :fixed-fieldids="fixedFieldids || ''"
+      :table-items="tableItems"
     />
 
     <dynamic-table-dialog
       :visible.sync="dynamicDialogVisible"
       :is-view-mode="true"
+      :request-type="2"
       :audited-unit-id="
-        (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
+        auditedUnitId ||
+        (currentTemplateRow && currentTemplateRow.auditedUnitId) ||
+        ''
+      "
+      :upload-id="
+        (currentTemplateRow &&
+          (currentTemplateRow.uploadId || currentTemplateRow.id)) ||
+        ''
       "
-      :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
       :survey-template-id="
         (currentTemplateRow &&
           (currentTemplateRow.templateId ||
             currentTemplateRow.surveyTemplateId)) ||
         ''
       "
-      :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
+      :catalog-id="
+        catalogId || (currentTemplateRow && currentTemplateRow.catalogId) || ''
+      "
+      :table-data="dynamicTableData"
+      :table-items="tableItems"
     />
   </div>
 </template>
@@ -208,6 +240,11 @@
   import SurveyFormDialog from '@/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue'
   import FixedTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/FixedTableDialog.vue'
   import DynamicTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/DynamicTableDialog.vue'
+  import {
+    getSingleRecordSurveyList,
+    getSurveyDetail,
+    getDynamicTableData,
+  } from '@/api/audit/survey'
 
   export default {
     name: 'AuditReview',
@@ -225,6 +262,18 @@
         type: String,
         default: '',
       },
+      auditedUnitId: {
+        type: [String, Number],
+        default: '',
+      },
+      catalogId: {
+        type: [String, Number],
+        default: '',
+      },
+      taskId: {
+        type: [String, Number],
+        default: '',
+      },
     },
     data() {
       return {
@@ -261,6 +310,11 @@
         singleDialogVisible: false,
         fixedDialogVisible: false,
         dynamicDialogVisible: false,
+        fixedFields: '',
+        fixedFieldids: '',
+        surveyDetailData: {},
+        dynamicTableData: [],
+        tableItems: [],
       }
     },
     watch: {
@@ -407,16 +461,50 @@
           //   this.$message.error('文件预览失败')
         }
       },
-      handleViewTemplate(row) {
+      async handleViewTemplate(row) {
         this.currentTemplateRow = row || null
         const t = String(
           (row && (row.templateType || row.templatetype)) || ''
         ).trim()
         if (t === '1') {
+          // 单记录:打开前回显数据(type=2)
+          try {
+            this.surveyDetailData = {}
+            const uploadId = (row && (row.uploadId || row.id)) || ''
+            if (uploadId) {
+              const params = {
+                uploadId,
+                auditedUnitId:
+                  this.auditedUnitId || (row && row.auditedUnitId) || '',
+                type: 2,
+              }
+              const res = await getSurveyDetail(params)
+              if (res && res.code === 200 && res.value) {
+                const detailData = {}
+                if (Array.isArray(res.value)) {
+                  res.value.forEach((item) => {
+                    if (item.rowid && item.rvalue !== undefined) {
+                      detailData[item.rowid] = item.rvalue
+                    }
+                  })
+                } else if (res.value && typeof res.value === 'object') {
+                  Object.assign(detailData, res.value)
+                }
+                this.surveyDetailData = detailData
+              }
+            }
+          } catch (e) {
+            console.error('获取单记录详情失败', e)
+          }
           this.singleDialogVisible = true
         } else if (t === '2') {
+          // 固定表:先加载固定表配置(表头),参考 CostSurveyTab
+          const surveyTemplateId =
+            (row && (row.surveyTemplateId || row.templateId)) || ''
+          await this.initFixedTableData(surveyTemplateId)
           this.fixedDialogVisible = true
         } else if (t === '3') {
+          await this.initDynamicTableData()
           this.dynamicDialogVisible = true
         } else {
           this.$message &&
@@ -424,6 +512,75 @@
             this.$message.warning('未知的模板类型,无法打开预置模板')
         }
       },
+      async initDynamicTableData() {
+        try {
+          const row = this.currentTemplateRow || {}
+          const uploadId = (row && (row.uploadId || row.id)) || ''
+          const auditedUnitId = this.auditedUnitId || row.auditedUnitId || ''
+          const catalogId = this.catalogId || row.catalogId || ''
+          const surveyTemplateId =
+            (row && (row.surveyTemplateId || row.templateId)) || ''
+          const params = {
+            uploadId,
+            auditedUnitId,
+            catalogId,
+            surveyTemplateId,
+            type: 2,
+          }
+          const res = await getDynamicTableData(params)
+          if (res && res.code === 200) {
+            const records = res.value?.records || res.value || []
+            this.dynamicTableData = Array.isArray(records) ? records : []
+          } else {
+            this.dynamicTableData = []
+          }
+          // 若当前行自带列配置则透传,否则传空数组
+          this.tableItems = (row && row.tableItems) || []
+        } catch (e) {
+          console.error('获取动态表数据失败:', e)
+          this.dynamicTableData = []
+          this.tableItems = []
+        }
+      },
+      async initFixedTableData(surveyTemplateId) {
+        try {
+          this.fixedFields = ''
+          this.fixedFieldids = ''
+          this.tableItems = []
+          if (!surveyTemplateId) return
+          const params = { surveyTemplateId, type: 2 }
+          const res = await getSingleRecordSurveyList(params)
+          if (res && res.code === 200 && res.value) {
+            this.fixedFields = res.value.fixedFields || ''
+            this.fixedFieldids = res.value.fixedFieldids || ''
+            const { itemlist } = res.value || {}
+            if (Array.isArray(itemlist) && itemlist.length > 0) {
+              this.tableItems = itemlist.map((item) => ({
+                id: item.id || item.itemId || '',
+                rowid: item.rowid || item.id || item.itemId || '',
+                seq: item.序号,
+                itemName: item.项目 || item.itemName || '',
+                unit: item.unit || '',
+                isCategory: item.isCategory || false,
+                categorySeq: item.categorySeq || '',
+                categoryId: item.categoryId || '',
+                parentid:
+                  item.parentid !== undefined
+                    ? item.parentid
+                    : item.parentId !== undefined
+                    ? item.parentId
+                    : '-1',
+                validateRules: item.validateRules || {},
+                linkageRules: item.linkageRules || {},
+                children: item.children || [],
+                ...item,
+              }))
+            }
+          }
+        } catch (e) {
+          console.error('加载固定表配置失败:', e)
+        }
+      },
       // 查看报表
       handleViewReport(row) {
         this.$message.info(`查看报表:${row.name}`)

+ 67 - 1
src/components/task/taskInfo.vue

@@ -591,7 +591,7 @@
                         "
                         type="text"
                         size="small"
-                        @click="$emit('handleTemplateDownload', scope.row)"
+                        @click="handleTemplateDownload(scope.row)"
                       >
                         模版下载
                       </el-button>
@@ -1015,6 +1015,7 @@
     getSingleRecordSurveyList,
     getSurveyDetail,
     getDynamicTableData,
+    downloadTemplate,
   } from '@/api/audit/survey'
   import { getListBySurveyFdTemplateIdAndVersion } from '@/api/costSurveyTemplateHeaders'
   export default {
@@ -1293,6 +1294,71 @@
         }
         this.downloadByFetch(row.fileUrl, row.informationName || '下载文件')
       },
+      // 模版下载(对齐 CostSurveyTab,兼容两种上下文)
+      async handleTemplateDownload(row) {
+        try {
+          const loading = this.$loading({
+            lock: true,
+            text: '模板下载中...',
+            spinner: 'el-icon-loading',
+            background: 'rgba(0, 0, 0, 0.7)',
+          })
+          const surveyTemplateId = this.getSurveyTemplateId(row)
+          const versionId =
+            (row && (row.versionId || row.version || row.templateVersionId)) ||
+            ''
+          const params = {
+            type: this.viewContext === 'costSurvey' ? 1 : 2,
+          }
+          if (surveyTemplateId) params.surveyTemplateId = surveyTemplateId
+          if (versionId) params.versionId = versionId
+          const taskId = (row && (row.taskId || row.taskID)) || this.taskId
+          if (taskId) params.taskId = taskId
+          const res = await downloadTemplate(params)
+          loading.close()
+          const headers = (res && res.headers) || {}
+          const contentDisposition =
+            headers['content-disposition'] || headers['Content-Disposition']
+          let fileName =
+            this.extractFileNameFromHeader(contentDisposition) ||
+            `${row.informationName || row.name || '模板文件'}.xlsx`
+          if (!/\.[a-zA-Z0-9]+$/.test(fileName)) fileName += '.xlsx'
+          const blobData = (res && res.data) || res
+          const blob =
+            blobData instanceof Blob ? blobData : new Blob([blobData])
+          const url = window.URL.createObjectURL(blob)
+          const link = document.createElement('a')
+          link.style.display = 'none'
+          link.href = url
+          link.download = fileName
+          document.body.appendChild(link)
+          link.click()
+          document.body.removeChild(link)
+          window.URL.revokeObjectURL(url)
+          this.$message &&
+            this.$message.success &&
+            this.$message.success('开始下载文件')
+        } catch (error) {
+          console.error('模板下载失败:', error)
+          this.$message &&
+            this.$message.error &&
+            this.$message.error(error.message || '模板下载失败,请稍后重试')
+        }
+      },
+      extractFileNameFromHeader(contentDisposition) {
+        if (!contentDisposition) return ''
+        const match = /filename[^;=\n]*=((['"])?.*?\2|[^;\n]*)/i.exec(
+          contentDisposition
+        )
+        if (match && match[1]) {
+          try {
+            return decodeURIComponent(match[1].replace(/['"]/g, ''))
+          } catch (e) {
+            return match[1].replace(/['"]/g, '')
+          }
+        }
+        return ''
+      },
       async downloadByFetch(rawUrl, fallbackName) {
         const url = this.normalizeUrl(rawUrl)
         let loading