|
|
@@ -1426,6 +1426,7 @@
|
|
|
:data="indicatorTableData"
|
|
|
border
|
|
|
style="width: 100%; margin-top: 10px"
|
|
|
+ class="mb20"
|
|
|
@row-click="handleRowClick"
|
|
|
>
|
|
|
<el-table-column label="选择" width="60">
|
|
|
@@ -2315,19 +2316,47 @@
|
|
|
|
|
|
switch (type) {
|
|
|
case '固定表项目':
|
|
|
+ let parentIndex1 =
|
|
|
+ this.contentEditForm.fixedTable.fixedTables.findIndex(
|
|
|
+ (item) => item.rowid == parentRow.rowid
|
|
|
+ )
|
|
|
+ if (
|
|
|
+ !this.contentEditForm.fixedTable.fixedTables[parentIndex1]
|
|
|
+ .children
|
|
|
+ ) {
|
|
|
+ this.$set(
|
|
|
+ this.contentEditForm.fixedTable.fixedTables[parentIndex1],
|
|
|
+ 'children',
|
|
|
+ []
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
let childOrderNum =
|
|
|
- this.contentEditForm.fixedTable.fixedTables.length + 1
|
|
|
+ this.contentEditForm.fixedTable.fixedTables[parentIndex1].children
|
|
|
+ .length + 1
|
|
|
+
|
|
|
+ let fixedValues = {
|
|
|
+ ...parentRow.fixedValues,
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const key in fixedValues) {
|
|
|
+ if (key == '序号') {
|
|
|
+ fixedValues[key] = childOrderNum
|
|
|
+ } else {
|
|
|
+ fixedValues[key] = ''
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const fixedNewRow = {
|
|
|
- orderText: childOrderNum, // 显示用的序号文本
|
|
|
- orderNum: childOrderNum, // 发送给后端的序号
|
|
|
+ orderText: this.contentEditForm.fixedTable.fixedTables.length + 1,
|
|
|
+ orderNum: this.contentEditForm.fixedTable.fixedTables.length + 1,
|
|
|
cellCode: '',
|
|
|
calculationFormula: '',
|
|
|
unit: '',
|
|
|
tabtype: this.templateType,
|
|
|
surveyTemplateId: this.surveyTemplateId,
|
|
|
versionId: this.versionId,
|
|
|
- fixedValues: { ...parentRow.fixedValues },
|
|
|
+ fixedValues: fixedValues,
|
|
|
parentid: parentRow.rowid,
|
|
|
isChild: true,
|
|
|
isSubItem: true,
|
|
|
@@ -2341,26 +2370,52 @@
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
-
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(
|
|
|
- index + 1,
|
|
|
- 0,
|
|
|
- fixedNewRow
|
|
|
- )
|
|
|
+ this.contentEditForm.fixedTable.fixedTables[
|
|
|
+ parentIndex1
|
|
|
+ ].children.push(fixedNewRow)
|
|
|
+ // this.contentEditForm.fixedTable.fixedTables.splice(
|
|
|
+ // index + 1,
|
|
|
+ // 0,
|
|
|
+ // fixedNewRow
|
|
|
+ // )
|
|
|
break
|
|
|
|
|
|
case '动态表项目':
|
|
|
// 生成子项序号 (在整个列表中的统一序号)
|
|
|
+ let parentIndex2 =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables.findIndex(
|
|
|
+ (item) => item.rowid == parentRow.rowid
|
|
|
+ )
|
|
|
+ if (
|
|
|
+ !this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
|
|
|
+ .children
|
|
|
+ ) {
|
|
|
+ this.$set(
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables[parentIndex2],
|
|
|
+ 'children',
|
|
|
+ []
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
let dynamicChildOrderNum =
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.length + 1
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
|
|
|
+ .children.length + 1
|
|
|
+ let dynamicValues = { ...parentRow.dynamicValues }
|
|
|
+ for (const key in dynamicValues) {
|
|
|
+ if (key == '序号') {
|
|
|
+ dynamicValues[key] = dynamicChildOrderNum
|
|
|
+ } else {
|
|
|
+ dynamicValues[key] = ''
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const dynamicNewRow = {
|
|
|
- orderText: dynamicChildOrderNum, // 显示用的序号文本
|
|
|
- orderNum: dynamicChildOrderNum, // 发送给后端的序号
|
|
|
+ orderText: dynamicChildOrderNum,
|
|
|
+ orderNum: dynamicChildOrderNum,
|
|
|
tabtype: this.templateType,
|
|
|
surveyTemplateId: this.surveyTemplateId,
|
|
|
versionId: this.versionId,
|
|
|
- dynamicValues: { ...parentRow.dynamicValues },
|
|
|
+ dynamicValues: dynamicValues,
|
|
|
parentid: parentRow.rowid,
|
|
|
isChild: true,
|
|
|
isSubItem: true,
|
|
|
@@ -2374,12 +2429,15 @@
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
-
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(
|
|
|
- index + 1,
|
|
|
- 0,
|
|
|
- dynamicNewRow
|
|
|
- )
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables[
|
|
|
+ parentIndex2
|
|
|
+ ].children.push(dynamicNewRow)
|
|
|
+
|
|
|
+ // this.contentEditForm.dynamicTable.dynamicTables.splice(
|
|
|
+ // index + 1,
|
|
|
+ // 0,
|
|
|
+ // dynamicNewRow
|
|
|
+ // )
|
|
|
break
|
|
|
}
|
|
|
|
|
|
@@ -2447,6 +2505,16 @@
|
|
|
this.contentEditForm.tableHeaders
|
|
|
this.contentEditForm.fixedTable.tableHeaders =
|
|
|
this.contentEditForm.tableHeaders
|
|
|
+ // 表头按照orderNum重新排序
|
|
|
+ this.contentEditForm.tableHeaders.sort(
|
|
|
+ (a, b) => a.orderNum - b.orderNum
|
|
|
+ )
|
|
|
+ this.contentEditForm.dynamicTable.tableHeaders.sort(
|
|
|
+ (a, b) => a.orderNum - b.orderNum
|
|
|
+ )
|
|
|
+ this.contentEditForm.fixedTable.tableHeaders.sort(
|
|
|
+ (a, b) => a.orderNum - b.orderNum
|
|
|
+ )
|
|
|
|
|
|
// 同时获取表头标题信息
|
|
|
listByTemplateIdAndVersion(surveyTemplateId, versionId)
|
|
|
@@ -2763,6 +2831,8 @@
|
|
|
this.contentEditForm.fixedTable.fixedTablesTitle.filter(
|
|
|
(title) => title.rkey !== '序号'
|
|
|
)
|
|
|
+ // 重新排序
|
|
|
+ this.updateTableHeadersOrderNumbers()
|
|
|
handleDelete()
|
|
|
break
|
|
|
|
|
|
@@ -2772,6 +2842,8 @@
|
|
|
return
|
|
|
}
|
|
|
this.contentEditForm.fixedTable.fixedTables.splice(index, 1)
|
|
|
+ // 重新排序
|
|
|
+ this.updateTableHeadersOrderNumbers()
|
|
|
handleDelete() // 执行删除逻辑
|
|
|
break
|
|
|
case '动态表表头':
|
|
|
@@ -2831,17 +2903,17 @@
|
|
|
this.swamTableArr(newDynamicTableData, row, true)
|
|
|
this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
|
|
|
} else {
|
|
|
- const tableHeaders = this.contentEditForm.tableHeaders
|
|
|
- const newTableHeaders = [...tableHeaders]
|
|
|
- this.swamTableArr(newTableHeaders, row, true, true)
|
|
|
- this.contentEditForm.tableHeaders = newTableHeaders
|
|
|
- // if (index > 0) {
|
|
|
- // const temp = this.contentEditForm.tableHeaders[index]
|
|
|
- // this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
- // this.contentEditForm.tableHeaders.splice(index - 1, 0, temp)
|
|
|
- // // 更新表头的序号
|
|
|
- // this.updateTableHeadersOrderNumbers()
|
|
|
- // }
|
|
|
+ // const tableHeaders = this.contentEditForm.tableHeaders
|
|
|
+ // const newTableHeaders = [...tableHeaders]
|
|
|
+ // this.swamTableArr(newTableHeaders, row, true, true)
|
|
|
+ // this.contentEditForm.tableHeaders = newTableHeaders
|
|
|
+ if (index > 0) {
|
|
|
+ const temp = this.contentEditForm.tableHeaders[index]
|
|
|
+ this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
+ this.contentEditForm.tableHeaders.splice(index - 1, 0, temp)
|
|
|
+ // 更新表头的序号
|
|
|
+ this.updateTableHeadersOrderNumbers()
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
// 下降
|
|
|
@@ -2858,17 +2930,17 @@
|
|
|
this.swamTableArr(newDynamicTableData, row, false)
|
|
|
this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
|
|
|
} else {
|
|
|
- const tableHeaders = this.contentEditForm.tableHeaders
|
|
|
- const newTableHeaders = [...tableHeaders]
|
|
|
- this.swamTableArr(newTableHeaders, row, false, true)
|
|
|
- this.contentEditForm.tableHeaders = newTableHeaders
|
|
|
- // if (index < this.contentEditForm.tableHeaders.length - 1) {
|
|
|
- // const temp = this.contentEditForm.tableHeaders[index]
|
|
|
- // this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
- // this.contentEditForm.tableHeaders.splice(index + 1, 0, temp)
|
|
|
- // // 更新表头的序号
|
|
|
- // this.updateTableHeadersOrderNumbers()
|
|
|
- // }
|
|
|
+ // const tableHeaders = this.contentEditForm.tableHeaders
|
|
|
+ // const newTableHeaders = [...tableHeaders]
|
|
|
+ // this.swamTableArr(newTableHeaders, row, false, true)
|
|
|
+ // this.contentEditForm.tableHeaders = newTableHeaders
|
|
|
+ if (index < this.contentEditForm.tableHeaders.length - 1) {
|
|
|
+ const temp = this.contentEditForm.tableHeaders[index]
|
|
|
+ this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
+ this.contentEditForm.tableHeaders.splice(index + 1, 0, temp)
|
|
|
+ // 更新表头的序号
|
|
|
+ this.updateTableHeadersOrderNumbers()
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -2939,6 +3011,38 @@
|
|
|
arr[rowIndex] = swam
|
|
|
arr[swamIndex] = curr
|
|
|
},
|
|
|
+ // 更新表头序号
|
|
|
+ updateTableHeadersOrderNumbers() {
|
|
|
+ if (!this.contentEditForm || !this.contentEditForm.tableHeaders) return
|
|
|
+
|
|
|
+ // 更新主表头的orderNum
|
|
|
+ this.contentEditForm.tableHeaders.forEach((header, index) => {
|
|
|
+ header.orderNum = index + 1
|
|
|
+ })
|
|
|
+
|
|
|
+ // 同步更新固定表和动态表的表头序号
|
|
|
+ if (
|
|
|
+ this.contentEditForm.fixedTable &&
|
|
|
+ this.contentEditForm.fixedTable.tableHeaders
|
|
|
+ ) {
|
|
|
+ this.contentEditForm.fixedTable.tableHeaders.forEach(
|
|
|
+ (header, index) => {
|
|
|
+ header.orderNum = index + 1
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ this.contentEditForm.dynamicTable &&
|
|
|
+ this.contentEditForm.dynamicTable.tableHeaders
|
|
|
+ ) {
|
|
|
+ this.contentEditForm.dynamicTable.tableHeaders.forEach(
|
|
|
+ (header, index) => {
|
|
|
+ header.orderNum = index + 1
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
// 绑定字典变化
|
|
|
handleBindDictChange(row) {
|
|
|
@@ -3363,7 +3467,54 @@
|
|
|
dynamicTables.forEach((row) => {
|
|
|
processNode(row)
|
|
|
})
|
|
|
+ // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
|
|
|
+ // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
|
|
|
+
|
|
|
+ // 计算所有已存在的orderNum中的最大值
|
|
|
+ let maxExistingOrderNum = 0
|
|
|
+
|
|
|
+ // 首先遍历结果数组找出当前最大的orderNum
|
|
|
+ result.forEach((item) => {
|
|
|
+ const orderNum =
|
|
|
+ typeof item.orderNum === 'number'
|
|
|
+ ? item.orderNum
|
|
|
+ : parseInt(item.orderNum, 10) || 0
|
|
|
+ if (orderNum > maxExistingOrderNum) {
|
|
|
+ maxExistingOrderNum = orderNum
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 子节点orderNum从当前最大orderNum + 1开始
|
|
|
+ let childOrderNumCounter = maxExistingOrderNum + 1
|
|
|
|
|
|
+ // 创建一个映射表,用于记录每个子节点对应的新orderNum
|
|
|
+ const childOrderMap = new Map()
|
|
|
+ // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
|
|
|
+ function assignChildOrderNums(nodes) {
|
|
|
+ nodes.forEach((node) => {
|
|
|
+ if (node.isChild || node.isSubItem) {
|
|
|
+ // 为每个子节点分配唯一的orderNum
|
|
|
+ childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
|
|
|
+ }
|
|
|
+ // 递归处理子节点
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ assignChildOrderNums(node.children)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 第二次遍历:更新结果数组中的orderNum
|
|
|
+ assignChildOrderNums(dynamicTables)
|
|
|
+
|
|
|
+ // 应用新的orderNum到结果数组
|
|
|
+ result.forEach((item) => {
|
|
|
+ // 只更新子节点的orderNum
|
|
|
+ if (item.isChild || item.isSubItem) {
|
|
|
+ const newOrderNum =
|
|
|
+ childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
|
|
|
+ if (newOrderNum) {
|
|
|
+ item.orderNum = newOrderNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
return result
|
|
|
},
|
|
|
//保存固定表项目数据
|
|
|
@@ -3570,6 +3721,8 @@
|
|
|
}
|
|
|
|
|
|
const itemList = responseData.value.itemlist
|
|
|
+ const allRows = []
|
|
|
+ const rowMap = new Map()
|
|
|
|
|
|
// 清空现有数据
|
|
|
this.contentEditForm.dynamicTable.dynamicTables = []
|
|
|
@@ -3589,8 +3742,9 @@
|
|
|
parentid: item.parentid || -1,
|
|
|
isChild: isSubItem,
|
|
|
isSubItem: isSubItem,
|
|
|
- rowid: item.rowid || Date.now() + Math.random() + index,
|
|
|
+ rowid: item.rowid || this.generateUUID(),
|
|
|
jsonstr: item.jsonstr || null,
|
|
|
+ children: [], // 添加children数组用于树形结构
|
|
|
}
|
|
|
|
|
|
// 确保orderNum是数字类型
|
|
|
@@ -3600,16 +3754,53 @@
|
|
|
|
|
|
// 初始化dynamicValues并填充实际值
|
|
|
dynamicTitles.forEach((title) => {
|
|
|
- newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
|
|
|
+ // 特殊处理序号字段,需要保存到dynamicValues中供输入框使用
|
|
|
+ if (title.rkey === '序号') {
|
|
|
+ // 优先使用item中的序号值,如果没有则保持为空
|
|
|
+ newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
|
|
|
+ }
|
|
|
+ // 排除其他序号相关字段,避免重复显示
|
|
|
+ else if (title.rkey !== 'ordernum' && title.rkey !== 'orderText') {
|
|
|
+ newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.push(newRow)
|
|
|
+ allRows.push(newRow)
|
|
|
+ // 构建rowMap用于快速查找
|
|
|
+ if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
|
|
|
+ if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
|
|
|
+ })
|
|
|
+
|
|
|
+ // 构建树形结构
|
|
|
+ const treeData = []
|
|
|
+ const parentItems = allRows.filter((item) => !item.isChild)
|
|
|
+
|
|
|
+ // 父级按orderNum正序排序
|
|
|
+ parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
|
|
|
+
|
|
|
+ // 将子项添加到对应的父项的children中
|
|
|
+ allRows.forEach((item) => {
|
|
|
+ if (item.isChild) {
|
|
|
+ const parentId = String(item.parentid)
|
|
|
+ const parent = rowMap.get(parentId)
|
|
|
+ if (parent) {
|
|
|
+ parent.children.push(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
- // 按orderNum排序,确保整个列表按统一序号排序
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.sort((a, b) => {
|
|
|
- return (a.orderNum || 0) - (b.orderNum || 0)
|
|
|
+ // 对子项进行排序
|
|
|
+ parentItems.forEach((parent) => {
|
|
|
+ parent.children.sort(
|
|
|
+ (a, b) =>
|
|
|
+ (Number(a.dynamicValues['序号']) || 0) -
|
|
|
+ (Number(b.dynamicValues['序号']) || 0)
|
|
|
+ )
|
|
|
+ treeData.push(parent)
|
|
|
})
|
|
|
+
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables = treeData
|
|
|
+ console.log('树形结构数据:', treeData)
|
|
|
},
|
|
|
//分割字符串
|
|
|
stringToObjects(str) {
|