|
@@ -5,7 +5,7 @@
|
|
|
ref="auditForm"
|
|
ref="auditForm"
|
|
|
:model="auditForm"
|
|
:model="auditForm"
|
|
|
:rules="rules"
|
|
:rules="rules"
|
|
|
- :disabled="auditForm.surveyTemplateId !== ''"
|
|
|
|
|
|
|
+ :disabled="hasTableData"
|
|
|
>
|
|
>
|
|
|
<el-row :gutter="20">
|
|
<el-row :gutter="20">
|
|
|
<el-col :span="6">
|
|
<el-col :span="6">
|
|
@@ -65,7 +65,7 @@
|
|
|
</el-row>
|
|
</el-row>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
<el-button
|
|
<el-button
|
|
|
- v-if="!hasUploadData"
|
|
|
|
|
|
|
+ v-if="!hasTableData"
|
|
|
type="primary"
|
|
type="primary"
|
|
|
size="small"
|
|
size="small"
|
|
|
:loading="loading"
|
|
:loading="loading"
|
|
@@ -398,6 +398,11 @@
|
|
|
: []
|
|
: []
|
|
|
return cols.filter((c) => c && c.showVisible !== '0')
|
|
return cols.filter((c) => c && c.showVisible !== '0')
|
|
|
},
|
|
},
|
|
|
|
|
+ hasTableData() {
|
|
|
|
|
+ return (
|
|
|
|
|
+ Array.isArray(this.costAuditData) && this.costAuditData.length > 0
|
|
|
|
|
+ )
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
|
// 直接监听最终的模板ID:一旦有值(或变更),拉取最新版本数据回显
|
|
// 直接监听最终的模板ID:一旦有值(或变更),拉取最新版本数据回显
|
|
@@ -1872,47 +1877,29 @@
|
|
|
},
|
|
},
|
|
|
handleDeleteItem(row) {
|
|
handleDeleteItem(row) {
|
|
|
// 显示确认对话框
|
|
// 显示确认对话框
|
|
|
- this.$confirm(
|
|
|
|
|
- '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
|
|
|
|
|
- '确认删除',
|
|
|
|
|
- {
|
|
|
|
|
- confirmButtonText: '确定',
|
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ this.$confirm('确定要删除此行数据吗?', '确认删除', {
|
|
|
|
|
+ confirmButtonText: '确定',
|
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ })
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
- // 获取要删除的行ID
|
|
|
|
|
- const rowId = row.rowId || row.id
|
|
|
|
|
- // 收集要删除的行索引
|
|
|
|
|
- const indicesToDelete = []
|
|
|
|
|
-
|
|
|
|
|
- // 查找要删除的行及其子项
|
|
|
|
|
- for (let i = 0; i < this.costAuditData.length; i++) {
|
|
|
|
|
- const item = this.costAuditData[i]
|
|
|
|
|
- // 如果是要删除的行本身,或者是其子项
|
|
|
|
|
- if (
|
|
|
|
|
- item.rowId === rowId ||
|
|
|
|
|
- item.id === rowId ||
|
|
|
|
|
- (item.parentId !== '-1' &&
|
|
|
|
|
- (item.parentId === rowId || item.parentId === row.id))
|
|
|
|
|
- ) {
|
|
|
|
|
- indicesToDelete.push(i)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 仅删除当前这一行
|
|
|
|
|
+ const targetId =
|
|
|
|
|
+ (row && (row.rowid || row.rowId || row.id || row.itemId)) || null
|
|
|
|
|
+ const index = this.costAuditData.findIndex((it) => {
|
|
|
|
|
+ if (it === row) return true
|
|
|
|
|
+ const itId = it && (it.rowid || it.rowId || it.id || it.itemId)
|
|
|
|
|
+ return targetId != null && itId === targetId
|
|
|
|
|
+ })
|
|
|
|
|
+ if (index !== -1) {
|
|
|
|
|
+ this.costAuditData.splice(index, 1)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 从后往前删除,避免索引偏移
|
|
|
|
|
- indicesToDelete
|
|
|
|
|
- .sort((a, b) => b - a)
|
|
|
|
|
- .forEach((index) => {
|
|
|
|
|
- this.costAuditData.splice(index, 1)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
// 更新剩余行的orderNum
|
|
// 更新剩余行的orderNum
|
|
|
this.updateOrderNumbersAfterDelete(row)
|
|
this.updateOrderNumbersAfterDelete(row)
|
|
|
|
|
|
|
|
// 删除行后调用保存模板方法
|
|
// 删除行后调用保存模板方法
|
|
|
- this.handleSaveTemplate('delete')
|
|
|
|
|
|
|
+ // this.handleSaveTemplate('delete')
|
|
|
|
|
|
|
|
this.$message.success('行删除成功')
|
|
this.$message.success('行删除成功')
|
|
|
})
|
|
})
|
|
@@ -1923,18 +1910,19 @@
|
|
|
},
|
|
},
|
|
|
// 删除行后更新orderNum的方法
|
|
// 删除行后更新orderNum的方法
|
|
|
updateOrderNumbersAfterDelete(deletedRow) {
|
|
updateOrderNumbersAfterDelete(deletedRow) {
|
|
|
- const deletedOrderNum = deletedRow.orderNum
|
|
|
|
|
- const deletedParentId = deletedRow.parentId || '-1'
|
|
|
|
|
|
|
+ const deletedOrderNum = deletedRow && deletedRow.orderNum
|
|
|
|
|
+ const deletedParentId =
|
|
|
|
|
+ (deletedRow && (deletedRow.parentId || deletedRow.parentid)) || '-1'
|
|
|
|
|
|
|
|
- // 遍历所有行,更新orderNum
|
|
|
|
|
|
|
+ // 遍历所有行,更新orderNum(同父级范围内顺延)
|
|
|
this.costAuditData.forEach((item) => {
|
|
this.costAuditData.forEach((item) => {
|
|
|
- // 如果是相同父项的子项,或者都是父项(parentId为'-1'),且orderNum大于删除行的orderNum
|
|
|
|
|
|
|
+ const parentId = item.parentId || item.parentid || '-1'
|
|
|
if (
|
|
if (
|
|
|
- (item.parentId === deletedParentId ||
|
|
|
|
|
- (item.parentId === '-1' && deletedParentId === '-1')) &&
|
|
|
|
|
|
|
+ parentId === deletedParentId &&
|
|
|
|
|
+ typeof item.orderNum !== 'undefined' &&
|
|
|
|
|
+ typeof deletedOrderNum !== 'undefined' &&
|
|
|
item.orderNum > deletedOrderNum
|
|
item.orderNum > deletedOrderNum
|
|
|
) {
|
|
) {
|
|
|
- // 将orderNum减1,保持连续性
|
|
|
|
|
item.orderNum -= 1
|
|
item.orderNum -= 1
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -2035,7 +2023,17 @@
|
|
|
if (ch === '-' || ch === '+') {
|
|
if (ch === '-' || ch === '+') {
|
|
|
const prop = cfg && cfg.prop
|
|
const prop = cfg && cfg.prop
|
|
|
const val = String((prop && row[prop]) || '')
|
|
const val = String((prop && row[prop]) || '')
|
|
|
- if (val.length > 0) e.preventDefault()
|
|
|
|
|
|
|
+ const el = e.target
|
|
|
|
|
+ // 允许在开头输入正负号:
|
|
|
|
|
+ // 1) 若当前值为空,允许
|
|
|
|
|
+ // 2) 若光标在起始位置且当前无前导正负号,允许
|
|
|
|
|
+ if (
|
|
|
|
|
+ val.length === 0 ||
|
|
|
|
|
+ (el && el.selectionStart === 0 && !/^[-+]/.test(val))
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ e.preventDefault()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
e.preventDefault()
|
|
e.preventDefault()
|