|
|
@@ -52,7 +52,6 @@
|
|
|
v-region-permission="{
|
|
|
category: 'costFormManage',
|
|
|
action: 'delete',
|
|
|
- targetData: row,
|
|
|
}"
|
|
|
plain
|
|
|
type="danger"
|
|
|
@@ -500,6 +499,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
+ class="delete-btn"
|
|
|
@click="
|
|
|
handleDeleteHeader(scope.$index, '单记录', scope.row)
|
|
|
"
|
|
|
@@ -767,6 +767,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="scope.row.isDisabled || viewDetail"
|
|
|
+ class="delete-btn"
|
|
|
@click="
|
|
|
handleDeleteHeader(
|
|
|
scope.$index,
|
|
|
@@ -959,6 +960,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
+ class="delete-btn"
|
|
|
@click="
|
|
|
handleDeleteHeader(
|
|
|
scope.$index,
|
|
|
@@ -1216,6 +1218,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="scope.row.isDisabled || viewDetail"
|
|
|
+ class="delete-btn"
|
|
|
@click="
|
|
|
handleDeleteHeader(
|
|
|
scope.$index,
|
|
|
@@ -1388,6 +1391,7 @@
|
|
|
type="text"
|
|
|
size="mini"
|
|
|
:disabled="viewDetail"
|
|
|
+ class="delete-btn"
|
|
|
@click="
|
|
|
handleDeleteHeader(
|
|
|
scope.$index,
|
|
|
@@ -2620,6 +2624,7 @@
|
|
|
tabtype: this.templateType,
|
|
|
surveyTemplateId: this.surveyTemplateId,
|
|
|
versionId: this.versionId,
|
|
|
+ orderNum: this.contentEditForm.tableHeaders.length + 1,
|
|
|
})
|
|
|
break
|
|
|
case '固定表表头':
|
|
|
@@ -2735,7 +2740,6 @@
|
|
|
|
|
|
// 删除表头
|
|
|
handleDeleteHeader(index, type, row) {
|
|
|
- // 提取重复的删除逻辑为内部函数
|
|
|
const handleDelete = () => {
|
|
|
const data = {
|
|
|
deleteheadersList: [row],
|
|
|
@@ -2754,7 +2758,6 @@
|
|
|
})
|
|
|
.finally(() => {})
|
|
|
}
|
|
|
-
|
|
|
switch (type) {
|
|
|
case '固定表表头':
|
|
|
if (this.contentEditForm.fixedTable.tableHeaders.length <= 1) {
|
|
|
@@ -2772,59 +2775,108 @@
|
|
|
this.contentEditForm.fixedTable.fixedTablesTitle.filter(
|
|
|
(title) => title.rkey !== '序号'
|
|
|
)
|
|
|
+ handleDelete()
|
|
|
// 重新排序
|
|
|
this.updateTableHeadersOrderNumbers()
|
|
|
- handleDelete()
|
|
|
break
|
|
|
|
|
|
case '固定表项目':
|
|
|
- // 检查是否是删除子项
|
|
|
- const isChildItem = row.isChild || row.isSubItem || false
|
|
|
-
|
|
|
- if (isChildItem) {
|
|
|
- // 查找父项
|
|
|
- const parentItem =
|
|
|
- this.contentEditForm.fixedTable.fixedTables.find(
|
|
|
- (item) =>
|
|
|
- item.children &&
|
|
|
- item.children.some((child) => child.rowid === row.rowid)
|
|
|
- )
|
|
|
+ this.$confirm(
|
|
|
+ '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
|
|
|
+ '确认删除',
|
|
|
+ {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ // 检查是否是删除子项
|
|
|
+ const isChildItem = row.isChild || row.isSubItem || false
|
|
|
+ console.log('isChildItem', isChildItem)
|
|
|
+ console.log('row', row)
|
|
|
+ if (isChildItem) {
|
|
|
+ // 查找父项
|
|
|
+ const parentItem =
|
|
|
+ this.contentEditForm.fixedTable.fixedTables.find(
|
|
|
+ (item) =>
|
|
|
+ item.children &&
|
|
|
+ item.children.some((child) => child.rowid === row.rowid)
|
|
|
+ )
|
|
|
|
|
|
- if (parentItem && parentItem.children) {
|
|
|
- // 从父项的children数组中删除子项
|
|
|
- const childIndex = parentItem.children.findIndex(
|
|
|
- (child) => child.rowid === row.rowid
|
|
|
- )
|
|
|
- if (childIndex > -1) {
|
|
|
- parentItem.children.splice(childIndex, 1)
|
|
|
-
|
|
|
- // 如果children数组为空,将hasChildren设为false
|
|
|
- if (parentItem.children.length === 0) {
|
|
|
- this.$set(parentItem, 'hasChildren', false)
|
|
|
- } else {
|
|
|
- // 重新计算子项序号
|
|
|
- parentItem.children.forEach((child, idx) => {
|
|
|
- child.orderText = idx + 1
|
|
|
- child.orderNum = idx + 1
|
|
|
- })
|
|
|
+ if (parentItem && parentItem.children) {
|
|
|
+ // 从父项的children数组中删除子项
|
|
|
+ const childIndex = parentItem.children.findIndex(
|
|
|
+ (child) => child.rowid === row.rowid
|
|
|
+ )
|
|
|
+ if (childIndex > -1) {
|
|
|
+ parentItem.children.splice(childIndex, 1)
|
|
|
+
|
|
|
+ // 如果children数组为空,将hasChildren设为false
|
|
|
+ if (parentItem.children.length === 0) {
|
|
|
+ this.$set(parentItem, 'hasChildren', false)
|
|
|
+ } else {
|
|
|
+ // 重新计算子项序号
|
|
|
+ parentItem.children.forEach((child, idx) => {
|
|
|
+ child.orderText = idx + 1
|
|
|
+ child.orderNum = idx + 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保Vue响应式系统检测到变化
|
|
|
+ const children = [...parentItem.children]
|
|
|
+ this.$set(parentItem, 'children', children)
|
|
|
+
|
|
|
+ this.handleSaveContent('固定表项目', 'delete') // 保存数据
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 处理删除父项的情况
|
|
|
+ if (this.contentEditForm.fixedTable.fixedTables.length <= 1) {
|
|
|
+ this.$message.warning('至少保留一个项目')
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- // 确保Vue响应式系统检测到变化
|
|
|
- const children = [...parentItem.children]
|
|
|
- this.$set(parentItem, 'children', children)
|
|
|
+ // 获取要删除的行
|
|
|
+ index =
|
|
|
+ this.contentEditForm.fixedTable.fixedTables.indexOf(row)
|
|
|
+ const rowToDelete =
|
|
|
+ this.contentEditForm.fixedTable.fixedTables[index]
|
|
|
+ // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
|
|
|
+ // 从后往前删除,避免索引偏移
|
|
|
+ const rowsToDelete = []
|
|
|
+
|
|
|
+ // 找出所有需要删除的行(包括父项和子项)
|
|
|
+ for (
|
|
|
+ let i = 0;
|
|
|
+ i < this.contentEditForm.fixedTable.fixedTables.length;
|
|
|
+ i++
|
|
|
+ ) {
|
|
|
+ const currentRow =
|
|
|
+ this.contentEditForm.fixedTable.fixedTables[i]
|
|
|
+ // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
|
|
|
+ if (
|
|
|
+ i === index ||
|
|
|
+ (currentRow.parentid &&
|
|
|
+ (currentRow.parentid === rowToDelete.rowid ||
|
|
|
+ currentRow.parentid === rowToDelete.itemId))
|
|
|
+ ) {
|
|
|
+ rowsToDelete.push(i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从后往前删除,避免索引偏移
|
|
|
+ for (let i = rowsToDelete.length - 1; i >= 0; i--) {
|
|
|
+ this.contentEditForm.fixedTable.fixedTables.splice(
|
|
|
+ rowsToDelete[i],
|
|
|
+ 1
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
- handleDelete() // 执行删除逻辑
|
|
|
+ this.handleSaveContent('固定表项目', 'delete') // 保存数据
|
|
|
}
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 处理删除父项的情况
|
|
|
- if (this.contentEditForm.fixedTable.fixedTables.length <= 1) {
|
|
|
- this.$message.warning('至少保留一个项目')
|
|
|
- return
|
|
|
- }
|
|
|
- this.contentEditForm.fixedTable.fixedTables.splice(index, 1)
|
|
|
- handleDelete() // 执行删除逻辑
|
|
|
- }
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
break
|
|
|
case '动态表表头':
|
|
|
if (this.contentEditForm.dynamicTable.tableHeaders.length <= 1) {
|
|
|
@@ -2841,17 +2893,113 @@
|
|
|
this.contentEditForm.dynamicTable.dynamicTablesTitle.filter(
|
|
|
(title) => title.rkey !== '序号'
|
|
|
)
|
|
|
+ handleDelete()
|
|
|
// 重新排序
|
|
|
this.updateTableHeadersOrderNumbers()
|
|
|
- handleDelete() // 执行删除逻辑
|
|
|
break
|
|
|
case '动态表项目':
|
|
|
if (this.contentEditForm.dynamicTable.dynamicTables.length <= 1) {
|
|
|
this.$message.warning('至少保留一个项目')
|
|
|
return
|
|
|
}
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables.splice(index, 1)
|
|
|
- handleDelete() // 执行删除逻辑
|
|
|
+ this.$confirm(
|
|
|
+ '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
|
|
|
+ '确认删除',
|
|
|
+ {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ // 检查是否是删除子项
|
|
|
+ const isChildItem = row.isChild || row.isSubItem || false
|
|
|
+
|
|
|
+ if (isChildItem) {
|
|
|
+ // 查找父项
|
|
|
+ const parentItem =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables.find(
|
|
|
+ (item) =>
|
|
|
+ item.children &&
|
|
|
+ item.children.some((child) => child.rowid === row.rowid)
|
|
|
+ )
|
|
|
+
|
|
|
+ if (parentItem && parentItem.children) {
|
|
|
+ // 从父项的children数组中删除子项
|
|
|
+ const childIndex = parentItem.children.findIndex(
|
|
|
+ (child) => child.rowid === row.rowid
|
|
|
+ )
|
|
|
+ if (childIndex > -1) {
|
|
|
+ parentItem.children.splice(childIndex, 1)
|
|
|
+
|
|
|
+ // 如果children数组为空,将hasChildren设为false
|
|
|
+ if (parentItem.children.length === 0) {
|
|
|
+ this.$set(parentItem, 'hasChildren', false)
|
|
|
+ } else {
|
|
|
+ // 重新计算子项序号
|
|
|
+ parentItem.children.forEach((child, idx) => {
|
|
|
+ child.orderText = idx + 1
|
|
|
+ child.orderNum = idx + 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保Vue响应式系统检测到变化
|
|
|
+ const children = [...parentItem.children]
|
|
|
+ this.$set(parentItem, 'children', children)
|
|
|
+
|
|
|
+ this.handleSaveContent('动态表项目', 'delete') // 保存数据
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 处理删除父项的情况
|
|
|
+ if (
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables.length <= 1
|
|
|
+ ) {
|
|
|
+ this.$message.warning('至少保留一个项目')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取要删除的行
|
|
|
+ index =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables.indexOf(row)
|
|
|
+ const rowToDelete =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables[index]
|
|
|
+
|
|
|
+ // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
|
|
|
+ // 从后往前删除,避免索引偏移
|
|
|
+ const rowsToDelete = []
|
|
|
+
|
|
|
+ // 找出所有需要删除的行(包括父项和子项)
|
|
|
+ for (
|
|
|
+ let i = 0;
|
|
|
+ i < this.contentEditForm.dynamicTable.dynamicTables.length;
|
|
|
+ i++
|
|
|
+ ) {
|
|
|
+ const currentRow =
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables[i]
|
|
|
+ // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
|
|
|
+ if (
|
|
|
+ i === index ||
|
|
|
+ (currentRow.parentid &&
|
|
|
+ (currentRow.parentid === rowToDelete.rowid ||
|
|
|
+ currentRow.parentid === rowToDelete.itemId))
|
|
|
+ ) {
|
|
|
+ rowsToDelete.push(i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从后往前删除,避免索引偏移
|
|
|
+ for (let i = rowsToDelete.length - 1; i >= 0; i--) {
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables.splice(
|
|
|
+ rowsToDelete[i],
|
|
|
+ 1
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ this.handleSaveContent('动态表项目', 'delete') // 保存数据
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
break
|
|
|
case '单记录':
|
|
|
if (this.contentEditForm.tableHeaders.length <= 1) {
|
|
|
@@ -2859,7 +3007,7 @@
|
|
|
return
|
|
|
}
|
|
|
this.contentEditForm.tableHeaders.splice(index, 1)
|
|
|
- handleDelete() // 执行删除逻辑
|
|
|
+ handleDelete()
|
|
|
break
|
|
|
default:
|
|
|
break
|
|
|
@@ -3127,7 +3275,7 @@
|
|
|
})
|
|
|
},
|
|
|
// 保存内容
|
|
|
- handleSaveContent(type) {
|
|
|
+ handleSaveContent(type, action) {
|
|
|
this.loading = true
|
|
|
let isValid = false
|
|
|
try {
|
|
|
@@ -3138,8 +3286,10 @@
|
|
|
getBatchSaveOrUpdate(data)
|
|
|
.then((res) => {
|
|
|
if (res.code === 200) {
|
|
|
- this.$message.success('保存成功')
|
|
|
- this.contentEditDialogVisible = false
|
|
|
+ if (action != 'delete') {
|
|
|
+ this.$message.success('保存成功')
|
|
|
+ this.contentEditDialogVisible = false
|
|
|
+ }
|
|
|
} else {
|
|
|
this.$message.error(`保存失败:${res.message || '未知错误'}`)
|
|
|
}
|
|
|
@@ -3210,7 +3360,7 @@
|
|
|
this.loading = false
|
|
|
})
|
|
|
} else if (type === '固定表项目') {
|
|
|
- this.saveFixedTableData()
|
|
|
+ this.saveFixedTableData(action)
|
|
|
} else if (type === '动态表表头') {
|
|
|
var data = {
|
|
|
headersList: this.contentEditForm.dynamicTable.tableHeaders,
|
|
|
@@ -3277,7 +3427,7 @@
|
|
|
this.loading = false
|
|
|
})
|
|
|
} else if (type === '动态表项目') {
|
|
|
- this.saveDynamicTableData()
|
|
|
+ this.saveDynamicTableData(action)
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('保存处理异常:', error)
|
|
|
@@ -3697,7 +3847,7 @@
|
|
|
return result
|
|
|
},
|
|
|
//保存固定表项目数据
|
|
|
- saveFixedTableData() {
|
|
|
+ saveFixedTableData(action = '') {
|
|
|
try {
|
|
|
// 获取拆分后的数据
|
|
|
const splitData = this.splitFixedTableDataForSave()
|
|
|
@@ -3711,8 +3861,16 @@
|
|
|
getBatchSaveOrUpdate(saveData)
|
|
|
.then((res) => {
|
|
|
if (res.code === 200) {
|
|
|
- this.$message.success('固定表数据保存成功')
|
|
|
- this.contentEditDialogVisible = false
|
|
|
+ // 如果是删除操作,不显示成功提示且不关闭对话框
|
|
|
+ if (action !== 'delete') {
|
|
|
+ this.$message.success('固定表数据保存成功')
|
|
|
+ this.contentEditDialogVisible = false
|
|
|
+ }
|
|
|
+ // 刷新数据以确保UI更新
|
|
|
+ this.getListBySurveyTemplateIdAndVersion(
|
|
|
+ this.surveyTemplateId,
|
|
|
+ this.versionId
|
|
|
+ )
|
|
|
} else {
|
|
|
this.$message.error(`保存失败:${res.message || '未知错误'}`)
|
|
|
}
|
|
|
@@ -3747,8 +3905,10 @@
|
|
|
getBatchSaveOrUpdate(saveData)
|
|
|
.then((res) => {
|
|
|
if (res.code === 200) {
|
|
|
- this.$message.success('动态表数据保存成功')
|
|
|
- this.contentEditDialogVisible = false
|
|
|
+ if (action != 'delete') {
|
|
|
+ this.$message.success('动态表数据保存成功')
|
|
|
+ this.contentEditDialogVisible = false
|
|
|
+ }
|
|
|
} else {
|
|
|
this.$message.error(`保存失败:${res.message || '未知错误'}`)
|
|
|
}
|