|
|
@@ -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
|
|
|
}
|
|
|
},
|
|
|
// 获取假数据表单字段配置(用于测试)
|