This commit is contained in:
2025-10-30 13:37:52 +08:00
parent d859ba62c8
commit c9c8f82910
31 changed files with 1485 additions and 397 deletions

View File

@@ -2,7 +2,7 @@
* @Author: zwq
* @Date: 2025-10-11 14:27:37
* @LastEditors: zwq
* @LastEditTime: 2025-10-15 16:47:28
* @LastEditTime: 2025-10-29 17:12:04
* @Description:
-->
<template>
@@ -12,6 +12,9 @@
ref="searchBarForm"
@headBtnClick="buttonClick" />
<base-table
ref="groupTableRef"
:id="'groupTableSelectRef'"
row-key="id"
:selectWidth="55"
@selection-change="selectChange"
:table-props="tableProps"
@@ -46,6 +49,7 @@ const tableProps = [
{
prop: 'remark',
label: '备注',
showOverflowtooltip: true,
},
];
@@ -84,22 +88,52 @@ export default {
name: '',
},
selectedList: [],
deptId: undefined
selectedArr: [], //已选的班组,从父组件传过来的
deptId: undefined,
};
},
created() {},
methods: {
init(id){
this.deptId = id
this.getDataList()
},
init(id, tableData) {
this.deptId = id;
this.selectedArr = tableData || [];
this.$nextTick(() => {
this.getDataList();
});
},
// 获取数据列表
getDataList() {
this.urlOptions
.getDataListURL(this.deptId)
.then((response) => {
this.tableData = response.data;
this.urlOptions.getDataListURL(this.deptId).then((response) => {
this.tableData = response.data;
this.$nextTick(() => {
if (this.selectedArr.length > 0) {
this.setSelectedRows();
}
});
});
},
setSelectedRows() {
const table = this.$refs.groupTableRef.$children[0];
// 先清空选择
table.clearSelection();
this.selectedArr.forEach((item) => {
const rowInTable = this.tableData.find((i) => i.id === item.id);
if (rowInTable) {
//这里一定要用table.tableData这样才是指向同一个数组
this.$set(table.store.states, 'selection', [
...table.store.states.selection,
table.tableData.find((i) => i.id === item.id),
]);
}
});
// 强制更新视图
this.$nextTick(() => {
table.$forceUpdate();
this.$forceUpdate();
});
},
buttonClick(val) {
switch (val.btnName) {
@@ -115,9 +149,25 @@ export default {
selectChange(val) {
this.selectedList = val;
},
// 判断两个数组是否有重复的 id
hasDuplicateIds(arr1, arr2) {
const idSet = new Set(arr1.map((item) => item.id));
return arr2.some((item) => idSet.has(item.id));
},
dataFormSubmit() {
if (this.selectedList && this.selectedList.length > 0) {
const haveData = this.hasDuplicateIds(
this.selectedArr,
this.selectedList
);
if (haveData) {
this.$message('请不要重复添加数组');
return;
}
this.$emit('refreshTableData', this.selectedList);
} else if (this.selectedArr.length > 0) {
this.$message('请不要重复添加数组');
}
},
},