|
|
|
@ -11,7 +11,7 @@ |
|
|
|
@refresh-change="refreshChange" @on-load="onLoad" @row-change="handleRowChange"> |
|
|
|
@refresh-change="refreshChange" @on-load="onLoad" @row-change="handleRowChange"> |
|
|
|
</avue-crud> |
|
|
|
</avue-crud> |
|
|
|
<div slot="footer" class="dialog-footer"> |
|
|
|
<div slot="footer" class="dialog-footer"> |
|
|
|
<el-button @click="handleCancel">取消</el-button> |
|
|
|
<el-button @click="handleCloseDetail">取消</el-button> |
|
|
|
<el-button type="primary" @click="handleConfirm">确定</el-button> |
|
|
|
<el-button type="primary" @click="handleConfirm">确定</el-button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</el-dialog> |
|
|
|
</el-dialog> |
|
|
|
@ -31,7 +31,7 @@ export default { |
|
|
|
default: '' |
|
|
|
default: '' |
|
|
|
}, |
|
|
|
}, |
|
|
|
departmentId: { |
|
|
|
departmentId: { |
|
|
|
type: [String, Number], |
|
|
|
type: String, |
|
|
|
default: '' |
|
|
|
default: '' |
|
|
|
}, |
|
|
|
}, |
|
|
|
selectionData: { |
|
|
|
selectionData: { |
|
|
|
@ -174,25 +174,23 @@ export default { |
|
|
|
// 更新当前页面的勾选状态 |
|
|
|
// 更新当前页面的勾选状态 |
|
|
|
updateCurrentPageSelection() { |
|
|
|
updateCurrentPageSelection() { |
|
|
|
if (!this.$refs.crud || !this.data) return; |
|
|
|
if (!this.$refs.crud || !this.data) return; |
|
|
|
|
|
|
|
|
|
|
|
this.isUpdatingSelection = true; |
|
|
|
this.isUpdatingSelection = true; |
|
|
|
|
|
|
|
const currentPageData = this.data |
|
|
|
const currentPageData = this.data || []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 先清除所有选择 |
|
|
|
// 先清除所有选择 |
|
|
|
this.$refs.crud.toggleSelection(); |
|
|
|
this.$refs.crud.toggleSelection(); |
|
|
|
|
|
|
|
|
|
|
|
// 检查当前页面的数据中有哪些在 allSelectedList 中 |
|
|
|
// 检查当前页面的数据中有哪些在 allSelectedList 中 |
|
|
|
currentPageData.forEach((item) => { |
|
|
|
currentPageData.forEach((item) => { |
|
|
|
const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
selectedItem.id === item.id |
|
|
|
selectedItem.id === item.id |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (isSelected) { |
|
|
|
if (isSelected) { |
|
|
|
this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 延迟 确保选择状态已完全更新 |
|
|
|
// 延迟 确保选择状态已完全更新 |
|
|
|
this.$nextTick(() => { |
|
|
|
this.$nextTick(() => { |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
@ -201,40 +199,19 @@ export default { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//勾选选中 |
|
|
|
|
|
|
|
selectionChange(selection) { |
|
|
|
selectionChange(selection) { |
|
|
|
if (this.isUpdatingSelection) { |
|
|
|
console.log(selection,'selection-------') |
|
|
|
return; |
|
|
|
console.log(this.selectionData, '---selectionData') |
|
|
|
} |
|
|
|
const currentPageIds = this.selectionData.map(item => item.id) |
|
|
|
|
|
|
|
let arr = selection.filter(item => !currentPageIds.includes(item.id)) //未选择的数据 |
|
|
|
console.log('当前选择:', selection) |
|
|
|
const selectionWithTwoInventoryId = arr.map(item => ({ |
|
|
|
console.log('当前页面数据:', this.data) |
|
|
|
|
|
|
|
console.log('当前全部勾选:', this.allSelectedList) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前页面的数据ID |
|
|
|
|
|
|
|
const currentPageIds = this.data.map(item => item.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const otherPageSelected = this.allSelectedList.filter(item => |
|
|
|
|
|
|
|
!currentPageIds.includes(item.id) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const currentSelected = selection.map(item => ({ |
|
|
|
|
|
|
|
...item, |
|
|
|
...item, |
|
|
|
twoInventoryId: item.id |
|
|
|
twoInventoryId: item.id |
|
|
|
})); |
|
|
|
})) |
|
|
|
|
|
|
|
this.allSelectedList.push(...selectionWithTwoInventoryId); |
|
|
|
// 组合所有勾选数据 |
|
|
|
this.allSelectedList = this.uniqueById(this.allSelectedList); |
|
|
|
const combinedSelection = [ |
|
|
|
|
|
|
|
...otherPageSelected, // 其他页面的数据 |
|
|
|
|
|
|
|
...currentSelected // 当前页面新勾选的数据 |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 去重并更新 allSelectedList |
|
|
|
|
|
|
|
this.allSelectedList = this.uniqueById(combinedSelection) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('更新后的allSelectedList:', this.allSelectedList) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//去重 |
|
|
|
//去重 |
|
|
|
uniqueById(arr) { |
|
|
|
uniqueById(arr) { |
|
|
|
const uniqueObj = {}; |
|
|
|
const uniqueObj = {}; |
|
|
|
@ -245,24 +222,24 @@ export default { |
|
|
|
}); |
|
|
|
}); |
|
|
|
return Object.values(uniqueObj); |
|
|
|
return Object.values(uniqueObj); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//点击确定 |
|
|
|
//点击确定 |
|
|
|
handleConfirm() { |
|
|
|
handleConfirm() { |
|
|
|
const uniqueList = this.uniqueById(this.allSelectedList) |
|
|
|
const uniqueList = this.uniqueById(this.allSelectedList) |
|
|
|
this.$emit("confirm", uniqueList) |
|
|
|
this.$emit("confirm", uniqueList) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
handleCloseDetail() { |
|
|
|
handleCloseDetail() { |
|
|
|
this.$emit('handleCloseDetail') |
|
|
|
this.$emit('handleCloseDetail') |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
selectionClear() { |
|
|
|
selectionClear() { |
|
|
|
this.allSelectedList = [] |
|
|
|
this.allSelectedList = [] |
|
|
|
if (this.$refs.crud) { |
|
|
|
if (this.$refs.crud) { |
|
|
|
this.$refs.crud.toggleSelection() |
|
|
|
this.$refs.crud.toggleSelection() |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
currentChange(currentPage) { |
|
|
|
currentChange(currentPage) { |
|
|
|
this.page.currentPage = currentPage; |
|
|
|
this.page.currentPage = currentPage; |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
@ -272,16 +249,16 @@ export default { |
|
|
|
this.page.pageSize = pageSize; |
|
|
|
this.page.pageSize = pageSize; |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
refreshChange() { |
|
|
|
refreshChange() { |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
this.onLoad(this.page, this.query) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
handleTabClick() { |
|
|
|
handleTabClick() { |
|
|
|
this.page.currentPage = 1 |
|
|
|
this.page.currentPage = 1 |
|
|
|
this.onLoad(this.page) |
|
|
|
this.onLoad(this.page) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
onLoad(page, params = {}) { |
|
|
|
onLoad(page, params = {}) { |
|
|
|
this.loading = true |
|
|
|
this.loading = true |
|
|
|
const requestParams = Object.assign({}, params, this.query, { |
|
|
|
const requestParams = Object.assign({}, params, this.query, { |
|
|
|
@ -294,7 +271,7 @@ export default { |
|
|
|
apiPromise.then((res) => { |
|
|
|
apiPromise.then((res) => { |
|
|
|
this.data = res.data.result.list |
|
|
|
this.data = res.data.result.list |
|
|
|
this.page.total = res.data.result.total |
|
|
|
this.page.total = res.data.result.total |
|
|
|
|
|
|
|
|
|
|
|
// 数据加载完成后,更新当前页面的勾选状态 |
|
|
|
// 数据加载完成后,更新当前页面的勾选状态 |
|
|
|
this.$nextTick(() => { |
|
|
|
this.$nextTick(() => { |
|
|
|
this.updateCurrentPageSelection() |
|
|
|
this.updateCurrentPageSelection() |
|
|
|
@ -305,7 +282,7 @@ export default { |
|
|
|
this.loading = false; |
|
|
|
this.loading = false; |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
handleCancel() { |
|
|
|
handleCancel() { |
|
|
|
this.categoryVisible = false |
|
|
|
this.categoryVisible = false |
|
|
|
} |
|
|
|
} |
|
|
|
|