add-group-member.vue
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div class="friend-item-container">
<el-row v-for="friend in currentUnMemberList" :key="friend.id" style="margin-bottom: 5px" class="friend-list"
type="flex" align="middle" justify="center" :gutter="16">
<el-col :span="6">
<avatar class="friend-avatar" :src="friend.avatar"/>
</el-col>
<el-col :span="14">
<div class="friend-name">{{ friend.name }}</div>
</el-col>
<el-col :span="4">
<div class="btn-add-member" :title="`添加:${friend.name}`" @click="addGroupMember(friend)">
<span class="tim-icon-friend-add"></span>
</div>
</el-col>
</el-row>
</div>
</template>
<script>
import {mapState} from 'vuex'
import Helper from '../../../utils/helper'
export default {
computed: {
...mapState({
users: state => state.friend.userList,
currentConversation: state => state.conversation.currentConversation,
currentMemberList: state => state.group.currentMemberList
}),
currentUnMemberList() {
return this.users.filter(item => this.currentMemberList.filter(data => data.userID === item.esm_id).length === 0)
}
},
methods: {
addGroupMember(user) {
const groupID = this.currentConversation.conversationID.replace('GROUP', '')
Helper.joinGroup(groupID, user.esm_id).then(() => {
this.$store.commit('showMessage', {message: `群成员:${user.name},加群成功`, type: 'success'})
this.tim.getGroupMemberProfile({groupID, userIDList: [user.esm_id]})
.then(({data: {memberList}}) => this.$store.commit('updateCurrentMemberList', memberList))
})
// this.tim
// .addGroupMember({
// groupID,
// userIDList: [userID]
// })
// .then((imResponse) => {
// const {
// successUserIDList,
// failureUserIDList,
// existedUserIDList
// } = imResponse.data
// if (successUserIDList.length > 0) {
// this.$store.commit('showMessage', {message: `群成员:${successUserIDList.join(',')},加群成功`, type: 'success'})
// this.tim.getGroupMemberProfile({groupID, userIDList: successUserIDList})
// .then(({data: {memberList}}) => this.$store.commit('updateCurrentMemberList', memberList))
// }
// if (failureUserIDList.length > 0) {
// this.$store.commit('showMessage', {message: `群成员:${failureUserIDList.join(',')},添加失败!`, type: 'error'})
// }
// if (existedUserIDList.length > 0) {
// this.$store.commit('showMessage', {message: `群成员:${existedUserIDList.join(',')},已在群中`})
// }
// })
// .catch(error => {
// this.$store.commit('showMessage', {type: 'error', message: error.message})
// })
}
}
}
</script>
<style lang="stylus" scoped>
.btn-add-member
width 30px
height 30px
font-size 28px
text-align center
line-height 32px
cursor pointer
float right
&:hover
color $light-primary
</style>