index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <transition name="msgbox-fade">
  3. <div class="pub-wrapper" v-if="visible">
  4. <div class="pub-mask"></div>
  5. <div class="pub-modal avater-modal">
  6. <div class="modal-hd">
  7. <i class="el-icon-close" @click="visible = false"></i>
  8. </div>
  9. <div class="modal-bd" v-if="userInfo">
  10. <div class="user-top">
  11. <div class="user-avatar">
  12. <img v-if="userInfo.cover_photo" :src="userInfo.cover_photo" alt="">
  13. <div v-else class="user-avatar"
  14. :class="'avatar_bg' + userInfo.user_id % 9"
  15. :data-name="userInfo.nick_name.slice(0,2).toUpperCase()"
  16. ></div>
  17. </div>
  18. <div class="r-info">
  19. <span class="name">{{userInfo.nick_name}}</span>
  20. <div class="introduce">@{{userInfo.user_id}}</div>
  21. </div>
  22. </div>
  23. <div class="account-wrap min-height-account">
  24. <div class="title">已绑定账户</div>
  25. <template v-if="accountList">
  26. <div class="account-item" v-for="(item, key) in accountList" :key="key">
  27. <div class="type">
  28. <strong>{{item.type.toUpperCase()}}</strong>
  29. </div>
  30. <p v-if="item.account && item.is_visible" class="key">{{item.account}}</p>
  31. <p v-else>未绑定或已隐藏</p>
  32. </div>
  33. </template>
  34. </div>
  35. <button v-if="$store.state.userId != userId" class="send-msg-btn" @click="sendMsg">发消息</button>
  36. </div>
  37. </div>
  38. </div>
  39. </transition>
  40. </template>
  41. <script>
  42. import { Button, Message, Switch } from 'element-ui'
  43. import Vue from 'vue'
  44. import { mapState } from 'vuex'
  45. import API from '@/api'
  46. Vue.component(Button.name, Button)
  47. Vue.component(Message.name, Message)
  48. Vue.component(Switch.name, Switch)
  49. export default {
  50. name: 'infoPopup',
  51. data () {
  52. return {
  53. accountList: null,
  54. userInfo: null
  55. }
  56. },
  57. computed: {
  58. ...mapState({
  59. members: state => state.group.members,
  60. sessionList: state => state.chat.sessionList,
  61. meId: state => state.userId,
  62. meInfo: state => state.userInfo
  63. })
  64. },
  65. methods: {
  66. sendMsg () {
  67. let youId = this.userInfo.user_id
  68. let sessionId = Number(youId) < Number(this.meId)
  69. ? `${youId}-${this.meId}`
  70. : `${this.meId}-${youId}`
  71. let repeatFlag = false
  72. this.sessionList.forEach(e => {
  73. if (e.session_id === sessionId) {
  74. repeatFlag = true
  75. }
  76. })
  77. if (!repeatFlag) {
  78. let obj = {
  79. cover_photo: this.userInfo.cover_photo,
  80. is_group: '0',
  81. name: this.userInfo.nick_name,
  82. // read_hash:null
  83. session_id: sessionId
  84. }
  85. this.$store.commit('addSessionItem', obj)
  86. }
  87. // 创建members,应对还没聊天记录的情况
  88. let myId = this.meInfo.user_id
  89. let members = {}
  90. members[myId] = {
  91. cover_photo: this.meInfo.cover_photo,
  92. nick_name: this.meInfo.nick_name
  93. }
  94. members[this.userInfo.user_id] = {
  95. cover_photo: this.userInfo.cover_photo,
  96. nick_name: this.userInfo.nick_name
  97. }
  98. this.$store.commit('updateGroup', {
  99. key: 'members',
  100. data: members
  101. })
  102. this.$store.commit('updateGroup', {
  103. key: 'privateName',
  104. data: this.userInfo.nick_name
  105. })
  106. this.$store.commit('changeSessionId', sessionId)
  107. this.visible = false
  108. }
  109. },
  110. created () {
  111. this.userInfo = this.members[this.userId]
  112. API.user.getOtherInfo({
  113. user_id: this.userId
  114. }).then(({ data }) => {
  115. this.accountList = data.data.binds
  116. })
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. @import "./style.scss";
  122. .min-height-account{
  123. min-height: 218px;
  124. }
  125. </style>