|
|
|
|
@ -35,7 +35,7 @@ export default { |
|
|
|
|
query: { type: "NY" }, |
|
|
|
|
loading: true, |
|
|
|
|
page: { |
|
|
|
|
pageSize: 5, |
|
|
|
|
pageSize: 10, |
|
|
|
|
currentPage: 1, |
|
|
|
|
total: 0, |
|
|
|
|
}, |
|
|
|
|
@ -152,6 +152,7 @@ export default { |
|
|
|
|
rkTable: [], |
|
|
|
|
currentRow: null, |
|
|
|
|
allSelectedList: [], //存储所有勾选的数据 |
|
|
|
|
isUpdatingSelection: false, // 修正:将此属性移到 data 中 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
computed: { |
|
|
|
|
@ -194,8 +195,8 @@ export default { |
|
|
|
|
|
|
|
|
|
handleTabClick() { |
|
|
|
|
this.loadTransactionData(); |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
async loadTransactionData() { |
|
|
|
|
if (!this.currentRow) return; |
|
|
|
|
const params = { |
|
|
|
|
@ -223,142 +224,155 @@ export default { |
|
|
|
|
this.loading = false; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
searchReset() { |
|
|
|
|
this.query = {}; |
|
|
|
|
this.onLoad(this.page); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
searchChange(params, done) { |
|
|
|
|
this.query = params; |
|
|
|
|
this.page.currentPage = 1; |
|
|
|
|
this.onLoad(this.page, params); |
|
|
|
|
done(); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
//勾选选中 |
|
|
|
|
selectionChange(list) { |
|
|
|
|
console.log("勾选选中", list) |
|
|
|
|
const currentPageIds = this.data.map(item => item.id) |
|
|
|
|
console.log(currentPageIds, "currentPageIds") |
|
|
|
|
this.allSelectedList = this.allSelectedList.filter(item => !currentPageIds.includes(item.id)) |
|
|
|
|
console.log(this.allSelectedList, '1') |
|
|
|
|
this.allSelectedList.push(...list) |
|
|
|
|
console.log('所有勾选数据:', this.allSelectedList) |
|
|
|
|
selectionChange(selection) { |
|
|
|
|
// 如果是程序自动更新选择状态,则不执行清理逻辑 |
|
|
|
|
if (this.isUpdatingSelection) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log("勾选选中", selection); |
|
|
|
|
const currentPageIds = this.data.map(item => item.id); |
|
|
|
|
console.log(currentPageIds, "currentPageIds"); |
|
|
|
|
|
|
|
|
|
// 从allSelectedList中移除当前页面的数据(因为当前页面的数据状态以selection为准) |
|
|
|
|
this.allSelectedList = this.allSelectedList.filter(item => |
|
|
|
|
!currentPageIds.includes(item.id) |
|
|
|
|
); |
|
|
|
|
console.log(this.allSelectedList, '1'); |
|
|
|
|
|
|
|
|
|
// 将当前页面选中的数据添加到allSelectedList |
|
|
|
|
this.allSelectedList.push(...selection); |
|
|
|
|
console.log('所有勾选数据:', this.allSelectedList); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
//点击确定 |
|
|
|
|
handleConfirm() { |
|
|
|
|
console.log(6) |
|
|
|
|
console.log(this.allSelectedList, 'chuan') |
|
|
|
|
this.$emit("confirm", this.allSelectedList) |
|
|
|
|
console.log(6); |
|
|
|
|
console.log(this.allSelectedList, 'chuan'); |
|
|
|
|
this.$emit("confirm", this.allSelectedList); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
selectionClear() { |
|
|
|
|
this.selectionList = []; |
|
|
|
|
this.$refs.crud.toggleSelection(); |
|
|
|
|
this.allSelectedList = []; // 清空所有选中的数据 |
|
|
|
|
if (this.$refs.crud) { |
|
|
|
|
this.$refs.crud.toggleSelection(); // 清空表格选择 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleRowChange(row, index, data) { |
|
|
|
|
// 切换页面保持勾选状态(仅保留有效行) |
|
|
|
|
// 这个方法应该只处理行变化,分页勾选保持应该在 onLoad 中处理 |
|
|
|
|
// 但为了保持当前页面勾选状态,我们保留此逻辑 |
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
const currentPageData = this.data |
|
|
|
|
console.log(this.data,0) |
|
|
|
|
this.$refs.crud.toggleAllSelection(false); |
|
|
|
|
// 设置标志,表示正在程序化更新选择状态 |
|
|
|
|
this.isUpdatingSelection = true; |
|
|
|
|
|
|
|
|
|
const currentPageData = this.data || []; |
|
|
|
|
// 清除当前页面的选中状态 |
|
|
|
|
this.$refs.crud.toggleSelection(); |
|
|
|
|
|
|
|
|
|
// 遍历当前页面的数据,检查是否在 allSelectedList 中 |
|
|
|
|
currentPageData.forEach((item) => { |
|
|
|
|
// 仅勾选数量非0的行 |
|
|
|
|
const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
|
selectedItem.id === item.id && !(item.num === 0 || item.num === null || item.num === undefined || item.num === '') |
|
|
|
|
selectedItem.id === item.id |
|
|
|
|
); |
|
|
|
|
// 如果该项已经被选中,则勾选它 |
|
|
|
|
if (isSelected) { |
|
|
|
|
this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 延迟重置标志 |
|
|
|
|
setTimeout(() => { |
|
|
|
|
this.isUpdatingSelection = false; |
|
|
|
|
}, 100); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
// handleRowChange(row, index, data) { |
|
|
|
|
// // 切换页面要判断当前页面数据是否在已勾选的数据中,如果在则勾选,否则不勾选 |
|
|
|
|
// this.$nextTick(() => { |
|
|
|
|
// // 获取当前页面的所有数据 |
|
|
|
|
// const currentPageData = this.data || []; |
|
|
|
|
// // 清除当前页面的选中状态 |
|
|
|
|
// this.$refs.crud.toggleAllSelection(false); |
|
|
|
|
|
|
|
|
|
// // 遍历当前页面的数据,检查是否在 allSelectedList 中 |
|
|
|
|
// currentPageData.forEach((item, index) => { |
|
|
|
|
// const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
|
// selectedItem.id === item.id |
|
|
|
|
// ); |
|
|
|
|
// // 如果该项已经被选中,则勾选它 |
|
|
|
|
// if (isSelected) { |
|
|
|
|
// this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
|
// } |
|
|
|
|
// }); |
|
|
|
|
// }); |
|
|
|
|
// }, |
|
|
|
|
// currentChange(currentPage) { |
|
|
|
|
// console.log(currentPage, 1); |
|
|
|
|
// this.page.currentPage = currentPage; |
|
|
|
|
// // 切换页面时重新加载数据,会触发 onLoad,从而调用 handleRowChange |
|
|
|
|
// this.onLoad(this.page, this.query); |
|
|
|
|
// }, |
|
|
|
|
// onLoad(page, params = {}) { |
|
|
|
|
// this.loading = true; |
|
|
|
|
// console.log(this.query, 2); |
|
|
|
|
// getList( |
|
|
|
|
// page.currentPage, |
|
|
|
|
// page.pageSize, |
|
|
|
|
// Object.assign(params, this.query) |
|
|
|
|
|
|
|
|
|
// ).then((res) => { |
|
|
|
|
// this.data = res.data.result.list; |
|
|
|
|
// this.loading = false; |
|
|
|
|
// this.page.total = res.data.result.total; |
|
|
|
|
|
|
|
|
|
// // 数据加载完成后,更新当前页面的勾选状态 |
|
|
|
|
// this.$nextTick(() => { |
|
|
|
|
// this.updateCurrentPageSelection(); |
|
|
|
|
// }); |
|
|
|
|
// }); |
|
|
|
|
// this.loading = false; |
|
|
|
|
// }, |
|
|
|
|
// // 添加一个新方法来更新当前页面的选中状态 |
|
|
|
|
// updateCurrentPageSelection() { |
|
|
|
|
// if (!this.$refs.crud) return; |
|
|
|
|
|
|
|
|
|
// const currentPageData = this.data || []; |
|
|
|
|
|
|
|
|
|
// currentPageData.forEach((item) => { |
|
|
|
|
// const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
|
// selectedItem.id === item.id |
|
|
|
|
// ); |
|
|
|
|
|
|
|
|
|
// if (isSelected) { |
|
|
|
|
// this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
|
// } |
|
|
|
|
// }); |
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
currentChange(currentPage) { |
|
|
|
|
console.log(currentPage, 1) |
|
|
|
|
this.handleRowChange() |
|
|
|
|
console.log(currentPage, 1); |
|
|
|
|
this.page.currentPage = currentPage; |
|
|
|
|
// 切换页面时重新加载数据,会触发 onLoad |
|
|
|
|
this.onLoad(this.page, this.query); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
sizeChange(pageSize) { |
|
|
|
|
this.page.pageSize = pageSize; |
|
|
|
|
this.onLoad(this.page, this.query); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
refreshChange() { |
|
|
|
|
this.onLoad(this.page, this.query); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
onLoad(page, params = {}) { |
|
|
|
|
this.loading = true; |
|
|
|
|
console.log(this.query, 2) |
|
|
|
|
console.log(this.query, 2); |
|
|
|
|
getList( |
|
|
|
|
page.currentPage, |
|
|
|
|
page.pageSize, |
|
|
|
|
Object.assign(params, this.query) |
|
|
|
|
|
|
|
|
|
).then((res) => { |
|
|
|
|
this.data = res.data.result.list |
|
|
|
|
this.data = res.data.result.list; |
|
|
|
|
this.loading = false; |
|
|
|
|
this.page.total = res.data.result.total; |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 数据加载完成后,更新当前页面的勾选状态 |
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
this.updateCurrentPageSelection(); |
|
|
|
|
}); |
|
|
|
|
}).catch(error => { |
|
|
|
|
this.loading = false; |
|
|
|
|
this.$message.error('加载数据失败: ' + error.message); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 添加一个新方法来更新当前页面的选中状态 |
|
|
|
|
updateCurrentPageSelection() { |
|
|
|
|
if (!this.$refs.crud) return; |
|
|
|
|
|
|
|
|
|
// 设置标志,表示正在程序化更新选择状态 |
|
|
|
|
this.isUpdatingSelection = true; |
|
|
|
|
|
|
|
|
|
const currentPageData = this.data || []; |
|
|
|
|
|
|
|
|
|
// 先清除所有选择 |
|
|
|
|
this.$refs.crud.toggleSelection(); |
|
|
|
|
|
|
|
|
|
currentPageData.forEach((item) => { |
|
|
|
|
const isSelected = this.allSelectedList.some(selectedItem => |
|
|
|
|
selectedItem.id === item.id |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (isSelected) { |
|
|
|
|
this.$refs.crud.toggleRowSelection(item, true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 延迟重置标志,确保选择状态已完全更新 |
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
this.isUpdatingSelection = false; |
|
|
|
|
}, 100); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleCancel() { |
|
|
|
|
this.$emit('handleCloseDetail'); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|