|
|
@@ -451,7 +451,7 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="操作" width="150" fixed="right">
|
|
|
+ <el-table-column label="操作" width="200" fixed="right">
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-actions">
|
|
|
<el-button
|
|
|
@@ -469,7 +469,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
- @click="handleMoveUp(scope.$index)"
|
|
|
+ @click="handleMoveUp(scope.$index, '', scope.row)"
|
|
|
>
|
|
|
上升
|
|
|
</el-button>
|
|
|
@@ -480,7 +480,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
- @click="handleMoveDown(scope.$index)"
|
|
|
+ @click="handleMoveDown(scope.$index, '', scope.row)"
|
|
|
>
|
|
|
下降
|
|
|
</el-button>
|
|
|
@@ -716,7 +716,7 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" width="150" fixed="right">
|
|
|
+ <el-table-column label="操作" width="200" fixed="right">
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-actions">
|
|
|
<el-button
|
|
|
@@ -780,28 +780,15 @@
|
|
|
:data="contentEditForm.fixedTable.fixedTables"
|
|
|
border
|
|
|
style="width: 100%"
|
|
|
+ row-key="rowid"
|
|
|
+ default-expand-all
|
|
|
+ :tree-props="{
|
|
|
+ children: 'children',
|
|
|
+ hasChildren: 'hasChildren',
|
|
|
+ }"
|
|
|
@selection-change="handleSelectionChange"
|
|
|
>
|
|
|
- <el-table-column label="序号" width="100" align="center">
|
|
|
- <template slot-scope="scope">
|
|
|
- <el-input
|
|
|
- :value="
|
|
|
- scope.row.fixedValues
|
|
|
- ? scope.row.fixedValues['序号']
|
|
|
- : ''
|
|
|
- "
|
|
|
- size="small"
|
|
|
- placeholder="数字或中文"
|
|
|
- :disabled="viewDetail"
|
|
|
- @input="handleFixedValueChange(scope.row, '序号', $event)"
|
|
|
- ></el-input>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column
|
|
|
- label="父子节点关系"
|
|
|
- align="center"
|
|
|
- width="120"
|
|
|
- >
|
|
|
+ <el-table-column label="父子节点" align="center" width="100">
|
|
|
<template slot-scope="scope">
|
|
|
<el-tag
|
|
|
v-if="
|
|
|
@@ -830,6 +817,22 @@
|
|
|
<el-tag v-else type="info" size="small">无</el-tag>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+ <el-table-column label="序号" width="100" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-input
|
|
|
+ :value="
|
|
|
+ scope.row.fixedValues
|
|
|
+ ? scope.row.fixedValues['序号']
|
|
|
+ : ''
|
|
|
+ "
|
|
|
+ size="small"
|
|
|
+ placeholder="数字或中文"
|
|
|
+ :disabled="viewDetail"
|
|
|
+ @input="handleFixedValueChange(scope.row, '序号', $event)"
|
|
|
+ ></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
<el-table-column
|
|
|
v-for="(item, index) in contentEditForm.fixedTable
|
|
|
.fixedTableHeaders"
|
|
|
@@ -888,7 +891,12 @@
|
|
|
></el-input>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" align="center" fixed="right">
|
|
|
+ <el-table-column
|
|
|
+ label="操作"
|
|
|
+ align="center"
|
|
|
+ width="220"
|
|
|
+ fixed="right"
|
|
|
+ >
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-actions">
|
|
|
<el-button
|
|
|
@@ -924,7 +932,7 @@
|
|
|
v-if="scope.$index !== 0"
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
- @click="handleMoveUp(scope.$index, '固定表')"
|
|
|
+ @click="handleMoveUp(scope.$index, '固定表', scope.row)"
|
|
|
>
|
|
|
上升
|
|
|
</el-button>
|
|
|
@@ -936,7 +944,9 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
- @click="handleMoveDown(scope.$index, '固定表')"
|
|
|
+ @click="
|
|
|
+ handleMoveDown(scope.$index, '固定表', scope.row)
|
|
|
+ "
|
|
|
>
|
|
|
下降
|
|
|
</el-button>
|
|
|
@@ -1157,7 +1167,7 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" width="150" fixed="right">
|
|
|
+ <el-table-column label="操作" width="200" fixed="right">
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-actions">
|
|
|
<el-button
|
|
|
@@ -1221,30 +1231,15 @@
|
|
|
:data="contentEditForm.dynamicTable.dynamicTables"
|
|
|
border
|
|
|
style="width: 100%"
|
|
|
+ row-key="rowid"
|
|
|
+ default-expand-all
|
|
|
+ :tree-props="{
|
|
|
+ children: 'children',
|
|
|
+ hasChildren: 'hasChildren',
|
|
|
+ }"
|
|
|
@selection-change="handleSelectionChange"
|
|
|
>
|
|
|
- <el-table-column label="序号" width="100" align="center">
|
|
|
- <template slot-scope="scope">
|
|
|
- <el-input
|
|
|
- :value="
|
|
|
- scope.row.dynamicValues
|
|
|
- ? scope.row.dynamicValues['序号']
|
|
|
- : ''
|
|
|
- "
|
|
|
- size="small"
|
|
|
- placeholder="数字或中文"
|
|
|
- :disabled="viewDetail"
|
|
|
- @input="
|
|
|
- handleDynamicValueChange(scope.row, '序号', $event)
|
|
|
- "
|
|
|
- ></el-input>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column
|
|
|
- label="父子节点关系"
|
|
|
- align="center"
|
|
|
- width="120"
|
|
|
- >
|
|
|
+ <el-table-column label="父子节点" align="center" width="100">
|
|
|
<template slot-scope="scope">
|
|
|
<el-tag
|
|
|
v-if="
|
|
|
@@ -1273,6 +1268,24 @@
|
|
|
<el-tag v-else type="info" size="small">无</el-tag>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+ <el-table-column label="序号" width="100" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-input
|
|
|
+ :value="
|
|
|
+ scope.row.dynamicValues
|
|
|
+ ? scope.row.dynamicValues['序号']
|
|
|
+ : ''
|
|
|
+ "
|
|
|
+ size="small"
|
|
|
+ placeholder="数字或中文"
|
|
|
+ :disabled="viewDetail"
|
|
|
+ @input="
|
|
|
+ handleDynamicValueChange(scope.row, '序号', $event)
|
|
|
+ "
|
|
|
+ ></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
<el-table-column
|
|
|
v-for="(item, index) in contentEditForm.dynamicTable
|
|
|
.dynamicTableHeaders"
|
|
|
@@ -1295,7 +1308,12 @@
|
|
|
></el-input>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" align="center" fixed="right">
|
|
|
+ <el-table-column
|
|
|
+ label="操作"
|
|
|
+ width="220"
|
|
|
+ align="center"
|
|
|
+ fixed="right"
|
|
|
+ >
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-actions">
|
|
|
<el-button
|
|
|
@@ -1332,7 +1350,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
- @click="handleMoveUp(scope.$index, '动态表')"
|
|
|
+ @click="handleMoveUp(scope.$index, '动态表', scope.row)"
|
|
|
>
|
|
|
上升
|
|
|
</el-button>
|
|
|
@@ -1344,7 +1362,9 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
- @click="handleMoveDown(scope.$index, '动态表')"
|
|
|
+ @click="
|
|
|
+ handleMoveDown(scope.$index, '动态表', scope.row)
|
|
|
+ "
|
|
|
>
|
|
|
下降
|
|
|
</el-button>
|
|
|
@@ -1774,7 +1794,7 @@
|
|
|
this.surveyTemplateId = row.surveyTemplateId
|
|
|
this.templateType = row.templateType
|
|
|
this.surveyTemplateName = row.surveyTemplateName
|
|
|
- this.contentEditForm.tableName = row.storageTable
|
|
|
+ this.contentEditForm.tableName = row.surveyTemplateName
|
|
|
this.contentEditForm.templateType = row.templateType
|
|
|
this.handleSearch()
|
|
|
this.loadDictTypeList()
|
|
|
@@ -2020,7 +2040,20 @@
|
|
|
}
|
|
|
let _data = []
|
|
|
if (this.radioType == 'current') {
|
|
|
- _data = this.contentEditForm.fixedTable.fixedTables
|
|
|
+ // 使用递归函数扁平化树形结构
|
|
|
+ const flattenTree = (nodes) => {
|
|
|
+ let result = []
|
|
|
+ nodes.forEach((node) => {
|
|
|
+ result.push(node)
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ result = result.concat(flattenTree(node.children))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return result
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扁平化数据并提取cellCode
|
|
|
+ _data = flattenTree(this.contentEditForm.fixedTable.fixedTables)
|
|
|
.filter((item) => item.cellCode)
|
|
|
.map((item) => item.cellCode)
|
|
|
} else if (this.radioType == 'other') {
|
|
|
@@ -2785,116 +2818,126 @@
|
|
|
},
|
|
|
|
|
|
// 上升
|
|
|
- handleMoveUp(index, tableType) {
|
|
|
+ handleMoveUp(index, tableType, row) {
|
|
|
if (tableType === '固定表') {
|
|
|
- if (index > 0) {
|
|
|
- const temp = this.contentEditForm.fixedTable.fixedTables[index]
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(index, 1)
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(
|
|
|
- index - 1,
|
|
|
- 0,
|
|
|
- temp
|
|
|
- )
|
|
|
- }
|
|
|
+ const fixedTableData = this.contentEditForm.fixedTable.fixedTables
|
|
|
+ const newFixedTableData = [...fixedTableData]
|
|
|
+ this.swamTableArr(newFixedTableData, row, true)
|
|
|
+ this.contentEditForm.fixedTable.fixedTables = newFixedTableData
|
|
|
} else if (tableType === '动态表') {
|
|
|
- if (index > 0) {
|
|
|
- const temp = this.contentEditForm.dynamicTable.dynamicTables[index]
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(index, 1)
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(
|
|
|
- index - 1,
|
|
|
- 0,
|
|
|
- temp
|
|
|
- )
|
|
|
- }
|
|
|
+ const dynamicTableData =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables
|
|
|
+ const newDynamicTableData = [...dynamicTableData]
|
|
|
+ this.swamTableArr(newDynamicTableData, row, true)
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
|
|
|
} else {
|
|
|
- if (index > 0) {
|
|
|
- const temp = this.contentEditForm.tableHeaders[index]
|
|
|
- this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
- this.contentEditForm.tableHeaders.splice(index - 1, 0, temp)
|
|
|
- }
|
|
|
+ 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()
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 下降
|
|
|
+ handleMoveDown(index, tableType, row) {
|
|
|
+ if (tableType === '固定表') {
|
|
|
+ const fixedTableData = this.contentEditForm.fixedTable.fixedTables
|
|
|
+ const newFixedTableData = [...fixedTableData]
|
|
|
+ this.swamTableArr(newFixedTableData, row, false)
|
|
|
+ this.contentEditForm.fixedTable.fixedTables = newFixedTableData
|
|
|
+ } else if (tableType === '动态表') {
|
|
|
+ const dynamicTableData =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables
|
|
|
+ const newDynamicTableData = [...dynamicTableData]
|
|
|
+ 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()
|
|
|
+ // }
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 启动/停用状态
|
|
|
- handleStatus(row) {
|
|
|
- const action = row.status === '0' ? '停用' : '启用'
|
|
|
- if (row.status === '0') {
|
|
|
- this.$confirm(`确认要停用该数据吗?`, '操作确认', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- row.status = '-1'
|
|
|
- putSurveyFdTemplatePublishVersion(row).then((res) => {
|
|
|
- if (res.code === 200) {
|
|
|
- this.$message.success(`${action}成功`)
|
|
|
- this.handleSearch()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- this.$message({
|
|
|
- type: 'info',
|
|
|
- message: '已取消操作',
|
|
|
- })
|
|
|
- })
|
|
|
- } else if (row.status === '-1') {
|
|
|
- this.$confirm(`确认要启用该数据吗?`, '操作确认', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- row.status = '0'
|
|
|
- putSurveyFdTemplatePublishVersion(row).then((res) => {
|
|
|
- if (res.code === 200) {
|
|
|
- this.$message.success(`停用成功`)
|
|
|
- this.handleSearch()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- this.$message({
|
|
|
- type: 'info',
|
|
|
- message: '已取消操作',
|
|
|
- })
|
|
|
- })
|
|
|
+ swamTableArr(arr, row, asc, isHeader) {
|
|
|
+ const isChild = row.isChild || row.isSubItem || false
|
|
|
+ if (isChild) {
|
|
|
+ // 子节点处理逻辑后续实现 parentid rowid
|
|
|
+ let child = arr.find((item) => item.rowid === row.parentid)
|
|
|
+ // const rowIndex = arr.indexOf(row);
|
|
|
+ // newFixedTableData[rowIndex]
|
|
|
+ this.doSwamTableArr(child.children, row, asc, isHeader)
|
|
|
+ } else {
|
|
|
+ // 创建数组副本以确保Vue能检测到变化
|
|
|
+ // 直接替换整个数组,确保Vue能检测到变化
|
|
|
+ this.doSwamTableArr(arr, row, asc, isHeader)
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 下降
|
|
|
- handleMoveDown(index, tableType) {
|
|
|
- if (tableType === '固定表') {
|
|
|
- if (index < this.contentEditForm.fixedTable.fixedTables.length - 1) {
|
|
|
- const temp = this.contentEditForm.fixedTable.fixedTables[index]
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(index, 1)
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(
|
|
|
- index + 1,
|
|
|
- 0,
|
|
|
- temp
|
|
|
- )
|
|
|
- }
|
|
|
- } else if (tableType === '动态表') {
|
|
|
- if (
|
|
|
- index <
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.length - 1
|
|
|
- ) {
|
|
|
- const temp = this.contentEditForm.dynamicTable.dynamicTables[index]
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(index, 1)
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(
|
|
|
- index + 1,
|
|
|
- 0,
|
|
|
- temp
|
|
|
- )
|
|
|
+ doSwamTableArr(arr, row, asc, isHeader) {
|
|
|
+ const rowIndex = arr.indexOf(row)
|
|
|
+ let swamIndex = 0
|
|
|
+ if (asc) {
|
|
|
+ // 正序
|
|
|
+ if (rowIndex < 1) {
|
|
|
+ return
|
|
|
}
|
|
|
+ swamIndex = rowIndex - 1
|
|
|
} else {
|
|
|
- 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)
|
|
|
+ // 倒序
|
|
|
+ if (rowIndex >= arr.length - 1) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ swamIndex = rowIndex + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ const curr = arr[rowIndex]
|
|
|
+ const swam = arr[swamIndex]
|
|
|
+
|
|
|
+ // 交换orderNum
|
|
|
+ const tempOrderNum = curr.orderNum
|
|
|
+ curr.orderNum = swam.orderNum
|
|
|
+ swam.orderNum = tempOrderNum
|
|
|
+
|
|
|
+ // 刷新序号 row.isChild&&
|
|
|
+ if (!isHeader) {
|
|
|
+ // 获取当前项的序号值
|
|
|
+ let currIndex = curr.fixedValues
|
|
|
+ ? curr.fixedValues['序号']
|
|
|
+ : curr.dynamicValues['序号']
|
|
|
+ // 获取交换项的序号值
|
|
|
+ let swamIndex = swam.fixedValues
|
|
|
+ ? swam.fixedValues['序号']
|
|
|
+ : swam.dynamicValues['序号']
|
|
|
+ // 先保存交换项的值,再进行赋值,避免值被覆盖
|
|
|
+ if (curr.fixedValues) {
|
|
|
+ curr.fixedValues['序号'] = swamIndex
|
|
|
+ } else {
|
|
|
+ curr.dynamicValues['序号'] = swamIndex
|
|
|
+ }
|
|
|
+ if (swam.fixedValues) {
|
|
|
+ swam.fixedValues['序号'] = currIndex
|
|
|
+ } else {
|
|
|
+ swam.dynamicValues['序号'] = currIndex
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 交换数组中的位置
|
|
|
+ arr[rowIndex] = swam
|
|
|
+ arr[swamIndex] = curr
|
|
|
},
|
|
|
|
|
|
// 绑定字典变化
|
|
|
@@ -3094,10 +3137,21 @@
|
|
|
// 结果数组
|
|
|
const result = []
|
|
|
|
|
|
- // 遍历每一行数据
|
|
|
- fixedTables.forEach((row, rowIndex) => {
|
|
|
+ // 递归处理树形结构中的所有节点
|
|
|
+ const processNode = (node, parentRowIndex = 0) => {
|
|
|
+ // 确保node和fixedValues存在
|
|
|
+ if (!node) {
|
|
|
+ console.warn('遇到空节点,跳过处理')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保fixedValues属性存在,如果不存在则初始化为空对象
|
|
|
+ if (!node.fixedValues) {
|
|
|
+ node.fixedValues = {}
|
|
|
+ }
|
|
|
+
|
|
|
// 为每个固定列创建一条记录
|
|
|
- fixedTitles.forEach((title, colIndex) => {
|
|
|
+ fixedTitles.forEach((title) => {
|
|
|
// 找到对应的表头信息
|
|
|
const correspondingHeader = fixedHeaders.find(
|
|
|
(header) => header.fieldName === title.rkey
|
|
|
@@ -3105,41 +3159,35 @@
|
|
|
|
|
|
const newItem = {
|
|
|
rkey: title.rkey,
|
|
|
- rvalue: row.fixedValues ? row.fixedValues[title.rkey] || '' : '',
|
|
|
- surveyTemplateId: row.surveyTemplateId,
|
|
|
- versionId: row.versionId,
|
|
|
- tabtype: row.tabtype,
|
|
|
- rowIndex: rowIndex,
|
|
|
+ rvalue: node.fixedValues[title.rkey] || '',
|
|
|
+ surveyTemplateId: node.surveyTemplateId || this.surveyTemplateId,
|
|
|
+ versionId: node.versionId || this.versionId,
|
|
|
+ tabtype: node.tabtype || this.templateType,
|
|
|
// 添加 headersId 字段(表头的id)
|
|
|
headersId: correspondingHeader ? correspondingHeader.id : null,
|
|
|
// 添加记录的id(itemlist中每条记录的id)
|
|
|
- id: row.itemId || null,
|
|
|
+ id: node.itemId || null,
|
|
|
// 添加父子关系字段
|
|
|
- parentid: row.parentid || -1, // 父项ID,默认为-1表示无父项
|
|
|
- isChild: row.isChild || false, // 是否为子项
|
|
|
+ parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
|
|
|
+ isChild: node.isChild || false, // 是否为子项
|
|
|
// 添加 rowid 字段
|
|
|
- rowid: row.rowid || null,
|
|
|
+ rowid: node.rowid || null,
|
|
|
// 添加计算公式相关字段
|
|
|
- calculationFormula: row.calculationFormula || null,
|
|
|
- jsonstr: row.jsonstr || null,
|
|
|
- }
|
|
|
-
|
|
|
- // 只有非子项才添加序号
|
|
|
- if (!row.isSubItem && row.orderNum) {
|
|
|
- newItem.orderNum =
|
|
|
- typeof row.orderNum === 'number'
|
|
|
- ? row.orderNum
|
|
|
- : parseInt(row.orderNum, 10) || 0
|
|
|
+ calculationFormula: node.calculationFormula || null,
|
|
|
+ jsonstr: node.jsonstr || null,
|
|
|
+ orderNum:
|
|
|
+ typeof node.orderNum === 'number'
|
|
|
+ ? node.orderNum
|
|
|
+ : parseInt(node.orderNum, 10) || 0,
|
|
|
}
|
|
|
-
|
|
|
// 添加其他固定表特有的字段
|
|
|
- if (!row.isSubItem) {
|
|
|
- newItem.cellCode = row.cellCode || ''
|
|
|
- newItem.unit = row.unit || ''
|
|
|
+ if (!node.isSubItem) {
|
|
|
+ newItem.cellCode = node.cellCode || ''
|
|
|
+ newItem.unit = node.unit || ''
|
|
|
}
|
|
|
|
|
|
// 添加其他可能需要的字段,但排除特定字段
|
|
|
- Object.keys(row).forEach((key) => {
|
|
|
+ Object.keys(node).forEach((key) => {
|
|
|
if (
|
|
|
!(key in newItem) &&
|
|
|
key !== 'fixedValues' &&
|
|
|
@@ -3150,14 +3198,77 @@
|
|
|
key !== 'isSubItem' &&
|
|
|
key !== 'rowid' &&
|
|
|
key !== 'jsonstr' &&
|
|
|
- key !== 'calculationFormula'
|
|
|
+ key !== 'calculationFormula' &&
|
|
|
+ key !== 'children' // 排除children字段
|
|
|
) {
|
|
|
- newItem[key] = row[key]
|
|
|
+ newItem[key] = node[key]
|
|
|
}
|
|
|
})
|
|
|
|
|
|
result.push(newItem)
|
|
|
})
|
|
|
+
|
|
|
+ // 递归处理子节点
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ node.children.forEach((childNode) => {
|
|
|
+ processNode(childNode)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有顶级节点
|
|
|
+ fixedTables.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(fixedTables)
|
|
|
+
|
|
|
+ // 应用新的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
|
|
|
@@ -3174,10 +3285,21 @@
|
|
|
// 结果数组
|
|
|
const result = []
|
|
|
|
|
|
- // 遍历每一行数据
|
|
|
- dynamicTables.forEach((row, rowIndex) => {
|
|
|
+ // 递归处理树形结构中的所有节点
|
|
|
+ const processNode = (node) => {
|
|
|
+ // 确保node和dynamicValues存在
|
|
|
+ if (!node) {
|
|
|
+ console.warn('遇到空节点,跳过处理')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保dynamicValues属性存在,如果不存在则初始化为空对象
|
|
|
+ if (!node.dynamicValues) {
|
|
|
+ node.dynamicValues = {}
|
|
|
+ }
|
|
|
+
|
|
|
// 为每个固定列创建一条记录
|
|
|
- dynamicTitles.forEach((title, colIndex) => {
|
|
|
+ dynamicTitles.forEach((title) => {
|
|
|
// 找到对应的表头信息
|
|
|
const correspondingHeader = dynamicHeaders.find(
|
|
|
(header) => header.fieldName === title.rkey
|
|
|
@@ -3185,37 +3307,30 @@
|
|
|
|
|
|
const newItem = {
|
|
|
rkey: title.rkey,
|
|
|
- rvalue: row.dynamicValues
|
|
|
- ? row.dynamicValues[title.rkey] || ''
|
|
|
- : '',
|
|
|
- surveyTemplateId: row.surveyTemplateId,
|
|
|
- versionId: row.versionId,
|
|
|
- tabtype: row.tabtype,
|
|
|
- rowIndex: rowIndex,
|
|
|
+ rvalue: node.dynamicValues[title.rkey] || '',
|
|
|
+ surveyTemplateId: node.surveyTemplateId,
|
|
|
+ versionId: node.versionId,
|
|
|
+ tabtype: node.tabtype,
|
|
|
// 添加 headersId 字段(表头的id)
|
|
|
headersId: correspondingHeader ? correspondingHeader.id : null,
|
|
|
// 添加记录的id(itemlist中每条记录的id)
|
|
|
- id: row.itemId || null,
|
|
|
+ id: node.itemId || null,
|
|
|
// 添加父子关系字段
|
|
|
- parentid: row.parentid || -1, // 父项ID,默认为-1表示无父项
|
|
|
- isChild: row.isChild || false, // 是否为子项
|
|
|
+ parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
|
|
|
+ isChild: node.isChild || false, // 是否为子项
|
|
|
// 添加 rowid 字段
|
|
|
- rowid: row.rowid || null,
|
|
|
+ rowid: node.rowid || null,
|
|
|
// 添加计算公式相关字段
|
|
|
- calculationFormula: row.calculationFormula || null,
|
|
|
- jsonstr: row.jsonstr || null,
|
|
|
- }
|
|
|
-
|
|
|
- // 只有非子项才添加序号
|
|
|
- if (!row.isSubItem && row.orderNum) {
|
|
|
- newItem.orderNum =
|
|
|
- typeof row.orderNum === 'number'
|
|
|
- ? row.orderNum
|
|
|
- : parseInt(row.orderNum, 10) || 0
|
|
|
+ calculationFormula: node.calculationFormula || null,
|
|
|
+ jsonstr: node.jsonstr || null,
|
|
|
+ orderNum:
|
|
|
+ typeof node.orderNum === 'number'
|
|
|
+ ? node.orderNum
|
|
|
+ : parseInt(node.orderNum, 10) || 0,
|
|
|
}
|
|
|
|
|
|
// 添加其他可能需要的字段,但排除特定字段
|
|
|
- Object.keys(row).forEach((key) => {
|
|
|
+ Object.keys(node).forEach((key) => {
|
|
|
if (
|
|
|
!(key in newItem) &&
|
|
|
key !== 'dynamicValues' &&
|
|
|
@@ -3226,14 +3341,27 @@
|
|
|
key !== 'isSubItem' &&
|
|
|
key !== 'rowid' &&
|
|
|
key !== 'jsonstr' &&
|
|
|
- key !== 'calculationFormula'
|
|
|
+ key !== 'calculationFormula' &&
|
|
|
+ key !== 'children' // 排除children字段
|
|
|
) {
|
|
|
- newItem[key] = row[key]
|
|
|
+ newItem[key] = node[key]
|
|
|
}
|
|
|
})
|
|
|
|
|
|
result.push(newItem)
|
|
|
})
|
|
|
+
|
|
|
+ // 递归处理子节点
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ node.children.forEach((childNode) => {
|
|
|
+ processNode(childNode)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有顶级节点
|
|
|
+ dynamicTables.forEach((row) => {
|
|
|
+ processNode(row)
|
|
|
})
|
|
|
|
|
|
return result
|
|
|
@@ -3338,6 +3466,8 @@
|
|
|
}
|
|
|
|
|
|
const itemList = responseData.value.itemlist
|
|
|
+ const allRows = []
|
|
|
+ const rowMap = new Map()
|
|
|
|
|
|
// 清空现有数据
|
|
|
this.contentEditForm.fixedTable.fixedTables = []
|
|
|
@@ -3361,8 +3491,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是数字类型
|
|
|
@@ -3375,13 +3506,41 @@
|
|
|
newRow.fixedValues[title.rkey] = item[title.rkey] || ''
|
|
|
})
|
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables.push(newRow)
|
|
|
+ allRows.push(newRow)
|
|
|
+ // 构建rowMap用于快速查找
|
|
|
+ if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
|
|
|
+ if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
|
|
|
})
|
|
|
|
|
|
- // 按orderNum排序,确保整个列表按统一序号排序
|
|
|
- this.contentEditForm.fixedTable.fixedTables.sort((a, b) => {
|
|
|
- return (a.orderNum || 0) - (b.orderNum || 0)
|
|
|
+ // 构建树形结构
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 对子项进行排序
|
|
|
+ parentItems.forEach((parent) => {
|
|
|
+ parent.children.sort(
|
|
|
+ (a, b) =>
|
|
|
+ (a.fixedValues['序号'] || 0) - (b.fixedValues['序号'] || 0)
|
|
|
+ )
|
|
|
+ treeData.push(parent)
|
|
|
})
|
|
|
+
|
|
|
+ this.contentEditForm.fixedTable.fixedTables = treeData
|
|
|
+ console.log('树形结构数据:', treeData)
|
|
|
},
|
|
|
/**
|
|
|
* 解析并回显动态表项目数据
|