user.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="app">
  3. <view class="top" id="app-top">
  4. <view class="search-view fx-h fx-bc fx-ac">
  5. <u--input
  6. placeholder="搜索联系人"
  7. prefixIcon="search"
  8. clearable
  9. border="none"
  10. prefixIconStyle="font-size: 22px;color: #909399"
  11. v-model="popKeyword"
  12. @input="tapPopKeyWord"
  13. ></u--input>
  14. </view>
  15. </view>
  16. <view class="pop-win-scroll">
  17. <view class="item fx-r fx-bc" @tap="tapItem(item)" v-for="(item,index) in data">
  18. <image :src="item.avatar == '' ? '/static/chat/user-avatar.png' : item.avatar" mode="aspectFill"></image>
  19. <view class="info fx-h fx-ac">
  20. <rich-text class="nickname" :nodes="getRanValue(item.nickname)"></rich-text>
  21. <view class="manager" v-if="item.is_manager">群主</view>
  22. <view class="admin" v-else-if="item.is_admin">管理</view>
  23. </view>
  24. </view>
  25. <view class="loading fx-r fx-ac fx-bc" v-if="page.isFrite && !page.isFoot">
  26. <image src="/static/chat/xloading.png"></image>
  27. <text>正在载入更多...</text>
  28. </view>
  29. <view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
  30. </view>
  31. </view>
  32. </template>
  33. <style>
  34. .top{background: #F8F6F6;position: fixed;z-index: 99;width: 100%;}
  35. .search-view{background: #fff;margin-top: 1px;padding: 10px;margin: 10px;border-radius: 6px;}
  36. .search-view .u-input{width: 100%;}
  37. .pop-win-scroll{ padding-top: 60px;}
  38. .pop-win-scroll .item{background: #fff;padding:10px 10px;position: relative;}
  39. .pop-win-scroll .item:active{background: #f1f1f1;}
  40. .pop-win-scroll .item image{width: 40px;height: 40px;border-radius: 50%;}
  41. .pop-win-scroll .item .info{width: calc(100% - 70px);padding: 10px 0;margin-left: 10px;font-size: 14px;color:#787878;border-bottom: 1px solid #f1f1f1;}
  42. .pop-win-scroll .item .info .title{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;}
  43. .pop-win-scroll .item .flg{background: #ff5857;width: 20px;height: 20px;border-radius: 50%;font-size: 10px;text-align: center;line-height: 20px;color: #fff;}
  44. .pop-win-scroll .item:last-child .info{border-bottom: 0;}
  45. .pop-win-scroll .letter{padding: 10px;background: #F8F6F6;}
  46. .manager{border: 1px solid #faac06;border-radius: 6px;font-size: 10px;padding:0px 6px;color: #faac06;background: #fff;width: 30px;text-align: center;}
  47. .admin{border: 1px solid #2fbec0;border-radius: 6px;font-size: 10px;padding:0px 6px;color: #2fbec0;background: #fff;width: 30px;text-align: center;}
  48. </style>
  49. <script>
  50. import {mapState,mapMutations } from 'vuex';
  51. export default {
  52. computed: mapState(['user','sysData']),
  53. data() {
  54. return {
  55. barheight : 40,
  56. toView : "",
  57. data : [],
  58. tvData : [],
  59. groupId : 0,
  60. popKeyword : "",
  61. mbAr : {},
  62. page:{
  63. isFirst:false,
  64. isLoad:false,
  65. isFoot:false,
  66. page:1
  67. }
  68. }
  69. },
  70. onLoad(option){
  71. this.$nextTick(() => {
  72. uni.createSelectorQuery().select("#app-top").boundingClientRect(res=>{
  73. this.barheight = res.height;
  74. }).exec();
  75. });
  76. this.groupId = option.groupId;
  77. this.getData();
  78. },
  79. onReachBottom() {
  80. if(this.page.isFoot || this.page.isLoad) {
  81. return;
  82. }
  83. this.page.page ++;
  84. this.getData();
  85. },
  86. methods: {
  87. tapPopKeyWord:function(ev){
  88. this.page = {page:1,isLoad:false,isFoot:false};
  89. if(this.mbAr[this.popKeyword] != null) {
  90. this.data = this.mbAr[this.popKeyword];
  91. } else {
  92. this.getData(true);
  93. }
  94. },
  95. getData:function(isPull = false){
  96. this
  97. .request
  98. .post("chatGroupUser",{groupId : this.groupId,page : this.page.page,keyword : this.popKeyword})
  99. .then(res=>{
  100. if(res.code == 200) {
  101. this.page.isFrite = true;
  102. this.page.isLoad = false;
  103. if(isPull) {
  104. this.data = res.data.list;
  105. } else {
  106. this.data = this.data.concat(res.data.list);
  107. }
  108. //是否到底
  109. if(res.data.list.length != res.data.pageSize) {
  110. this.page.isFoot = true;
  111. }
  112. if(this.page.page == 1 && this.popKeyword != ''){
  113. this.mbAr[this.popKeyword] = res.data.list;
  114. }
  115. //this.tapPopKeyWord();
  116. } else {
  117. uni.showModal({title: '系统提示',content:res.msg,showCancel: false});
  118. }
  119. });
  120. },
  121. /**
  122. * 搜索聊天信息
  123. * @param {Object} item
  124. */
  125. tapItem:function(item){
  126. uni.navigateTo({
  127. url: 'msgView?groupId=' + this.groupId + '&usercode=' + item.uid
  128. })
  129. },
  130. /**
  131. * 遍历字符串
  132. */
  133. getRanValue:function(str) {
  134. let value = str;
  135. if (value.indexOf(this.popKeyword)!==-1) {
  136. let reg = new RegExp(this.popKeyword, 'gi')
  137. return value.replace(reg, `<font style="color:#2fbec0">${this.popKeyword}</font>`)
  138. } else {
  139. return value
  140. }
  141. },
  142. }
  143. }
  144. </script>