多选解绑和绑定

This commit is contained in:
jjLv 2024-11-05 14:42:12 +08:00
parent 3f57f7b93f
commit 42646b4f32
1 changed files with 91 additions and 14 deletions

View File

@ -144,6 +144,8 @@
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
@selection-change="handleSelectionChange"
@select="handlerSelect"
@select-all="handlerSelectAll"
>
<el-table-column
type="selection"
@ -321,6 +323,7 @@ export default {
userNoList:[],
userIdTemp: -1,
typeIdTemp: -1,
maxLength:100,//
//
queryParams: {
typeName: undefined,
@ -529,21 +532,95 @@ export default {
},
// //-
// handlerSelect(val, row) {
// this.ids.indexOf(row.deviceCode) === -1
// ? this.currentSelection.push(row.deviceCode)
// : this.currentSelection.splice(this.currentSelection.indexOf(row.deviceCode), 1)
// },
handleSelect(selection, row) {
this.toggleSelection(selection, row);
},
handleSelectAll(selection) {
this.isAllSelect = !this.isAllSelect;
let data = this.typeList;
this.toggleSelect(data,this.isAllSelect,'all');
//-
handlerSelect(val, row) {
const index = this.userList.findIndex(item=>item.typeId===row.typeId);
if(this.ids.indexOf(row.typeId) === -1){
this.userList.push({'typeId':row.typeId,'userId':this.userIdTemp})
}else if(index!== -1){
this.userList.splice(index,1);
}
const indexNo = this.userNoList.findIndex(item=>item.typeId===row.typeId);
if(this.ids.indexOf(row.typeId) === -1){
this.userNoList.push({'typeId':row.typeId,'userId':row.keeperUserId})
}else if(indexNo!== -1){
this.userNoList.splice(indexNo,1);
}
},
//-
handlerSelectAll(val) {
if (val.length) {
// :
// 1 2
//
// tableDatavalcurrentSelection
// tableDatavalcurrentSelection
const isAllSelect = this.tableData.every(item =>
val.some(valItem => valItem.typeId === item.typeId)
)
if (isAllSelect) {
//
const diff = val.filter(
item => !this.userList.some(user => user.typeId === item.typeId)
)
if (this.userList.length + diff.length > this.maxLength) {
const spaceLeft = this.maxLength - this.userList.length
const toAdd = diff.slice(0,spaceLeft)
this.userList = this.userList.concat(toAdd.map(item =>({
typeId:item.typeId,
userId:this.userIdTemp
})));
diff.slice(spaceLeft).forEach(item => this.$refs.multipleTable.toggleRowSelection(item, false))
} else {
this.userList = this.userList.concat(diff.map(item=>({
typeId:item.typeId,
userId:this.userIdTemp
})))
}
//
const diffNo = val.filter(
item => !this.userNoList.some(user => user.typeId === item.typeId)
)
if (this.userNoList.length + diff.length > this.maxLength) {
const spaceLeft = this.maxLength - this.userNoList.length
const toAdd = diff.slice(0,spaceLeft)
this.userNoList = this.userNoList.concat(toAdd.map(item =>({
typeId:item.typeId,
userId:item.userId
})));
diff.slice(spaceLeft).forEach(item => this.$refs.multipleTable.toggleRowSelection(item, false))
} else {
this.userNoList = this.userNoList.concat(diff.map(item=>({
typeId:item.typeId,
userId:item.userId
})))
}
} else {
this.userList = this.userList.filter(
user => !this.tableData.some(item => item.typeId === user.typeId)
)
this.userNoList = this.userNoList.filter(
user => !this.tableData.some(item => item.typeId === user.typeId)
)
}
} else {
// :
//
this.userList = []
this.userNoList = []
}
},
// handleSelect(selection, row) {
// this.toggleSelection(selection, row);
// },
// handleSelectAll(selection) {
// this.isAllSelect = !this.isAllSelect;
// let data = this.typeList;
// this.toggleSelect(data,this.isAllSelect,'all');
},
// },
// //
// selectTr(selection,row){