多选解绑和绑定
This commit is contained in:
parent
3f57f7b93f
commit
42646b4f32
|
|
@ -144,6 +144,8 @@
|
||||||
default-expand-all
|
default-expand-all
|
||||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
@selection-change="handleSelectionChange"
|
@selection-change="handleSelectionChange"
|
||||||
|
@select="handlerSelect"
|
||||||
|
@select-all="handlerSelectAll"
|
||||||
>
|
>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
type="selection"
|
type="selection"
|
||||||
|
|
@ -321,6 +323,7 @@ export default {
|
||||||
userNoList:[],
|
userNoList:[],
|
||||||
userIdTemp: -1,
|
userIdTemp: -1,
|
||||||
typeIdTemp: -1,
|
typeIdTemp: -1,
|
||||||
|
maxLength:100,//已选列表上限,防止数据过多请求报错
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
typeName: undefined,
|
typeName: undefined,
|
||||||
|
|
@ -529,21 +532,95 @@ export default {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// //单选操作-跨页
|
//单选操作-跨页
|
||||||
// handlerSelect(val, row) {
|
handlerSelect(val, row) {
|
||||||
// this.ids.indexOf(row.deviceCode) === -1
|
const index = this.userList.findIndex(item=>item.typeId===row.typeId);
|
||||||
// ? this.currentSelection.push(row.deviceCode)
|
if(this.ids.indexOf(row.typeId) === -1){
|
||||||
// : this.currentSelection.splice(this.currentSelection.indexOf(row.deviceCode), 1)
|
this.userList.push({'typeId':row.typeId,'userId':this.userIdTemp})
|
||||||
// },
|
}else if(index!== -1){
|
||||||
handleSelect(selection, row) {
|
this.userList.splice(index,1);
|
||||||
this.toggleSelection(selection, row);
|
}
|
||||||
},
|
const indexNo = this.userNoList.findIndex(item=>item.typeId===row.typeId);
|
||||||
handleSelectAll(selection) {
|
if(this.ids.indexOf(row.typeId) === -1){
|
||||||
this.isAllSelect = !this.isAllSelect;
|
this.userNoList.push({'typeId':row.typeId,'userId':row.keeperUserId})
|
||||||
let data = this.typeList;
|
}else if(indexNo!== -1){
|
||||||
this.toggleSelect(data,this.isAllSelect,'all');
|
this.userNoList.splice(indexNo,1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//全选操作-跨页
|
||||||
|
handlerSelectAll(val) {
|
||||||
|
if (val.length) {
|
||||||
|
// 进来此处说明:
|
||||||
|
// 1 当前页的全选 2 其他页有数据然后当前页的取消全选
|
||||||
|
// 比较全选或者取消全选与当前页的数据,得到差集
|
||||||
|
// 如果tableData中的数据在val中不存在,则说明是取消全选,需要从currentSelection中移除
|
||||||
|
// 如果tableData中所有的数据都在val中存在,则说明是全选,需要将差集添加到currentSelection中
|
||||||
|
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){
|
// selectTr(selection,row){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue