代码优化

This commit is contained in:
BianLzhaoMin 2024-11-11 17:06:52 +08:00
parent 9645d6160c
commit 8835cb8906
1 changed files with 171 additions and 25 deletions

View File

@ -191,7 +191,8 @@ export default {
currentIndex: 0, currentIndex: 0,
fixedPersonList: [], fixedPersonList: [],
tempPersonList: [], tempPersonList: [],
returnPersonList: [] returnPersonList: [],
isSearch: false
} }
}, },
methods: { methods: {
@ -232,13 +233,46 @@ export default {
// //
if (this.subUserListTemp.length > 0) { if (this.subUserListTemp.length > 0) {
// this.subUserList = this.subUserListTemp.filter(e => e.isAllChecked == true) // this.subUserList = this.subUserListTemp.filter(e => e.isAllChecked == true)
this.subUserListAll.forEach(e => { // this.subUserListAll.forEach(e => {
this.subUserListTemp.forEach(j => { // this.subUserListTemp.forEach(j => {
if (e.idNumber == j.idNumber) { // if (e.idNumber == j.idNumber) {
this.subUserList.push(JSON.parse(JSON.stringify(j))) // this.subUserList.push(JSON.parse(JSON.stringify(j)))
} // }
// })
// })
let tempArray = this.personList.filter((e, index) => index != this.currentIndex)
let tempPersonList = []
if (tempArray.length > 0) {
this.subUserList = []
// this.subUserListTemp
tempArray.forEach(e => {
this.subUserListAll.forEach(j => {
if (!e.includes(j.idNumber)) {
// this.subUserList.push(j)
tempPersonList.push(JSON.parse(JSON.stringify(j)))
// this.subUserListTemp.push(JSON.parse(JSON.stringify(j)))
}
})
}) })
})
// this.subUserList = this.subUserListTemp.filter(e => e.isAllChecked == true)
tempPersonList.forEach(e => {
this.subUserListTemp.forEach(j => {
if (e.idNumber == j.idNumber) {
this.subUserList.push(JSON.parse(JSON.stringify(j)))
}
})
})
// this.subUserList = tempPersonList
} else {
this.subUserListAll.forEach(e => {
this.subUserListTemp.forEach(j => {
if (e.idNumber == j.idNumber) {
this.subUserList.push(JSON.parse(JSON.stringify(j)))
}
})
})
}
} else { } else {
this.subUserList = [] this.subUserList = []
} }
@ -250,15 +284,67 @@ export default {
// this.subUserList = this.subUserListTemp.filter(e => e.isAllChecked == false) // this.subUserList = this.subUserListTemp.filter(e => e.isAllChecked == false)
// } // }
if (this.subUserListTemp.length > 0) { if (this.subUserListTemp.length > 0) {
this.subUserListAll.forEach(e => { // this.subUserListAll.forEach(e => {
this.subUserListTemp.forEach(j => { // if (!this.subUserListTemp.includes(e)) {
if (e.idNumber != j.idNumber) { // this.subUserList.push(JSON.parse(JSON.stringify(e)))
this.subUserList.push(JSON.parse(JSON.stringify(e))) // }
} // // console.log('', e)
// // this.subUserListTemp.forEach(j => {
// // console.log('', j)
// // if (e.idNumber == j.idNumber) {
// // this.subUserList.push(JSON.parse(JSON.stringify(e)))
// // }
// // })
// })
// this.subUserListTemp.forEach((e)=>{
// this.subUserListAll.forEach((j)=>{
// if(e.idNumber )
// })
// })
let tempArray = this.personList.filter((e, index) => index != this.currentIndex)
let tempPersonList = []
if (tempArray.length > 0) {
this.subUserList = []
// this.subUserListTemp
tempArray.forEach(e => {
this.subUserListAll.forEach(j => {
if (!e.includes(j.idNumber)) {
// this.subUserList.push(j)
tempPersonList.push(JSON.parse(JSON.stringify(j)))
// this.subUserListTemp.push(JSON.parse(JSON.stringify(j)))
}
})
}) })
})
this.subUserList = this.tempPersonList.filter(
itemA => !this.subUserListTemp.some(itemB => itemB.idNumber == itemA.idNumber)
)
} else {
this.subUserList = this.subUserListAll.filter(
itemA => !this.subUserListTemp.some(itemB => itemB.idNumber == itemA.idNumber)
)
}
} else { } else {
this.subUserList = JSON.parse(JSON.stringify(this.subUserListAll)) let tempArray = this.personList.filter((e, index) => index != this.currentIndex)
let tempPersonList = []
if (tempArray.length > 0) {
this.subUserList = []
// this.subUserListTemp
tempArray.forEach(e => {
this.subUserListAll.forEach(j => {
if (!e.includes(j.idNumber)) {
// this.subUserList.push(j)
tempPersonList.push(JSON.parse(JSON.stringify(j)))
// this.subUserListTemp.push(JSON.parse(JSON.stringify(j)))
}
})
})
this.subUserList = tempPersonList
} else {
this.subUserList = JSON.parse(JSON.stringify(this.subUserListAll))
}
} }
} }
} else { } else {
@ -272,7 +358,7 @@ export default {
// } // }
console.log('全部状态---', this.personList) console.log('全部状态---', this.personList)
if (this.subUserListTemp.length == 0) { if (this.subUserListTemp.length == 0 && !this.isSearch) {
if (this.personList.length > 0) { if (this.personList.length > 0) {
this.subUserListAll.forEach(e => { this.subUserListAll.forEach(e => {
if (this.personList[this.currentIndex].includes(e.idNumber)) { if (this.personList[this.currentIndex].includes(e.idNumber)) {
@ -300,16 +386,69 @@ export default {
} else { } else {
this.subUserList = JSON.parse(JSON.stringify(this.subUserListAll)) this.subUserList = JSON.parse(JSON.stringify(this.subUserListAll))
} }
} else { } else if (this.subUserListTemp.length > 0 && this.isSearch) {
this.subUserListAll.forEach(e => { let tempArray = this.personList.filter((e, index) => index != this.currentIndex)
this.subUserListTemp.forEach(j => { let tempPersonList = []
if (e.idNumber == j.idNumber) { if (tempArray.length > 0) {
this.subUserList.push(JSON.parse(JSON.stringify(j))) this.subUserList = []
} else { // this.subUserListTemp
this.subUserList.push(JSON.parse(JSON.stringify(e))) tempArray.forEach(e => {
} this.subUserListAll.forEach(j => {
if (!e.includes(j.idNumber)) {
// this.subUserList.push(j)
tempPersonList.push(JSON.parse(JSON.stringify(j)))
// this.subUserListTemp.push(JSON.parse(JSON.stringify(j)))
}
})
}) })
})
// this.subUserList = tempPersonList
tempPersonList.forEach(e => {
this.subUserListTemp.forEach(j => {
if (e.idNumber == j.idNumber) {
// this.subUserList.push(JSON.parse(JSON.stringify(j)))
e.isChecked = true
} else {
// this.subUserList.push(JSON.parse(JSON.stringify(e)))
}
})
})
this.subUserList = tempPersonList
} else {
this.subUserListAll.forEach(e => {
this.subUserListTemp.forEach(j => {
if (e.idNumber == j.idNumber) {
// this.subUserList.push(JSON.parse(JSON.stringify(j)))
e.isChecked = true
} else {
// this.subUserList.push(JSON.parse(JSON.stringify(e)))
}
})
})
this.subUserList = this.subUserListAll
}
} else if (this.subUserListTemp.length == 0 && this.isSearch) {
let tempArray = this.personList.filter((e, index) => index != this.currentIndex)
let tempPersonList = []
if (tempArray.length > 0) {
this.subUserList = []
// this.subUserListTemp
tempArray.forEach(e => {
this.subUserListAll.forEach(j => {
if (!e.includes(j.idNumber)) {
// this.subUserList.push(j)
tempPersonList.push(JSON.parse(JSON.stringify(j)))
// this.subUserListTemp.push(JSON.parse(JSON.stringify(j)))
}
})
})
this.subUserList = tempPersonList
} else {
this.subUserList = this.subUserListAll
}
} else {
} }
} }
this.totalAmount = this.subUserList.length this.totalAmount = this.subUserList.length
@ -327,7 +466,7 @@ export default {
// try { // try {
// this.subUserListAll.forEach(e => { // this.subUserListAll.forEach(e => {
// if (e.idNumber == item.idNumber) { // if (e.idNumber == item.idNumber) {
// e.isChecked = !eisChecked // e.isChecked = !e.isChecked
// throw new Error() // throw new Error()
// } // }
// }) // })
@ -397,6 +536,7 @@ export default {
this.$refs.popup.close() this.$refs.popup.close()
}, },
onSubmit() { onSubmit() {
this.isSearch = true
if (this.reamList.length > 0) { if (this.reamList.length > 0) {
this.subQueryParams.teamName = this.reamList.join(',') this.subQueryParams.teamName = this.reamList.join(',')
} }
@ -460,6 +600,12 @@ export default {
console.log(isAllChecked, 'isAllChecked') console.log(isAllChecked, 'isAllChecked')
this.subUserList.forEach(e => { this.subUserList.forEach(e => {
e.isChecked = !isAllChecked e.isChecked = !isAllChecked
// this.subUserListAll.forEach(j => {
// if (e.idNumber == j.idNumber) {
// j.isChecked = !j.isChecked
// }
// })
}) })
if (this.subUserList.every(e => e.isChecked == true)) { if (this.subUserList.every(e => e.isChecked == true)) {