全選
handleAllClick(){ //@click.prevent="handleAllClick" :checked="selectAllChecked"
if(this.selectAllChecked){
//全選->全不選
for (let i = 0, length = this.currentPageList.length; i < length; i++) {
if (this.currentPageList[i].isChecked && (this.currentPageList[i].isDisabled == false)) {
this.currentPageList[i].isChecked = false;
}
}
this.resetSelectedEditCountList(); //重置選擇列表
}else{
// 不全選->全選
let uTempArr = [];
for (let i = 0, length = this.currentPageList.length; i < length; i++) {
if ((!this.currentPageList[i].isChecked) && (this.currentPageList[i].isDisabled == false)) {
this.currentPageList[i].isChecked = true;
uTempArr.push(this.currentPageList[i]);
}
}
this.resetSelectedEditCountList("insert", uTempArr);
}
this.selectedListCheckedAllStateChanged();
},
重置已選列表中可編輯數(shù)量列表 只支持刪除單個對象,多個對象時直接重置
resetSelectedEditCountList(action = "reset", arr) {
if (action === "reset") {
this.selectedEditCountList = [];
this.tableList.forEach(function (item) {
if (item.checked) {
this.selectedEditCountList.push(item);
}
}, this)
} else if (action === "remove") { // employeeId 后臺返回 todo
for (let i = 0;i < this.selectedEditCountList.length; i++) {
if (typeof arr === "object" && arr.id === this.selectedEditCountList[i].id) {
this.selectedEditCountList.splice(i, 1);
return;
}
}
} else {
this.selectedEditCountList = this.selectedEditCountList.concat(arr);
}
},
已選列表全選復選框狀態(tài)變更
selectedListCheckedAllStateChanged: function () {
let isAllChecked = true;
this.currentPageList.forEach(function (item) {
if(item.hasOwnProperty('isChecked')){ //判斷一個對象是否有某個屬性
if (item.isChecked !== true) {
isAllChecked = false;
}
}
});
this.selectAllChecked = isAllChecked;
}
每個checkbox 點擊
itemHandleClick(item,index){
if(!item.isChecked){
this.currentPageList[index].isChecked = true;
this.resetSelectedEditCountList("insert", item);
}else{
this.currentPageList[index].isChecked = false;
this.resetSelectedEditCountList("remove", item);
}
this.selectedListCheckedAllStateChanged();
},
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者