1,html代碼
image.png
2,字段說明挤渐,tableData2為請求的列表數(shù)據(jù),roleUserLists為回顯數(shù)據(jù)
// 全選/取消全選
Allofthem(val, row) {
// 如果為空双絮,則為清除選項狀態(tài),此時將table中的所有內容都從saveCheckList移除
if (val && val.length == 0) {
this.tableData2.forEach((row) => {
// 從保存項saveCheckList里面尋找,如果找到了row則刪除
let fitemIndex = this.roleUserLists.findIndex((item) => {
return item.userCode == row.userCode;
});
// 找到了就刪除掉
if (fitemIndex >= 0) {
this.roleUserLists.splice(fitemIndex, 1);
}
});
} else if (val && val.length != 0 && this.roleUserLists.length != 0) {
// 如果不為空,且this.saveCheckList也不為空則從val里面找
val.forEach((row) => {
// 從保存項saveCheckList里面尋找,如果找到了row則刪除得问,如果沒找到則添加
let fitemIndex = this.roleUserLists.findIndex((item) => {
return item.userCode == row.userCode;
});
// 沒找到就push進去
if (fitemIndex < 0) {
this.roleUserLists.push(row);
}
});
} else if (val && val.length != 0 && this.roleUserLists.length == 0) {
val.forEach((row) => {
this.roleUserLists.push(row);
});
}
//
},
// 單選/取消單選
Radioselect(val, row) {
debugger;
// that.roleUserLists
let selected = val.length && val.indexOf(row) !== -1; //selected為true時為選中囤攀,false時為未選中
if (selected) {
this.roleUserLists.push({
userCode: row.userCode,
userName: row.userName,
});
console.log(this.roleUserLists);
} else {
// 從保存項roleUserLists里面尋找,如果找到了row則刪除,如果沒找到則添加
let fitemIndex = this.roleUserLists.findIndex((item) => {
return item.userCode == row.userCode;
});
// 找到了就刪除掉
if (fitemIndex >= 0) {
this.roleUserLists.splice(fitemIndex, 1);
}
}
//
},
3宫纬,加載勾選的列表及勾選回顯
GetuserList() {
var that = this;
that.loading = true;
that.$axios
.get(that.$baseService.getqualityuserslit, {
params: that.formselect2,
})
.then(function (res) {
that.total2 = res.data.totalCount;
that.tableData2 = JSON.parse(JSON.stringify(res.data.items));
that.loading = false;
var rows = that.roleUserLists;
that.$nextTick(() => {
that.tableData2.forEach(function (row, index) {
rows.forEach(function (row2, index2) {
if (row2.userCode == row.userCode) {
that.$refs.table2.toggleRowSelection(row, true);
}
});
});
});
})
.catch(function (error) {
that.loading = false;
});
},