|
|
@@ -142,7 +142,7 @@
|
|
|
:data="treeList"
|
|
|
:render-after-expand="false"
|
|
|
:props="defaultProps"
|
|
|
- @change="getItemList(scope.row,true,true)"
|
|
|
+ @change="getItemList(scope.row, true, shouldAutoFill(scope.row))"
|
|
|
filterable
|
|
|
/>
|
|
|
<span v-else>{{
|
|
|
@@ -406,7 +406,8 @@ const handleAdd = () => {
|
|
|
minimumDays: '',
|
|
|
isSameDayRefund: '',
|
|
|
amount: undefined,
|
|
|
- itemList: []
|
|
|
+ itemList: [],
|
|
|
+ __isNew: true
|
|
|
})
|
|
|
}
|
|
|
const handleDelete = (index: number) => {
|
|
|
@@ -441,8 +442,26 @@ const getTreeData = async () => {
|
|
|
|
|
|
// 项目名称
|
|
|
// const itemList = ref<{chargeName: string, id: string}>([])
|
|
|
-const getItemList = async (row, flag = true,flag2=false) => {
|
|
|
- if(flag){
|
|
|
+const shouldAutoFill = (row) => {
|
|
|
+ // 只有新增行才参与自动补齐/自动回填
|
|
|
+ if (!row?.__isNew) return false
|
|
|
+ if (!row?.categoryId) return false
|
|
|
+
|
|
|
+ // 如果该分类存在“缺失的子项”,就允许自动补齐(用于你删除某个子项后再新增补回)
|
|
|
+ const sameCategoryRows = dataForm.value.items.filter(
|
|
|
+ (item) => item !== row && item.categoryId === row.categoryId
|
|
|
+ )
|
|
|
+ const existingItemIdSet = new Set(sameCategoryRows.map((item) => item.itemId).filter(Boolean))
|
|
|
+ if (!Array.isArray(row.itemList) || row.itemList.length === 0) return true
|
|
|
+ const missing = row.itemList.find((it) => it?.id && !existingItemIdSet.has(it.id))
|
|
|
+ return Boolean(missing)
|
|
|
+}
|
|
|
+
|
|
|
+// 项目名称
|
|
|
+// const itemList = ref<{chargeName: string, id: string}>([])
|
|
|
+const getItemList = async (row, flag = true, flag2 = false) => {
|
|
|
+ const prevCategoryId = row.categoryId
|
|
|
+ if (flag) {
|
|
|
row.itemId = ''
|
|
|
}
|
|
|
try {
|
|
|
@@ -453,32 +472,54 @@ const getItemList = async (row, flag = true,flag2=false) => {
|
|
|
})
|
|
|
row.itemList = data.list
|
|
|
|
|
|
- // 如果需要自动添加子项
|
|
|
- if (flag2 && row.itemList && row.itemList.length > 0) {
|
|
|
- // 清除当前分类下的其他项(除了当前行)
|
|
|
- const currentCategoryItems = dataForm.value.items.filter(
|
|
|
- item => item.categoryId === row.categoryId && item !== row
|
|
|
+ // 如果该类型下的所有项目都已经在表格中存在,则禁止再次新增该类型
|
|
|
+ if (row?.__isNew && Array.isArray(row.itemList) && row.itemList.length > 0) {
|
|
|
+ const sameCategoryRows = dataForm.value.items.filter(
|
|
|
+ (item) => item !== row && item.categoryId === row.categoryId
|
|
|
+ )
|
|
|
+ const existingItemIdSet = new Set(sameCategoryRows.map((item) => item.itemId).filter(Boolean))
|
|
|
+ const allExist = row.itemList.every((it) => it?.id && existingItemIdSet.has(it.id))
|
|
|
+ if (allExist) {
|
|
|
+ message.warning('该退费类型下的所有项目已存在,请选择其他类型')
|
|
|
+ row.categoryId = ''
|
|
|
+ row.itemId = ''
|
|
|
+ row.itemList = []
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果需要自动添加子项(仅补齐缺失,不删除/不重置已有行,避免误清空 customAmount)
|
|
|
+ if (flag2 && Array.isArray(row.itemList) && row.itemList.length > 0) {
|
|
|
+ // 新增行在成功触发自动补齐/回填后,避免后续再次触发
|
|
|
+ if (row?.__isNew) {
|
|
|
+ row.__isNew = false
|
|
|
+ }
|
|
|
+ const sameCategoryRows = dataForm.value.items.filter(item => item.categoryId === row.categoryId)
|
|
|
+ const existingItemIdSet = new Set(
|
|
|
+ sameCategoryRows.map(item => item.itemId).filter(Boolean)
|
|
|
)
|
|
|
|
|
|
- // 删除这些项
|
|
|
- currentCategoryItems.forEach(item => {
|
|
|
- const index = dataForm.value.items.indexOf(item)
|
|
|
- if (index > -1) {
|
|
|
- dataForm.value.items.splice(index, 1)
|
|
|
+ // 当前行如果还没选子项:优先回填“缺失的子项”
|
|
|
+ if (!row.itemId) {
|
|
|
+ const missing = row.itemList.find((it) => it?.id && !existingItemIdSet.has(it.id))
|
|
|
+ row.itemId = missing?.id || row.itemList[0]?.id || ''
|
|
|
+ if (row.itemId) {
|
|
|
+ existingItemIdSet.add(row.itemId)
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
|
|
|
- // 为当前行设置第一个子项
|
|
|
- row.itemId = row.itemList[0]?.id || ''
|
|
|
+ // 把该分类下剩余缺失的子项补充为新行(只新增,不动旧行)
|
|
|
+ for (let i = 0; i < row.itemList.length; i++) {
|
|
|
+ const id = row.itemList[i]?.id
|
|
|
+ if (!id || existingItemIdSet.has(id)) continue
|
|
|
+ existingItemIdSet.add(id)
|
|
|
|
|
|
- // 添加剩余的子项作为新行
|
|
|
- for (let i = 1; i < row.itemList.length; i++) {
|
|
|
dataForm.value.items.push({
|
|
|
categoryId: row.categoryId,
|
|
|
- itemId: row.itemList[i].id,
|
|
|
+ itemId: id,
|
|
|
type: 3,
|
|
|
- isCustom: 0, //是否自定义
|
|
|
- customAmount: '', //自定义金额
|
|
|
+ isCustom: 0, // 是否自定义
|
|
|
+ customAmount: '', // 自定义金额
|
|
|
maximumDays: '',
|
|
|
minimumDays: '',
|
|
|
isSameDayRefund: '',
|
|
|
@@ -487,9 +528,7 @@ const getItemList = async (row, flag = true,flag2=false) => {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} finally {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|