addGroupUser.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="content-addGroupUser">
  3. <u-navbar :is-back="true" title="选择好友" :background="{ background: '#F6F7F8' }" title-color="#404133" :border-bottom="false"
  4. z-index="1001">
  5. <view class="slot-wrap" slot="right">
  6. <u-button size="mini" type="success" @click="saveGroupMember">保存</u-button>
  7. </view>
  8. </u-navbar>
  9. <view class="list-search">
  10. <u-search v-model="keyword" placeholder="搜索" shape="square" :show-action="false" :bg-color="'#ffffff'"></u-search>
  11. </view>
  12. <u-index-list class="list-box" :scrollTop="scrollTop" :indexList="indexList">
  13. <view class="list-wrap" v-if="item.members.length" v-for="(item, index) in fList" :key="index">
  14. <u-index-anchor :index="item.name" />
  15. <u-checkbox-group style="width: 100%;">
  16. <view class="member-list u-border-bottom list-cell" v-for="(user, jndex) in item.members" :key="jndex">
  17. <u-checkbox @change="checkboxChange(user)" v-model="user.checked" :name="user.id">
  18. <u-avatar class="my-avatar" :src="user.avatar" mode="square" size="60"></u-avatar>
  19. </u-checkbox>
  20. {{ user.nickName }}
  21. </view>
  22. </u-checkbox-group>
  23. </view>
  24. </u-index-list>
  25. </view>
  26. </template>
  27. <script>
  28. import chatItem from '../../components/chatItem.vue'
  29. import searchInput from '@/components/searchInput/index.vue';
  30. export default {
  31. components: {
  32. searchInput
  33. },
  34. data() {
  35. return {
  36. scrollTop: 0,
  37. indexList: [],
  38. ids: [],
  39. userNames: [],
  40. fList: [],
  41. keyword: '',
  42. $url:''
  43. }
  44. },
  45. onShow() {
  46. this.queryGuests();
  47. },
  48. onLoad(option) {},
  49. watch: {
  50. keyword: function(val) {
  51. let arr = this.firendList;
  52. if (val != '') {
  53. this.fList = arr.filter(v => {
  54. let flag = false
  55. if (v.members.length > 0) {
  56. v.members.forEach(m => {
  57. if (m.nickName.includes(val)) {
  58. flag = true
  59. }
  60. })
  61. }
  62. return flag
  63. })
  64. } else {
  65. this.fList = this.firendList
  66. }
  67. }
  68. },
  69. methods: {
  70. saveGroupMember() {
  71. let type = this.$route.query.type
  72. if (type === '1') {
  73. let defaultGroupName = this.userNames.length > 8 ? this.userNames.substr(0, 8) + '...' : this.userNames
  74. this.$socket.createGroup(this.ids, defaultGroupName, this.userData.user.operId, res => {
  75. if (res.success) {
  76. this.$u.route({
  77. url: 'pages/home/home'
  78. });
  79. }
  80. });
  81. }
  82. if (type === '2') {
  83. this.$socket.joinGroup(this.chatObj.chatId, this.ids, this.userData.user.username, res => {
  84. if (res.success) {
  85. this.$u.route({
  86. url: 'pages/chat/groupDetail'
  87. });
  88. }
  89. });
  90. }
  91. },
  92. checkboxChange(user) {
  93. if (user.checked) {
  94. this.ids.push(user.id);
  95. this.userNames.push(user.chatName);
  96. } else {
  97. this.ids.splice(this.ids.indexOf(user.id), 1);
  98. this.userNames.splice(this.userNames.indexOf(user.chatName), 1);
  99. }
  100. },
  101. queryGuests() {
  102. this.$socket.listGuests(this.userData.user.operId, res => {
  103. this.$u.vuex('firendItem', res.response.data);
  104. this.fList = res.response.data
  105. let indexList = []
  106. this.fList.forEach(item => {
  107. indexList.push(item.name)
  108. })
  109. this.indexList = indexList
  110. });
  111. },
  112. linkToCard({
  113. id
  114. }) {
  115. this.$u.route({
  116. url: 'pageC/businessCard/businessCard',
  117. params: {
  118. id: id,
  119. source: 1
  120. }
  121. });
  122. }
  123. },
  124. onPageScroll(e) {
  125. this.scrollTop = e.scrollTop;
  126. }
  127. };
  128. </script>
  129. <style lang="scss">
  130. .content-addGroupUser {
  131. height: 100%;
  132. .list-search {
  133. padding: 0 24rpx;
  134. margin-top: 24rpx;
  135. }
  136. /deep/.u-index-anchor {
  137. background: #F6F7F8;
  138. }
  139. /deep/.u-checkbox__label {
  140. display: flex;
  141. }
  142. .list-wrap {
  143. display: flex;
  144. flex-direction: column;
  145. box-sizing: border-box;
  146. width: 100%;
  147. overflow: hidden;
  148. color: #323233;
  149. font-size: 14px;
  150. line-height: 24px;
  151. background-color: #fff;
  152. }
  153. .member-list {
  154. padding: 24rpx;
  155. display: flex;
  156. align-items: center;
  157. }
  158. .u-checkbox-group {
  159. flex-direction: column;
  160. }
  161. }
  162. </style>