|
@@ -72,7 +72,10 @@
|
|
|
>
|
|
>
|
|
|
<template slot-scope="scope">
|
|
<template slot-scope="scope">
|
|
|
{{
|
|
{{
|
|
|
- scope.row.fixedValues ? scope.row.fixedValues['序号'] : ''
|
|
|
|
|
|
|
+ (scope.row.fixedValues && scope.row.fixedValues['序号']) ||
|
|
|
|
|
+ scope.row.orderNum ||
|
|
|
|
|
+ scope.row.orderText ||
|
|
|
|
|
+ ''
|
|
|
}}
|
|
}}
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
@@ -304,58 +307,250 @@
|
|
|
* @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中获取字段配置
|
|
|
|
|
+ let fixedFields = this.contentEditForm.fixedTable.tableHeaders
|
|
|
|
|
+ .map((item) => item.fieldName || '')
|
|
|
|
|
+ .filter(Boolean)
|
|
|
|
|
+ .join(',')
|
|
|
|
|
+
|
|
|
|
|
+ if (fixedFields) {
|
|
|
|
|
+ const headerFields = this.stringToObjects(fixedFields)
|
|
|
|
|
+ if (headerFields.length > 0) {
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTablesTitle = headerFields
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
|
|
|
|
|
+ console.log('生成的表头标题:', fixedTitles)
|
|
|
|
|
+
|
|
|
|
|
+ // 过滤掉序号列,创建固定表头
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
|
|
|
|
|
+ (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
|
|
const itemList = responseData.value.itemlist
|
|
|
- this.contentEditForm.fixedTable.fixedTablesTitle = this.stringToObjects(
|
|
|
|
|
- responseData.value.fixedFields || ''
|
|
|
|
|
- )
|
|
|
|
|
- const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTableHeaders =
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTablesTitle.filter(
|
|
|
|
|
- (title) => title.rkey !== '序号'
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ // 清空现有数据
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTables = []
|
|
|
|
|
+
|
|
|
|
|
+ const allRows = []
|
|
|
|
|
|
|
|
// 清空现有数据
|
|
// 清空现有数据
|
|
|
this.contentEditForm.fixedTable.fixedTables = []
|
|
this.contentEditForm.fixedTable.fixedTables = []
|
|
|
|
|
|
|
|
// 遍历itemList,为每个项目创建一行数据
|
|
// 遍历itemList,为每个项目创建一行数据
|
|
|
itemList.forEach((item, index) => {
|
|
itemList.forEach((item, index) => {
|
|
|
- const orderNum = item.orderNum
|
|
|
|
|
- ? parseInt(item.orderNum, 10)
|
|
|
|
|
- : index + 1
|
|
|
|
|
|
|
+ // 判断是否为子项(parentid不为-1且不为"-1")
|
|
|
|
|
+ const isSubItem =
|
|
|
|
|
+ item.parentid && item.parentid !== -1 && item.parentid !== '-1'
|
|
|
|
|
+
|
|
|
const newRow = {
|
|
const newRow = {
|
|
|
- orderNum: orderNum,
|
|
|
|
|
|
|
+ orderText: item.orderNum || '', // 显示用序号
|
|
|
|
|
+ orderNum: item.orderNum || '', // 保留原始序号用于发送后端
|
|
|
surveyTemplateId: item.surveyTemplateId,
|
|
surveyTemplateId: item.surveyTemplateId,
|
|
|
versionId: item.versionId,
|
|
versionId: item.versionId,
|
|
|
|
|
+ cellCode: item.cellCode || '',
|
|
|
|
|
+ calculationFormula: item.calculationFormula || '',
|
|
|
|
|
+ unit: item.unit || '',
|
|
|
fixedValues: {},
|
|
fixedValues: {},
|
|
|
- // 保存每行数据的id,用于更新操作
|
|
|
|
|
itemId: item.id || null,
|
|
itemId: item.id || null,
|
|
|
|
|
+ parentid: item.parentid || -1,
|
|
|
|
|
+ isChild: isSubItem,
|
|
|
|
|
+ isSubItem: isSubItem,
|
|
|
|
|
+ rowid: item.rowid || this.generateUUID(),
|
|
|
|
|
+ jsonstr: item.jsonstr || null,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确保orderNum是数字类型
|
|
|
|
|
+ if (item.orderNum) {
|
|
|
|
|
+ newRow.orderNum = parseInt(item.orderNum, 10) || 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 初始化fixedValues并填充实际值
|
|
// 初始化fixedValues并填充实际值
|
|
|
|
|
+ newRow.fixedValues = {}
|
|
|
fixedTitles.forEach((title) => {
|
|
fixedTitles.forEach((title) => {
|
|
|
- newRow.fixedValues[title.rkey] = item[title.rkey] || ''
|
|
|
|
|
|
|
+ // 优先使用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] = ''
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables.push(newRow)
|
|
|
|
|
|
|
+ // 确保主要字段在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.sort((a, b) => {
|
|
|
|
|
+ // 先按orderNum排序父项
|
|
|
|
|
+ if (a.isChild && !b.isChild) {
|
|
|
|
|
+ // 如果a是子项,b是父项,需要检查a的父项是否在b之后
|
|
|
|
|
+ const parentOfA = allRows.find(
|
|
|
|
|
+ (item) => item.rowid === a.parentid || item.itemId === a.parentid
|
|
|
|
|
+ )
|
|
|
|
|
+ if (parentOfA && parentOfA.orderNum > b.orderNum) {
|
|
|
|
|
+ return 1
|
|
|
|
|
+ }
|
|
|
|
|
+ return -1
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!a.isChild && b.isChild) {
|
|
|
|
|
+ // 如果a是父项,b是子项,需要检查b的父项是否在a之前
|
|
|
|
|
+ const parentOfB = allRows.find(
|
|
|
|
|
+ (item) => item.rowid === b.parentid || item.itemId === b.parentid
|
|
|
|
|
+ )
|
|
|
|
|
+ if (parentOfB && parentOfB.orderNum < a.orderNum) {
|
|
|
|
|
+ return -1
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果都是父项或都是子项,按orderNum排序
|
|
|
|
|
+ return (a.orderNum || 0) - (b.orderNum || 0)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 按orderNum排序
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables.sort(
|
|
|
|
|
- (a, b) => a.orderNum - b.orderNum
|
|
|
|
|
|
|
+ // 重新排序,确保子项紧跟在其对应的父项后面
|
|
|
|
|
+ const sortedArray = []
|
|
|
|
|
+ const parentItems = allRows.filter((item) => !item.isChild)
|
|
|
|
|
+ const childItems = allRows.filter((item) => item.isChild)
|
|
|
|
|
+
|
|
|
|
|
+ parentItems.forEach((parent) => {
|
|
|
|
|
+ sortedArray.push(parent)
|
|
|
|
|
+ // 找到并添加该父项的所有子项
|
|
|
|
|
+ const relatedChildren = childItems.filter(
|
|
|
|
|
+ (child) =>
|
|
|
|
|
+ child.parentid === parent.rowid ||
|
|
|
|
|
+ child.parentid === parent.itemId
|
|
|
|
|
+ )
|
|
|
|
|
+ // 子项按orderNum排序
|
|
|
|
|
+ relatedChildren.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
|
|
|
|
|
+ sortedArray.push(...relatedChildren)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ this.contentEditForm.dynamicTable = {
|
|
|
|
|
+ tableHeaders: [],
|
|
|
|
|
+ dynamicTables: [],
|
|
|
|
|
+ dynamicTablesTitle: [],
|
|
|
|
|
+ dynamicTableHeaders: [],
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化默认表头
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTablesTitle = [
|
|
|
|
|
+ { rkey: '序号', rvalue: '序号' },
|
|
|
|
|
+ { rkey: '项目', rvalue: '项目' },
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ // 使用API返回的字段配置(如果有)
|
|
|
|
|
+ if (responseData.value.fixedFields) {
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTablesTitle =
|
|
|
|
|
+ this.stringToObjects(responseData.value.fixedFields || '')
|
|
|
|
|
+ } else if (
|
|
|
|
|
+ this.contentEditForm.dynamicTable.tableHeaders &&
|
|
|
|
|
+ this.contentEditForm.dynamicTable.tableHeaders.length > 0
|
|
|
|
|
+ ) {
|
|
|
|
|
+ let fixedFields = this.contentEditForm.dynamicTable.tableHeaders
|
|
|
|
|
+ .map((item) => item.fieldName || '')
|
|
|
|
|
+ .filter(Boolean)
|
|
|
|
|
+ .join(',')
|
|
|
|
|
+ if (fixedFields) {
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTablesTitle =
|
|
|
|
|
+ this.stringToObjects(fixedFields || '')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ '动态表表头标题:',
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
|
|
|
+ )
|
|
|
|
|
+ const dynamicTitles =
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTableHeaders =
|
|
|
|
|
+ dynamicTitles.filter((title) => title.rkey !== '序号')
|
|
|
if (
|
|
if (
|
|
|
!responseData ||
|
|
!responseData ||
|
|
|
!responseData.value ||
|
|
!responseData.value ||
|
|
@@ -365,68 +560,176 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const itemList = responseData.value.itemlist
|
|
const itemList = responseData.value.itemlist
|
|
|
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
|
|
|
|
|
- this.stringToObjects(responseData.value.fixedFields || '')
|
|
|
|
|
- const dynamicTitles =
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTablesTitle
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTableHeaders =
|
|
|
|
|
- dynamicTitles.filter((title) => title.rkey !== '序号')
|
|
|
|
|
|
|
|
|
|
- // 按orderNum分组数据
|
|
|
|
|
- const groupedData = {}
|
|
|
|
|
- itemList.forEach((item) => {
|
|
|
|
|
- const orderNum = item.orderNum ? parseInt(item.orderNum, 10) : 1
|
|
|
|
|
- if (!groupedData[orderNum]) {
|
|
|
|
|
- groupedData[orderNum] = []
|
|
|
|
|
- }
|
|
|
|
|
- groupedData[orderNum].push(item)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ const allRows = []
|
|
|
|
|
|
|
|
// 清空现有数据
|
|
// 清空现有数据
|
|
|
this.contentEditForm.dynamicTable.dynamicTables = []
|
|
this.contentEditForm.dynamicTable.dynamicTables = []
|
|
|
|
|
|
|
|
- // 为每个orderNum创建一行数据
|
|
|
|
|
- Object.keys(groupedData).forEach((orderNum) => {
|
|
|
|
|
- const itemsForOrder = groupedData[orderNum]
|
|
|
|
|
|
|
+ // 遍历itemList,为每个项目创建一行数据
|
|
|
|
|
+ itemList.forEach((item, index) => {
|
|
|
|
|
+ // 判断是否为子项(parentid不为-1且不为"-1")
|
|
|
|
|
+ const isSubItem =
|
|
|
|
|
+ item.parentid && item.parentid !== -1 && item.parentid !== '-1'
|
|
|
|
|
+
|
|
|
const newRow = {
|
|
const newRow = {
|
|
|
- orderNum: parseInt(orderNum, 10),
|
|
|
|
|
- surveyTemplateId: itemsForOrder[0].surveyTemplateId,
|
|
|
|
|
- versionId: itemsForOrder[0].versionId,
|
|
|
|
|
|
|
+ orderText: item.orderNum || '', // 显示用序号
|
|
|
|
|
+ orderNum: item.orderNum || '', // 保留原始序号用于发送后端
|
|
|
|
|
+ surveyTemplateId: item.surveyTemplateId,
|
|
|
dynamicValues: {},
|
|
dynamicValues: {},
|
|
|
- // 保存每行数据的id,用于更新操作(这是itemlist中每条记录的id)
|
|
|
|
|
- itemId: itemsForOrder[0].id || null,
|
|
|
|
|
|
|
+ itemId: item.id || null,
|
|
|
|
|
+ parentid: item.parentid || -1,
|
|
|
|
|
+ isChild: isSubItem,
|
|
|
|
|
+ isSubItem: isSubItem,
|
|
|
|
|
+ rowid: item.rowid || this.generateUUID(),
|
|
|
|
|
+ jsonstr: item.jsonstr || null,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确保orderNum是数字类型
|
|
|
|
|
+ if (item.orderNum) {
|
|
|
|
|
+ newRow.orderNum = parseInt(item.orderNum, 10) || 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 初始化dynamicValues
|
|
// 初始化dynamicValues
|
|
|
|
|
+ newRow.dynamicValues = {}
|
|
|
dynamicTitles.forEach((title) => {
|
|
dynamicTitles.forEach((title) => {
|
|
|
- newRow.dynamicValues[title.rkey] = ''
|
|
|
|
|
|
|
+ // 特殊处理序号字段
|
|
|
|
|
+ if (title.rkey === '序号') {
|
|
|
|
|
+ // 优先使用item中的序号值,如果没有则使用orderNum或index+1
|
|
|
|
|
+ newRow.dynamicValues[title.rkey] =
|
|
|
|
|
+ item[title.rkey] || item.orderNum || index + 1
|
|
|
|
|
+ }
|
|
|
|
|
+ // 排除其他序号相关字段,避免重复显示
|
|
|
|
|
+ else if (title.rkey !== 'ordernum' && title.rkey !== 'orderText') {
|
|
|
|
|
+ newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 填充实际值
|
|
|
|
|
- itemsForOrder.forEach((item) => {
|
|
|
|
|
- // 从item中找出对应的字段值
|
|
|
|
|
- dynamicTitles.forEach((title) => {
|
|
|
|
|
- if (item[title.rkey] !== undefined) {
|
|
|
|
|
- newRow.dynamicValues[title.rkey] = item[title.rkey]
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `处理动态表行数据${index + 1}的dynamicValues:`,
|
|
|
|
|
+ newRow.dynamicValues
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ allRows.push(newRow)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 按父子关系排序:父项在前,子项在对应的父项后面
|
|
|
|
|
+ // 1. 先创建一个映射表,方便通过ID查找父项
|
|
|
|
|
+ const rowMap = new Map()
|
|
|
|
|
+ const sortedArray = []
|
|
|
|
|
+ const addedItems = new Set()
|
|
|
|
|
+
|
|
|
|
|
+ // 深拷贝原始数据并过滤掉重复项
|
|
|
|
|
+ const uniqueRows = allRows.reduce((acc, current) => {
|
|
|
|
|
+ const isDuplicate = acc.some(
|
|
|
|
|
+ (row) =>
|
|
|
|
|
+ (row.rowid && current.rowid && row.rowid === current.rowid) ||
|
|
|
|
|
+ (row.itemId && current.itemId && row.itemId === current.itemId)
|
|
|
|
|
+ )
|
|
|
|
|
+ if (!isDuplicate) {
|
|
|
|
|
+ acc.push(JSON.parse(JSON.stringify(current)))
|
|
|
|
|
+ }
|
|
|
|
|
+ return acc
|
|
|
|
|
+ }, [])
|
|
|
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.push(newRow)
|
|
|
|
|
|
|
+ // 填充映射表
|
|
|
|
|
+ uniqueRows.forEach((row) => {
|
|
|
|
|
+ if (row.rowid) rowMap.set(String(row.rowid), row)
|
|
|
|
|
+ if (row.itemId) rowMap.set(String(row.itemId), row)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 按orderNum排序
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.sort(
|
|
|
|
|
- (a, b) => a.orderNum - b.orderNum
|
|
|
|
|
|
|
+ // 先按orderNum排序所有父项
|
|
|
|
|
+ const parentItems = uniqueRows.filter((item) => !item.isChild)
|
|
|
|
|
+ parentItems.sort(
|
|
|
|
|
+ (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ // 递归添加父项及其子项的函数
|
|
|
|
|
+ const addItemWithChildren = (item) => {
|
|
|
|
|
+ // 确保项目ID唯一
|
|
|
|
|
+ const itemIdKey = String(
|
|
|
|
|
+ item.rowid || item.itemId || `temp_${Math.random()}`
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 如果已经添加过,则跳过
|
|
|
|
|
+ if (addedItems.has(itemIdKey)) return
|
|
|
|
|
+
|
|
|
|
|
+ // 添加当前项目
|
|
|
|
|
+ sortedArray.push(item)
|
|
|
|
|
+ addedItems.add(itemIdKey)
|
|
|
|
|
+
|
|
|
|
|
+ // 找到并添加所有子项
|
|
|
|
|
+ const children = uniqueRows.filter((child) => {
|
|
|
|
|
+ if (child.isChild) {
|
|
|
|
|
+ const childParentId = String(child.parentid)
|
|
|
|
|
+ return (
|
|
|
|
|
+ childParentId === String(item.rowid) ||
|
|
|
|
|
+ childParentId === String(item.itemId)
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 子项按orderNum排序
|
|
|
|
|
+ children.sort(
|
|
|
|
|
+ (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 添加所有子项
|
|
|
|
|
+ children.forEach((child) => addItemWithChildren(child))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历所有父项,添加父项及其子项
|
|
|
|
|
+ parentItems.forEach((parent) => addItemWithChildren(parent))
|
|
|
|
|
+
|
|
|
|
|
+ // 添加剩余的没有被添加的项目(应该很少,但作为兜底)
|
|
|
|
|
+ uniqueRows.forEach((row) => {
|
|
|
|
|
+ const itemIdKey = String(
|
|
|
|
|
+ row.rowid || row.itemId || `temp_${Math.random()}`
|
|
|
|
|
+ )
|
|
|
|
|
+ if (!addedItems.has(itemIdKey)) {
|
|
|
|
|
+ sortedArray.push(row)
|
|
|
|
|
+ addedItems.add(itemIdKey)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 最后,重新计算显示序号,确保序号连续且正确
|
|
|
|
|
+ sortedArray.forEach((item, index) => {
|
|
|
|
|
+ item.orderText = String(index + 1)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables = sortedArray
|
|
|
},
|
|
},
|
|
|
- //分割字符串
|
|
|
|
|
|
|
+ // 字符串转对象数组
|
|
|
stringToObjects(str) {
|
|
stringToObjects(str) {
|
|
|
- const items = str.split(',')
|
|
|
|
|
- return items.map((item) => ({
|
|
|
|
|
- rkey: item,
|
|
|
|
|
- rvalue: '',
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ console.log('转换字符串为对象数组:', str)
|
|
|
|
|
+ if (!str || typeof str !== 'string') return []
|
|
|
|
|
+
|
|
|
|
|
+ const result = str
|
|
|
|
|
+ .split(',')
|
|
|
|
|
+ .map((item) => {
|
|
|
|
|
+ const trimmed = item.trim()
|
|
|
|
|
+ return {
|
|
|
|
|
+ rkey: trimmed,
|
|
|
|
|
+ rvalue: trimmed,
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter((item) => item.rkey)
|
|
|
|
|
+
|
|
|
|
|
+ console.log('转换结果:', result)
|
|
|
|
|
+ return result
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 生成UUID用于临时行ID
|
|
|
|
|
+ generateUUID() {
|
|
|
|
|
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
|
|
|
|
|
+ /[xy]/g,
|
|
|
|
|
+ function (c) {
|
|
|
|
|
+ const r = (Math.random() * 16) | 0
|
|
|
|
|
+ const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
|
|
|
+ return v.toString(16)
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
},
|
|
},
|
|
|
// 处理选择变化
|
|
// 处理选择变化
|
|
|
handleSelectionChange(val) {
|
|
handleSelectionChange(val) {
|