|
@@ -32,12 +32,12 @@
|
|
|
border
|
|
border
|
|
|
style="width: 100%"
|
|
style="width: 100%"
|
|
|
>
|
|
>
|
|
|
- <el-table-column
|
|
|
|
|
|
|
+ <!-- <el-table-column
|
|
|
label="序号"
|
|
label="序号"
|
|
|
width="100"
|
|
width="100"
|
|
|
align="center"
|
|
align="center"
|
|
|
prop="orderNum"
|
|
prop="orderNum"
|
|
|
- ></el-table-column>
|
|
|
|
|
|
|
+ ></el-table-column> -->
|
|
|
<el-table-column
|
|
<el-table-column
|
|
|
v-for="(item, index) in contentEditForm.fixedTable
|
|
v-for="(item, index) in contentEditForm.fixedTable
|
|
|
.fixedTablesTitle"
|
|
.fixedTablesTitle"
|
|
@@ -45,13 +45,13 @@
|
|
|
:label="item.rkey"
|
|
:label="item.rkey"
|
|
|
align="center"
|
|
align="center"
|
|
|
>
|
|
>
|
|
|
- <template slot-scope="scope">
|
|
|
|
|
|
|
+ <!-- <template slot-scope="scope">
|
|
|
{{
|
|
{{
|
|
|
scope.row.fixedValues
|
|
scope.row.fixedValues
|
|
|
? scope.row.fixedValues[item.rkey]
|
|
? scope.row.fixedValues[item.rkey]
|
|
|
: ''
|
|
: ''
|
|
|
}}
|
|
}}
|
|
|
- </template>
|
|
|
|
|
|
|
+ </template> -->
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
</el-table>
|
|
</el-table>
|
|
|
</div>
|
|
</div>
|
|
@@ -218,10 +218,26 @@
|
|
|
type: Object,
|
|
type: Object,
|
|
|
default: () => ({
|
|
default: () => ({
|
|
|
surveyTemplateName: '',
|
|
surveyTemplateName: '',
|
|
|
- templateType: '单记录',
|
|
|
|
|
|
|
+ templateType: '1',
|
|
|
|
|
+ versionId: '',
|
|
|
|
|
+ // 单记录列表
|
|
|
tableHeaders: [],
|
|
tableHeaders: [],
|
|
|
- fixedTable: [],
|
|
|
|
|
- dynamicTable: [],
|
|
|
|
|
|
|
+ // 固定表列表
|
|
|
|
|
+ fixedTable: {
|
|
|
|
|
+ tableHeaders: [],
|
|
|
|
|
+ fixedTables: [],
|
|
|
|
|
+ fixedTablesTitle: [],
|
|
|
|
|
+ fixedTableHeaders: [],
|
|
|
|
|
+ },
|
|
|
|
|
+ // 动态表列表
|
|
|
|
|
+ dynamicTable: {
|
|
|
|
|
+ tableHeaders: [],
|
|
|
|
|
+ dynamicTables: [],
|
|
|
|
|
+ dynamicTablesTitle: [],
|
|
|
|
|
+ dynamicTableHeaders: [],
|
|
|
|
|
+ },
|
|
|
|
|
+ isDynamicTables: false,
|
|
|
|
|
+ isFixedTables: false,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
// 是否禁用编辑
|
|
// 是否禁用编辑
|
|
@@ -233,7 +249,7 @@
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
contentEditForm: {
|
|
contentEditForm: {
|
|
|
- tableName: '',
|
|
|
|
|
|
|
+ surveyTemplateName: '',
|
|
|
templateType: '1',
|
|
templateType: '1',
|
|
|
versionId: '',
|
|
versionId: '',
|
|
|
// 单记录列表
|
|
// 单记录列表
|
|
@@ -290,6 +306,15 @@
|
|
|
surveyTemplateId: this.contentEditForm.data.surveyId,
|
|
surveyTemplateId: this.contentEditForm.data.surveyId,
|
|
|
}).then((res) => {
|
|
}).then((res) => {
|
|
|
// 根据模板类型解析并显示数据
|
|
// 根据模板类型解析并显示数据
|
|
|
|
|
+ // if (this.contentEditForm.templateType === '1') {
|
|
|
|
|
+ // if (res.value.fixedFields) {
|
|
|
|
|
+ // console.log(this.contentEditForm)
|
|
|
|
|
+ // this.contentEditForm.fixedTable.fixedTablesTitle =
|
|
|
|
|
+ // this.stringToObjects(res.value.fixedFields || '')
|
|
|
|
|
+ // this.contentEditForm.fixedTable.fixedTables = []
|
|
|
|
|
+ // console.log(this.contentEditForm.fixedTable.fixedTablesTitle)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
if (
|
|
if (
|
|
|
this.contentEditForm.templateType === '1' ||
|
|
this.contentEditForm.templateType === '1' ||
|
|
|
this.contentEditForm.templateType === '2'
|
|
this.contentEditForm.templateType === '2'
|
|
@@ -307,80 +332,29 @@
|
|
|
* @param {Object} responseData - listByCurrentTemplateId接口返回的数据
|
|
* @param {Object} responseData - listByCurrentTemplateId接口返回的数据
|
|
|
*/
|
|
*/
|
|
|
parseAndDisplayFixedTableData(responseData) {
|
|
parseAndDisplayFixedTableData(responseData) {
|
|
|
- console.log('开始解析固定表数据:', responseData)
|
|
|
|
|
-
|
|
|
|
|
- // 确保数据初始化
|
|
|
|
|
- if (!this.contentEditForm.fixedTable) {
|
|
|
|
|
- this.contentEditForm.fixedTable = {
|
|
|
|
|
- tableHeaders: [],
|
|
|
|
|
- fixedTables: [],
|
|
|
|
|
- fixedTablesTitle: [],
|
|
|
|
|
- fixedTableHeaders: [],
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 初始化表头 - 使用默认表头配置,确保即使没有返回字段也能显示列
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTablesTitle = [
|
|
|
|
|
- { rkey: '序号', rvalue: '序号' },
|
|
|
|
|
- { rkey: '项目', rvalue: '项目' },
|
|
|
|
|
- { rkey: 'cellCode', rvalue: '指标编号' },
|
|
|
|
|
- { rkey: 'calculationFormula', rvalue: '计算公式' },
|
|
|
|
|
- { rkey: 'unit', rvalue: '单位' },
|
|
|
|
|
- ]
|
|
|
|
|
-
|
|
|
|
|
- // 如果API返回了字段配置,则使用API返回的字段
|
|
|
|
|
- if (
|
|
|
|
|
- responseData &&
|
|
|
|
|
- responseData.value &&
|
|
|
|
|
- responseData.value.fixedFields
|
|
|
|
|
- ) {
|
|
|
|
|
- const apiFields = this.stringToObjects(responseData.value.fixedFields)
|
|
|
|
|
- if (apiFields.length > 0) {
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTablesTitle = apiFields
|
|
|
|
|
- }
|
|
|
|
|
- } else if (
|
|
|
|
|
- this.contentEditForm.fixedTable.tableHeaders &&
|
|
|
|
|
- this.contentEditForm.fixedTable.tableHeaders.length > 0
|
|
|
|
|
- ) {
|
|
|
|
|
- // 尝试从tableHeaders中获取字段配置
|
|
|
|
|
|
|
+ if (responseData.value.fixedFields) {
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTablesTitle =
|
|
|
|
|
+ this.stringToObjects(responseData.value.fixedFields || '')
|
|
|
|
|
+ } else {
|
|
|
let fixedFields = this.contentEditForm.fixedTable.tableHeaders
|
|
let fixedFields = this.contentEditForm.fixedTable.tableHeaders
|
|
|
- .map((item) => item.fieldName || '')
|
|
|
|
|
- .filter(Boolean)
|
|
|
|
|
|
|
+ .map((item) => item.fieldName)
|
|
|
.join(',')
|
|
.join(',')
|
|
|
-
|
|
|
|
|
- if (fixedFields) {
|
|
|
|
|
- const headerFields = this.stringToObjects(fixedFields)
|
|
|
|
|
- if (headerFields.length > 0) {
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTablesTitle = headerFields
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTablesTitle =
|
|
|
|
|
+ this.stringToObjects(fixedFields || '')
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
|
|
const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
|
|
|
- console.log('生成的表头标题:', fixedTitles)
|
|
|
|
|
-
|
|
|
|
|
- // 过滤掉序号列,创建固定表头
|
|
|
|
|
this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
|
|
this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
|
|
|
(title) => title.rkey !== '序号'
|
|
(title) => title.rkey !== '序号'
|
|
|
)
|
|
)
|
|
|
- console.log(
|
|
|
|
|
- '过滤后的固定表头:',
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTableHeaders
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // 检查数据有效性
|
|
|
|
|
if (
|
|
if (
|
|
|
!responseData ||
|
|
!responseData ||
|
|
|
!responseData.value ||
|
|
!responseData.value ||
|
|
|
!responseData.value.itemlist
|
|
!responseData.value.itemlist
|
|
|
) {
|
|
) {
|
|
|
- console.error('无效的响应数据:', responseData)
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- const itemList = responseData.value.itemlist
|
|
|
|
|
- // 清空现有数据
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables = []
|
|
|
|
|
|
|
|
|
|
|
|
+ const itemList = responseData.value.itemlist
|
|
|
const allRows = []
|
|
const allRows = []
|
|
|
|
|
|
|
|
// 清空现有数据
|
|
// 清空现有数据
|
|
@@ -415,33 +389,10 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 初始化fixedValues并填充实际值
|
|
// 初始化fixedValues并填充实际值
|
|
|
- newRow.fixedValues = {}
|
|
|
|
|
fixedTitles.forEach((title) => {
|
|
fixedTitles.forEach((title) => {
|
|
|
- // 优先使用item中的对应字段值
|
|
|
|
|
- if (item[title.rkey] !== undefined) {
|
|
|
|
|
- newRow.fixedValues[title.rkey] = item[title.rkey]
|
|
|
|
|
- }
|
|
|
|
|
- // 特殊处理序号字段
|
|
|
|
|
- else if (title.rkey === '序号') {
|
|
|
|
|
- newRow.fixedValues[title.rkey] = item.orderNum || index + 1
|
|
|
|
|
- }
|
|
|
|
|
- // 默认空字符串
|
|
|
|
|
- else {
|
|
|
|
|
- newRow.fixedValues[title.rkey] = ''
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ newRow.fixedValues[title.rkey] = item[title.rkey] || ''
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 确保主要字段在fixedValues中也存在
|
|
|
|
|
- if (item.cellCode) newRow.fixedValues.cellCode = item.cellCode
|
|
|
|
|
- if (item.calculationFormula)
|
|
|
|
|
- newRow.fixedValues.calculationFormula = item.calculationFormula
|
|
|
|
|
- if (item.unit) newRow.fixedValues.unit = item.unit
|
|
|
|
|
-
|
|
|
|
|
- console.log(
|
|
|
|
|
- `处理行数据${index + 1}的fixedValues:`,
|
|
|
|
|
- newRow.fixedValues
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
allRows.push(newRow)
|
|
allRows.push(newRow)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -492,23 +443,12 @@
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
this.contentEditForm.fixedTable.fixedTables = sortedArray
|
|
this.contentEditForm.fixedTable.fixedTables = sortedArray
|
|
|
- console.log(
|
|
|
|
|
- '最终表格数据:',
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables
|
|
|
|
|
- )
|
|
|
|
|
- console.log('表格数据长度:', sortedArray.length)
|
|
|
|
|
- if (sortedArray.length > 0) {
|
|
|
|
|
- console.log('第一条数据详情:', sortedArray[0])
|
|
|
|
|
- console.log('第一条数据的fixedValues:', sortedArray[0].fixedValues)
|
|
|
|
|
- }
|
|
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
* 解析并回显动态表项目数据
|
|
* 解析并回显动态表项目数据
|
|
|
* @param {Object} responseData - listByCurrentTemplateId接口返回的数据
|
|
* @param {Object} responseData - listByCurrentTemplateId接口返回的数据
|
|
|
*/
|
|
*/
|
|
|
parseAndDisplayDynamicTableData(responseData) {
|
|
parseAndDisplayDynamicTableData(responseData) {
|
|
|
- console.log('开始解析动态表数据:', responseData)
|
|
|
|
|
-
|
|
|
|
|
// 确保数据初始化
|
|
// 确保数据初始化
|
|
|
if (!this.contentEditForm.dynamicTable) {
|
|
if (!this.contentEditForm.dynamicTable) {
|
|
|
this.contentEditForm.dynamicTable = {
|
|
this.contentEditForm.dynamicTable = {
|
|
@@ -519,12 +459,6 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 初始化默认表头
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTablesTitle = [
|
|
|
|
|
- { rkey: '序号', rvalue: '序号' },
|
|
|
|
|
- { rkey: '项目', rvalue: '项目' },
|
|
|
|
|
- ]
|
|
|
|
|
-
|
|
|
|
|
// 使用API返回的字段配置(如果有)
|
|
// 使用API返回的字段配置(如果有)
|
|
|
if (responseData.value.fixedFields) {
|
|
if (responseData.value.fixedFields) {
|
|
|
this.contentEditForm.dynamicTable.dynamicTablesTitle =
|
|
this.contentEditForm.dynamicTable.dynamicTablesTitle =
|
|
@@ -543,10 +477,6 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log(
|
|
|
|
|
- '动态表表头标题:',
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
|
|
|
- )
|
|
|
|
|
const dynamicTitles =
|
|
const dynamicTitles =
|
|
|
this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
|
this.contentEditForm.dynamicTable.dynamicTableHeaders =
|
|
this.contentEditForm.dynamicTable.dynamicTableHeaders =
|
|
@@ -605,11 +535,6 @@
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- console.log(
|
|
|
|
|
- `处理动态表行数据${index + 1}的dynamicValues:`,
|
|
|
|
|
- newRow.dynamicValues
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
allRows.push(newRow)
|
|
allRows.push(newRow)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -702,7 +627,6 @@
|
|
|
},
|
|
},
|
|
|
// 字符串转对象数组
|
|
// 字符串转对象数组
|
|
|
stringToObjects(str) {
|
|
stringToObjects(str) {
|
|
|
- console.log('转换字符串为对象数组:', str)
|
|
|
|
|
if (!str || typeof str !== 'string') return []
|
|
if (!str || typeof str !== 'string') return []
|
|
|
|
|
|
|
|
const result = str
|
|
const result = str
|
|
@@ -716,7 +640,6 @@
|
|
|
})
|
|
})
|
|
|
.filter((item) => item.rkey)
|
|
.filter((item) => item.rkey)
|
|
|
|
|
|
|
|
- console.log('转换结果:', result)
|
|
|
|
|
return result
|
|
return result
|
|
|
},
|
|
},
|
|
|
|
|
|