index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 invite-modal">
  6. <div class="modal-hd">
  7. <!-- <div class="title">
  8. <i class="el-icon-close" @click="visible = false"></i>
  9. </div> -->
  10. <i class="el-icon-close" @click="visible = false"></i>
  11. </div>
  12. <div class="modal-bd clearfix">
  13. <div class="left">
  14. <div class="search-input">
  15. <input type="text" placeholder="搜索">
  16. <i class="el-icon-search"></i>
  17. </div>
  18. <div class="user-list select-list">
  19. <div class="user-item"
  20. v-for="(item, key) in checkList"
  21. :key="key"
  22. :class="{'checked': item.isChecked}"
  23. @click="changeState(key)">
  24. <img v-if="item.cover_photo" class="user-avatar" :src="item.cover_photo" alt="">
  25. <div v-else class="user-avatar"
  26. :class="`avatar_bg${item.user_id % 9}`"
  27. :data-name="item.nick_name.slice(0,2).toUpperCase()">
  28. </div>
  29. <span class="name">{{item.nick_name}}</span>
  30. <i v-if="item.isChecked" class="el-icon-circle-check"></i>
  31. <i v-else class="el-icon-circle-uncheck"></i>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="right">
  36. <p class="tips">请勾选需要添加的联系人</p>
  37. <div class="group-name">
  38. <input v-model="groupName" type="text" placeholder="请输入群名称">
  39. </div>
  40. <div class="user-list">
  41. <template v-for="(item, key) in checkList">
  42. <div class="user-item" :key="key" v-if="item.isChecked">
  43. <img v-if="item.cover_photo" class="user-avatar" :src="item.cover_photo" alt="">
  44. <div v-else class="user-avatar"
  45. :class="`avatar_bg${item.user_id % 9}`"
  46. :data-name="item.nick_name.slice(0,2).toUpperCase()">
  47. </div>
  48. <span class="name">{{item.nick_name}}</span>
  49. <i @click="changeState(key, false)" class="el-icon-circle-close"></i>
  50. </div>
  51. </template>
  52. </div>
  53. <div class="send-btn">
  54. <el-button @click="createGroup" type="primary">确认</el-button>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </transition>
  61. </template>
  62. <script>
  63. import { Button, Message } from 'element-ui'
  64. import Vue from 'vue'
  65. import { mapState } from 'vuex'
  66. import API from '@/api'
  67. Vue.component(Button.name, Button)
  68. export default {
  69. name: 'invitePopup',
  70. data () {
  71. return {
  72. checkList: [],
  73. groupName: ''
  74. }
  75. },
  76. computed: {
  77. ...mapState({
  78. friendList: state => state.chat.friendList
  79. }),
  80. inviteList () {
  81. return this.checkList.filter(v => {
  82. return v.isChecked
  83. }).map(v => v.user_id).join(',')
  84. }
  85. },
  86. methods: {
  87. changeState (ind, flag = null) {
  88. let item = this.checkList[ind]
  89. item['isChecked'] = flag || !item['isChecked']
  90. this.$set(this.checkList, ind, item)
  91. },
  92. async initList () {
  93. await this.$store.dispatch('getFriendList')
  94. this.checkList = this.friendList
  95. this.checkList.map(v => {
  96. v.isChecked = false
  97. })
  98. },
  99. createGroup () {
  100. if (this.groupName) {
  101. API.group.createGroup({
  102. group_title: this.groupName,
  103. user_id_list: this.inviteList
  104. }).then(({ data }) => {
  105. this.$showTips('创建成功')
  106. this.$store.commit('addSessionItem', data.data)
  107. this.visible = false
  108. })
  109. } else {
  110. Message({
  111. message: '请输入群名',
  112. type: 'warning'
  113. })
  114. }
  115. }
  116. },
  117. created () {
  118. this.initList()
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. @import "./style.scss";
  124. </style>