You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.0 KiB
135 lines
3.0 KiB
|
2 years ago
|
<template>
|
||
|
|
<el-scrollbar v-show="show" ref="scrollBox" class="group-member-choose"
|
||
|
|
:style="{'left':pos.x+'px','top':pos.y-300+'px'}">
|
||
|
2 years ago
|
<div v-for="(member,idx) in showMembers" :key="member.id">
|
||
|
|
<chat-group-member :member="member" :height="40" :active='activeIdx==idx'
|
||
|
|
@click.native="onSelectMember(member)"></chat-group-member>
|
||
|
2 years ago
|
</div>
|
||
|
|
</el-scrollbar>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
2 years ago
|
import ChatGroupMember from "./ChatGroupMember.vue";
|
||
|
2 years ago
|
export default {
|
||
|
|
name: "chatAtBox",
|
||
|
|
components: {
|
||
|
2 years ago
|
ChatGroupMember
|
||
|
2 years ago
|
},
|
||
|
|
props: {
|
||
|
|
searchText: {
|
||
|
|
type: String,
|
||
|
|
default: ""
|
||
|
|
},
|
||
|
2 years ago
|
ownerId: {
|
||
|
|
type: Number,
|
||
|
|
},
|
||
|
2 years ago
|
members: {
|
||
|
|
type: Array
|
||
|
|
}
|
||
|
|
},
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
show: false,
|
||
|
|
pos: {
|
||
|
|
x: 0,
|
||
|
|
y: 0
|
||
|
|
},
|
||
|
|
activeIdx: 0,
|
||
|
2 years ago
|
showMembers: []
|
||
|
2 years ago
|
};
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
2 years ago
|
init() {
|
||
|
2 years ago
|
this.$refs.scrollBox.wrap.scrollTop = 0;
|
||
|
2 years ago
|
this.showMembers = [];
|
||
|
|
let userId = this.$store.state.userStore.userInfo.id;
|
||
|
|
let name = "全体成员";
|
||
|
|
if (this.ownerId == userId && name.startsWith(this.searchText)) {
|
||
|
|
this.showMembers.push({
|
||
|
|
userId: -1,
|
||
|
2 years ago
|
showNickName: name
|
||
|
2 years ago
|
})
|
||
|
|
}
|
||
|
|
this.members.forEach((m) => {
|
||
|
2 years ago
|
if (m.userId != userId && !m.quit && m.showNickName.startsWith(this.searchText)) {
|
||
|
2 years ago
|
this.showMembers.push(m);
|
||
|
|
}
|
||
|
|
})
|
||
|
2 years ago
|
this.activeIdx = this.showMembers.length > 0 ? 0: -1;
|
||
|
2 years ago
|
console.log(this.showMembers.length)
|
||
|
|
if(this.showMembers.length == 0){
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
2 years ago
|
},
|
||
|
|
open(pos) {
|
||
|
|
this.show = true;
|
||
|
|
this.pos = pos;
|
||
|
|
this.init();
|
||
|
|
},
|
||
|
|
close() {
|
||
|
|
this.show = false;
|
||
|
|
},
|
||
|
|
moveUp() {
|
||
|
|
if (this.activeIdx > 0) {
|
||
|
|
this.activeIdx--;
|
||
|
|
this.scrollToActive()
|
||
|
|
}
|
||
|
|
},
|
||
|
|
moveDown() {
|
||
|
|
if (this.activeIdx < this.showMembers.length - 1) {
|
||
|
|
this.activeIdx++;
|
||
|
|
this.scrollToActive()
|
||
|
|
}
|
||
|
|
},
|
||
|
|
select() {
|
||
|
2 years ago
|
if (this.activeIdx >= 0) {
|
||
|
|
this.onSelectMember(this.showMembers[this.activeIdx])
|
||
|
|
}
|
||
|
|
this.close();
|
||
|
2 years ago
|
},
|
||
|
|
scrollToActive() {
|
||
|
|
if (this.activeIdx * 35 - this.$refs.scrollBox.wrap.clientHeight > this.$refs.scrollBox.wrap.scrollTop) {
|
||
|
|
this.$refs.scrollBox.wrap.scrollTop += 140;
|
||
|
|
if (this.$refs.scrollBox.wrap.scrollTop > this.$refs.scrollBox.wrap.scrollHeight) {
|
||
|
|
this.$refs.scrollBox.wrap.scrollTop = this.$refs.scrollBox.wrap.scrollHeight
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (this.activeIdx * 35 < this.$refs.scrollBox.wrap.scrollTop) {
|
||
|
|
this.$refs.scrollBox.wrap.scrollTop -= 140;
|
||
|
|
if (this.$refs.scrollBox.wrap.scrollTop < 0) {
|
||
|
|
this.$refs.scrollBox.wrap.scrollTop = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
onSelectMember(member) {
|
||
|
|
this.$emit("select", member);
|
||
|
|
this.show = false;
|
||
|
|
}
|
||
|
|
},
|
||
|
2 years ago
|
computed: {
|
||
|
|
isOwner() {
|
||
|
|
return this.$store.state.userStore.userInfo.id == this.ownerId;
|
||
|
|
}
|
||
|
|
},
|
||
|
2 years ago
|
watch: {
|
||
|
|
searchText: {
|
||
|
|
handler(newText, oldText) {
|
||
|
|
this.init();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style scoped lang="scss">
|
||
|
|
.group-member-choose {
|
||
|
|
position: fixed;
|
||
|
|
width: 200px;
|
||
|
|
height: 300px;
|
||
|
2 years ago
|
border: 1px solid #53a0e79c;
|
||
|
2 years ago
|
border-radius: 5px;
|
||
|
|
background-color: #f5f5f5;
|
||
|
|
box-shadow: 0px 0px 10px #ccc;
|
||
|
|
}
|
||
|
|
</style>
|