table,已选中人员回显 重置

This commit is contained in:
shijingjing
2022-07-26 10:32:07 +08:00
parent faea4c65bd
commit 601640eea1
6 changed files with 35 additions and 32 deletions

View File

@@ -3,7 +3,7 @@
<div class="header-middle">
<div class="userCards" v-for="e in userList" :key="e.userId">
<div class="imges">
<div class="imgselect" :class="{ checked: e.isChecked }" @click.stop="itemCheck(e)" />
<div class="imgselect" :class="{ 'checked': e.isChecked }" @click.stop="itemCheck(e)" />
<img src="./images/tx@2x.png" alt="" class="avatras"/> {{e.userId}}
</div>
<div class="rights fill">
@@ -41,11 +41,10 @@ export default {
onLoad() {
this.selected = uni.getStorageSync('userSelect') || []
this.getDeptsAndUsersByParent()
console.log(this.selected);
},
methods: {
isSelected(id) {
return !!this.selected.find(e => e.id == id)
return this.selected.userId===id
},
getDeptsAndUsersByParent() {
this.userList = []
@@ -53,7 +52,7 @@ export default {
params: {}
}).then(res => {
if (res?.data) {
let userArr = res.data.records.map(e => ({userId: e.createUserId, isChecked: this.isSelected(e.id)}))
let userArr = res.data.records.map(e => ({userId: e.createUserId, isChecked: this.isSelected(e.createUserId)}))
// 数组去重
this.userList = []
userArr.forEach(item=> {
@@ -61,20 +60,27 @@ export default {
this.userList.push(item)
}
})
}
})
},
itemCheck(row) {
this.userList.forEach(e => e.isChecked = false)
row.isChecked = !row.isChecked
this.selected[0] = this.userList.filter(e => e.isChecked == true)
this.$forceUpdate()
const index= this.userList.findIndex(o => {
return row.userId===o.userId
})
this.userList[index].isChecked=true
this.selected = this.userList[index]
console.log( this.selected)
// this.$forceUpdate()
},
submit() {
if(!this.selected.length) {
if(!this.selected.userId) {
return this.$u.toast('请选择创建人')
}
uni.$emit("pagePicker:custom", this.selected)
uni.$emit("pagePicker:custom",[ this.selected])
uni.setStorageSync('userSelect', this.selected)
uni.navigateBack()
},