Ver código fonte

feat: 成本调查表列表对接,单记录在线填报功能完成

shiyanyu 1 mês atrás
pai
commit
5b2e96226c

+ 39 - 0
src/api/audit/survey.js

@@ -0,0 +1,39 @@
+import request from '@/utils/request'
+
+const url = window.context.form
+
+// 成本调查列表
+export function getSurveyList(data) {
+  return request({
+    url: url + '/api/enterprise/castTaskInfo/listUploadByCatalogId',
+    method: 'get',
+    params: data,
+  })
+}
+
+// 单记录成本调查表
+export function getSingleRecordSurveyList(data) {
+  return request({
+    url: url + '/api/enterprise/castTaskInfo/listItemsByCurrentTemplateId',
+    method: 'get',
+    params: data,
+  })
+}
+
+// 单记录保存
+export function saveSingleRecordSurvey(data) {
+  return request({
+    url: url + '/api/enterprise/castTaskInfo/saveUploadData',
+    method: 'post',
+    data: data,
+  })
+}
+
+// 获取详情
+export function getSurveyDetail(data) {
+  return request({
+    url: url + '/api/enterprise/castTaskInfo/getUploadData',
+    method: 'post',
+    data: data,
+  })
+}

+ 149 - 14
src/views/EntDeclaration/auditTaskManagement/components/CostSurveyTab.vue

@@ -3,10 +3,21 @@
     <!-- 调查表填报弹窗(单记录类型) -->
     <survey-form-dialog
       :visible.sync="surveyFormDialogVisible"
-      :survey-data="currentSurveyRow"
+      :survey-data="{ ...currentSurveyRow, ...surveyDetailData }"
       :form-fields="formFields"
       :is-view-mode="isViewMode"
+      :audited-unit-id="auditedUnitId"
+      :upload-id="
+        currentSurveyRow && currentSurveyRow.id ? currentSurveyRow.id : uploadId
+      "
+      :survey-template-id="
+        currentSurveyRow && currentSurveyRow.surveyTemplateId
+          ? currentSurveyRow.surveyTemplateId
+          : surveyTemplateId
+      "
+      :catalog-id="catalogId"
       @save="handleSurveyFormSave"
+      @refresh="handleRefresh"
     />
 
     <!-- 固定表填报弹窗 -->
@@ -82,7 +93,13 @@
       >
         <template slot-scope="scope">
           <span>
-            {{ scope.row.isRequired === '1' ? '是' : '否' }}
+            {{
+              scope.row.isRequired === '是' ||
+              scope.row.isRequired === '1' ||
+              scope.row.isRequired === 1
+                ? '是'
+                : '否'
+            }}
           </span>
         </template>
       </el-table-column>
@@ -185,6 +202,10 @@
   import SurveyFormDialog from './SurveyFormDialog.vue'
   import FixedTableDialog from './FixedTableDialog.vue'
   import DynamicTableDialog from './DynamicTableDialog.vue'
+  import {
+    getSingleRecordSurveyList,
+    getSurveyDetail,
+  } from '@/api/audit/survey'
 
   export default {
     name: 'CostSurveyTab',
@@ -206,6 +227,26 @@
         type: Boolean,
         default: false,
       },
+      // 被监审单位ID
+      auditedUnitId: {
+        type: String,
+        default: '',
+      },
+      // 上传记录ID
+      uploadId: {
+        type: String,
+        default: '',
+      },
+      // 成本调查表模板ID
+      surveyTemplateId: {
+        type: String,
+        default: '',
+      },
+      // 目录ID
+      catalogId: {
+        type: String,
+        default: '',
+      },
     },
     data() {
       return {
@@ -215,6 +256,8 @@
         currentSurveyRow: null,
         // 表单字段配置(可以从后台获取,或通过 props 传入)
         formFields: [],
+        // 表单详情数据(用于回显)
+        surveyDetailData: {},
         // 固定表数据配置
         tableItems: [],
         // 监审期间(年份数组)
@@ -224,20 +267,51 @@
       }
     },
     mounted() {
-      // 如果当前行有表单配置,则使用,否则使用默认配置
-      // 这里可以根据实际需求从后台获取表单配置
-      this.initFormFields()
+      // 表单字段配置在打开弹窗时动态加载,不需要在 mounted 中初始化
     },
     methods: {
       // 处理在线填报点击
-      handleOnlineFillClick(row) {
+      async handleOnlineFillClick(row) {
         this.currentSurveyRow = row
+        // 重置详情数据
+        this.surveyDetailData = {}
 
         // 如果表格类型是"单记录",弹出调查表填报弹窗
         if (row.tableType === '单记录') {
-          // 初始化表单字段配置
-          this.initFormFields()
-          this.surveyFormDialogVisible = true
+          // 如果该行有 id,先调用接口获取详情数据
+          if (row.id && this.auditedUnitId) {
+            try {
+              const params = {
+                uploadId: row.id,
+                auditedUnitId: this.auditedUnitId,
+              }
+              const res = await getSurveyDetail(params)
+              console.log('单记录详情数据', res)
+              if (res && res.code === 200 && res.value) {
+                // 将详情数据转换为表单数据格式
+                // 接口返回的数据可能是数组格式 [{rowid: 'xxx', rkey: 'xxx', rvalue: 'xxx'}, ...]
+                // 需要转换为 {rowid: 'rvalue', ...} 的格式
+                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) {
+                  // 如果不是数组,可能是对象格式,直接使用
+                  Object.assign(detailData, res.value)
+                }
+                this.surveyDetailData = detailData
+                console.log('转换后的详情数据', this.surveyDetailData)
+              }
+            } catch (err) {
+              console.error('获取单记录详情失败', err)
+            }
+          }
+          // 调用接口获取单记录表单字段配置(详情数据已准备好)
+          await this.initFormFields()
+          // 接口调用完成后会自动打开弹窗(在 initFormFields 中处理)
         } else if (row.tableType === '固定表') {
           // 如果表格类型是"固定表",弹出固定表填报弹窗
           this.initFixedTableData()
@@ -259,6 +333,14 @@
           formData: formData,
         })
       },
+      // 处理刷新事件
+      handleRefresh() {
+        // 触发父组件的刷新事件
+        this.$emit('handle-survey-form-save', {
+          row: this.currentSurveyRow,
+          formData: {},
+        })
+      },
       // 处理固定表保存
       handleFixedTableSave(tableData) {
         // 可以将保存的数据传递给父组件
@@ -294,15 +376,68 @@
         }
       },
       // 初始化表单字段配置
-      initFormFields() {
-        // 如果当前行有表单配置,则使用
-        // 这里可以根据实际需求从后台获取表单配置
-        // 例如:从 currentSurveyRow 中获取表单配置,或调用 API 获取
-        if (this.currentSurveyRow && this.currentSurveyRow.formFields) {
+      async initFormFields() {
+        // 如果是单记录类型,调用接口获取表单字段配置
+        if (
+          this.currentSurveyRow &&
+          this.currentSurveyRow.tableType === '单记录' &&
+          this.currentSurveyRow.surveyTemplateId
+        ) {
+          try {
+            const params = {
+              surveyTemplateId: this.currentSurveyRow.surveyTemplateId,
+            }
+            const res = await getSingleRecordSurveyList(params)
+            console.log('单记录表单字段配置', res)
+            if (res && res.code === 200 && res.value) {
+              // 将接口返回的数据转换为表单字段配置格式
+              const { fixedFields, fixedFieldids } = res.value
+
+              if (fixedFields && fixedFieldids) {
+                // 将 fixedFields 和 fixedFieldids 按逗号分割
+                const labels = fixedFields.split(',').map((item) => item.trim())
+                const ids = fixedFieldids.split(',').map((item) => item.trim())
+                console.log('labels', labels)
+                console.log('ids', ids)
+
+                // 组合成表单字段配置数组
+                this.formFields = labels.map((label, index) => ({
+                  prop: ids[index] || `field_${index}`, // 使用 fixedFieldids 作为 prop
+                  label: label, // 使用 fixedFields 作为 label
+                  type: 'input', // 默认类型为 input
+                  colSpan: 12, // 默认占一半宽度
+                  placeholder: `请输入${label}`,
+                  rules: [],
+                  defaultValue: '',
+                  disabled: false,
+                  clearable: true,
+                  multiple: false,
+                  required: false,
+                }))
+              } else {
+                // 如果没有 fixedFields 和 fixedFieldids,使用默认配置
+                this.formFields = this.getMockFormFields()
+              }
+            } else {
+              // 接口返回失败,使用默认配置
+              this.formFields = this.getMockFormFields()
+            }
+            // 打开弹窗
+            this.surveyFormDialogVisible = true
+          } catch (err) {
+            console.error('获取单记录表单字段配置失败', err)
+            // 出错时使用默认配置
+            this.formFields = this.getMockFormFields()
+            this.surveyFormDialogVisible = true
+          }
+        } else if (this.currentSurveyRow && this.currentSurveyRow.formFields) {
+          // 如果当前行有表单配置,则使用
           this.formFields = this.currentSurveyRow.formFields
+          this.surveyFormDialogVisible = true
         } else {
           // 使用假数据作为测试(实际开发中应该从后台获取)
           this.formFields = this.getMockFormFields()
+          this.surveyFormDialogVisible = true
         }
       },
       // 获取假数据表单字段配置(用于测试)

+ 92 - 9
src/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue

@@ -138,6 +138,7 @@
 <script>
   import { Message } from 'element-ui'
   import { dictMixin } from '@/mixins/useDict'
+  import { saveSingleRecordSurvey } from '@/api/audit/survey'
 
   export default {
     name: 'SurveyFormDialog',
@@ -177,6 +178,26 @@
         type: Boolean,
         default: false,
       },
+      // 被监审单位ID
+      auditedUnitId: {
+        type: String,
+        default: '',
+      },
+      // 上传记录ID
+      uploadId: {
+        type: String,
+        default: '',
+      },
+      // 成本调查表模板ID
+      surveyTemplateId: {
+        type: String,
+        default: '',
+      },
+      // 目录ID
+      catalogId: {
+        type: String,
+        default: '',
+      },
     },
     data() {
       return {
@@ -223,6 +244,15 @@
         },
         deep: true,
       },
+      surveyData: {
+        handler() {
+          // 详情数据变化时重新初始化表单(用于回显数据)
+          if (this.dialogVisible) {
+            this.initForm()
+          }
+        },
+        deep: true,
+      },
     },
     created() {
       // 初始化字典数据
@@ -264,7 +294,13 @@
 
         fields.forEach((field) => {
           // 初始化表单值
-          if (this.surveyData && this.surveyData[field.prop] !== undefined) {
+          // 优先使用传入的详情数据(surveyData 中可能包含从 getSurveyDetail 接口返回的数据)
+          if (
+            this.surveyData &&
+            this.surveyData[field.prop] !== undefined &&
+            this.surveyData[field.prop] !== null &&
+            this.surveyData[field.prop] !== ''
+          ) {
             // 优先使用传入的数据
             form[field.prop] = this.surveyData[field.prop]
           } else if (field.defaultValue !== undefined) {
@@ -390,15 +426,62 @@
       handleCancel() {
         this.handleClose()
       },
-      handleSave() {
-        this.$refs.surveyForm.validate((valid) => {
+      async handleSave() {
+        this.$refs.surveyForm.validate(async (valid) => {
           if (valid) {
-            // 保存逻辑
-            console.log('保存表单数据:', this.form)
-            Message.success('保存成功')
-            // 可以在这里触发保存事件,将数据传递给父组件
-            this.$emit('save', { ...this.form })
-            this.handleClose()
+            try {
+              // 判断是否有数据(编辑模式):如果有 uploadId,说明是编辑已有数据
+              const hasData = !!(
+                this.uploadId ||
+                this.surveyData.uploadId ||
+                this.surveyData.id
+              )
+
+              // 将表单数据转换为接口需要的格式
+              const saveData = this.formFields.map((field) => {
+                const dataItem = {
+                  auditedUnitId:
+                    this.auditedUnitId || this.surveyData.auditedUnitId || '',
+                  surveyTemplateId:
+                    this.surveyTemplateId ||
+                    this.surveyData.surveyTemplateId ||
+                    '',
+                  catalogId: this.catalogId || this.surveyData.catalogId || '',
+                  rowid: field.prop, // 字段ID(对应 fixedFieldids)
+                  rkey: field.label, // 字段名称(对应 fixedFields,即 label)
+                  rvalue: this.form[field.prop] || '', // 字段值(表单输入的值)
+                }
+
+                // 如果有数据(编辑模式),添加 uploadId 字段
+                if (hasData) {
+                  dataItem.uploadId =
+                    this.uploadId ||
+                    this.surveyData.uploadId ||
+                    this.surveyData.id ||
+                    ''
+                }
+
+                return dataItem
+              })
+
+              console.log('保存表单数据:', saveData)
+
+              // 调用保存接口
+              const res = await saveSingleRecordSurvey(saveData)
+              if (res && res.code === 200) {
+                Message.success('保存成功')
+                // 触发保存事件,将数据传递给父组件
+                this.$emit('save', { ...this.form })
+                // 触发刷新事件,通知父组件刷新列表
+                this.$emit('refresh')
+                this.handleClose()
+              } else {
+                Message.error(res.message || '保存失败')
+              }
+            } catch (err) {
+              console.error('保存失败', err)
+              Message.error(err.message || '保存失败')
+            }
           } else {
             Message.error('请完善表单信息')
             return false

+ 97 - 4
src/views/EntDeclaration/auditTaskManagement/taskFillIn.vue

@@ -100,12 +100,15 @@
               :paginated-data="formData.paginatedData"
               :pagination="costSurveyPagination"
               :is-view-mode="isViewMode"
+              :audited-unit-id="auditedUnitId"
+              :catalog-id="taskInfo.catalogId"
               @handle-modify="handleModify"
               @handle-data-download="handleDataDownload"
               @handle-data-upload="handleDataUpload"
               @handle-preview="handlePreview"
               @handle-page-change="handleCostSurveyPageChange"
               @handle-size-change="handleCostSurveySizeChange"
+              @handle-survey-form-save="handleSurveyFormSave"
             />
           </el-tab-pane>
 
@@ -276,6 +279,7 @@
   import { dictMixin } from '@/mixins/useDict'
   import { uploadFile } from '@/api/file'
   import { submitPreliminaryOpinion } from '@/api/audit/preliminaryOpinion'
+  import { getSurveyList } from '@/api/audit/survey'
   import ProjectInfoTab from './components/ProjectInfoTab.vue'
   import AuditDocumentTab from './components/AuditDocumentTab.vue'
   import DataRequirementsTab from './components/DataRequirementsTab.vue'
@@ -933,6 +937,9 @@
         } else if (tab.name === 'dataRequirements') {
           // 报送资料要求
           this.getTaskRequirementPage()
+        } else if (tab.name === 'costSurvey') {
+          // 成本调查表
+          this.getCostSurveyList()
         } else if (tab.name === 'messageNotice') {
           // 消息通知
           this.getSendMessage()
@@ -1054,6 +1061,86 @@
           })
       },
 
+      // 获取成本调查表列表
+      getCostSurveyList() {
+        this.tabLoading.costSurvey = true
+        const params = {
+          catalogId: this.taskInfo.catalogId,
+          pageNum: this.costSurveyPagination.currentPage,
+          pageSize: this.costSurveyPagination.pageSize,
+        }
+        getSurveyList(params)
+          .then((res) => {
+            console.log('成本调查表列表', res)
+            if (res && res.code === 200 && res.value) {
+              // 处理返回的数据
+              const records = res.value.records || res.value || []
+              // 映射数据格式,转换为组件需要的格式
+              const mappedData = records.map((item, index) => {
+                // 转换表格类型:1=单记录,2=固定表,3=动态表
+                let tableType = ''
+                if (item.templateType === 1 || item.templateType === '1') {
+                  tableType = '单记录'
+                } else if (
+                  item.templateType === 2 ||
+                  item.templateType === '2'
+                ) {
+                  tableType = '固定表'
+                } else if (
+                  item.templateType === 3 ||
+                  item.templateType === '3'
+                ) {
+                  tableType = '动态表'
+                } else if (item.tableType) {
+                  tableType = item.tableType
+                }
+
+                // 转换是否必填:0=否,1=是
+                const isRequired =
+                  item.isRequired === 1 || item.isRequired === '1' ? '是' : '否'
+
+                // 转换是否上传:0=未上传,1=已上传
+                const isUploaded = item.isUpload === 1 || item.isUpload === '1'
+
+                return {
+                  index: index + 1,
+                  id: item.id,
+                  name: item.surveyTemplateName || '',
+                  dataType: item.dataType || '', // 资料类型
+                  tableType: tableType, // 表格类型(转换后)
+                  isRequired: isRequired, // 是否必填(转换后)
+                  isUploaded: isUploaded, // 是否上传(转换后)
+                  surveyTemplateId: item.surveyTemplateId || '', // 成本调查表模板ID
+                  isDisabled: item.isDisabled || false,
+                  fileUrl: item.fileUrl || '',
+                  dataUrl: item.dataUrl || '',
+                  templateUrl: item.templateUrl || '',
+                  ...item, // 保留其他字段
+                }
+              })
+              // 更新 costSurveyData(完整数据)
+              this.formData.costSurveyData = mappedData
+              // 更新 paginatedData(用于传递给子组件,如果接口返回的是分页数据,直接使用;否则使用全部数据)
+              this.formData.paginatedData = mappedData
+              // 更新分页信息
+              this.costSurveyPagination.total =
+                res.value.total || mappedData.length || 0
+            } else {
+              this.formData.costSurveyData = []
+              this.formData.paginatedData = []
+              this.costSurveyPagination.total = 0
+            }
+          })
+          .catch((err) => {
+            console.error('获取成本调查表列表失败', err)
+            this.formData.costSurveyData = []
+            this.formData.paginatedData = []
+            this.costSurveyPagination.total = 0
+          })
+          .finally(() => {
+            this.tabLoading.costSurvey = false
+          })
+      },
       // 消息通知分页处理
       handleMessageNoticePageChange(pageNo) {
         this.messageNoticePagination.pageNo = pageNo
@@ -1771,16 +1858,22 @@
       // 成本调查表分页 - 页码改变
       handleCostSurveyPageChange(page) {
         this.costSurveyPagination.currentPage = page
-        // 如果成本调查表数据来自API,可以在这里调用API
-        // this.getCostSurveyData()
+        // 调用接口重新获取数据
+        this.getCostSurveyList()
       },
 
       // 成本调查表分页 - 每页条数改变
       handleCostSurveySizeChange(size) {
         this.costSurveyPagination.pageSize = size
         this.costSurveyPagination.currentPage = 1
-        // 如果成本调查表数据来自API,可以在这里调用API
-        // this.getCostSurveyData()
+        // 调用接口重新获取数据
+        this.getCostSurveyList()
+      },
+
+      // 处理单记录调查表保存
+      handleSurveyFormSave(data) {
+        // 保存成功后刷新列表
+        this.getCostSurveyList()
       },
     },
   }

+ 1 - 1
src/views/EntDeclaration/auditTaskProcessing/index.vue

@@ -265,7 +265,7 @@
         searchForm: {
           pageNum: 1,
           pageSize: 10,
-          projectYear: '',
+          projectYear: '2025',
           projectName: '',
           projectSource: '',
           auditForm: '',