index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <style>
  2. .search{background: #fff;border-radius: 6px;margin: 0px 10px;padding: 10px;}
  3. .search image{width: 30px;height: 30px;}
  4. .search input{font-size: 14px;}
  5. .search-view .lists{margin-top: 10px;}
  6. .search-view .lists .item{background: #fff;padding:0 10px;position: relative;}
  7. .search-view .lists .item:active{background: #f1f1f1;}
  8. .search-view .lists .item image{width: 40px;height: 40px;border-radius: 50%;}
  9. .search-view .lists .item .info{width: calc(100% - 70px);margin-left: 10px;font-size: 14px;color:#787878;border-bottom: 1px solid #f1f1f1;height: 60px;}
  10. .search-view .lists .item .flg{background: #ff5857;width: 20px;height: 20px;border-radius: 50%;font-size: 10px;text-align: center;line-height: 20px;color: #fff;}
  11. .search-view .lists .item:last-child .info{border-bottom: 0;}
  12. .search-view .letter{padding: 10px;}
  13. .SideMenu {
  14. position: fixed;
  15. top: 50%;
  16. right: 0;
  17. padding: 20rpx 0rpx;
  18. width: 45rpx;
  19. transform: translate(0,-50%);
  20. z-index: 1;
  21. }
  22. .SideMenu view {
  23. height: 30rpx;
  24. display: block;
  25. padding: 4rpx 0;
  26. wdith:45rpx;
  27. color: #000;
  28. text-align: center;
  29. font-size: 22rpx;
  30. }
  31. .foot-value{height:60px;line-height: 60px;font-size: 14px;text-align: center;color:#787878;}
  32. </style>
  33. <template>
  34. <view class="app">
  35. <uni-nav-bar statusBar backgroundColor="transparent" fixed title="我的好友" left-icon="left" @clickLeft="utils.navigateBack()" />
  36. <view class="search fx-r fx-bc">
  37. <image src="/static/chat/tb-seach.png"></image>
  38. <input @input="tapKeyWord" class="fx-g1" type="text" placeholder="搜索联系人" />
  39. </view>
  40. <scroll-view class="search-view" :style="'height: calc(100% - 80px)'" scroll-y :scroll-into-view="toView" scroll-with-animation='true' show-scrollbar="false" >
  41. <view class="lists">
  42. <view class="item fx-r fx-bc" v-for="(item,index) in sysData.serviceAr">
  43. <image src="/static/chat/ic_customer_chat.png" mode="widthFix"></image>
  44. <view class="info fx-h fx-ac">
  45. <view class="title">官方客服{{index + 1}}</view>
  46. </view>
  47. </view>
  48. <view v-for="(item,index) in letter">
  49. <view class="letter" :id="'letter_' + item.letter">{{item.letter}}</view>
  50. <view class="item fx-r fx-bc" @tap="tapOpen" :data-url="'info?usercode=' + item2.f_uid" v-for="(item2,index2) in item.data">
  51. <image :src="item2.avatar == '' ? '/static/img/user-avatar1.png' : item2.avatar" mode="aspectFill"></image>
  52. <view class="info fx-h fx-ac">
  53. <rich-text class="title" :nodes="getRanValue(item2.remark || item2.nickname)"></rich-text>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="foot-value">{{count}}个朋友</view>
  58. </view>
  59. </scroll-view>
  60. <view class="SideMenu" >
  61. <view @tap="tapOpenLetter(item.letter)" v-for="(item, index) in letter"> {{item.letter}} </view>
  62. </view>
  63. <view class="choice" v-if="isChoice">{{choice}}</view>
  64. </view>
  65. </template>
  66. <script>
  67. import {mapState,mapMutations} from 'vuex';
  68. var LetterList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','#'];
  69. export default {
  70. computed: mapState(['user','sysData']),
  71. data() {
  72. return {
  73. dataAr : [],
  74. letter : [],
  75. count : 0,
  76. keyword : "",
  77. isChoice : false,
  78. choice : "",
  79. toView:""
  80. }
  81. },
  82. onLoad() {
  83. },
  84. onShow() {
  85. this.checkUserLogin({
  86. page:this,isLogin:true,fn:this.initView
  87. })
  88. },
  89. methods: {
  90. ...mapMutations(['checkUserLogin','setSys']),
  91. /**
  92. *
  93. */
  94. initView:function(){
  95. this
  96. .request
  97. .get("FriendIndex")
  98. .then(res=>{
  99. if(res.code == 200) {
  100. this.dataAr = res.data;
  101. this.letterView();
  102. } else {
  103. this.utils.showModal(res.msg);
  104. }
  105. });
  106. },
  107. /**
  108. * 检索关键词
  109. */
  110. tapKeyWord:function(ev){
  111. this.keyword = ev.detail.value;
  112. this.letterView();
  113. },
  114. //字母
  115. letterView:function(){
  116. var tAr = {};
  117. for(var i in LetterList) {
  118. var letter = LetterList[i];
  119. for(var j in this.dataAr) {
  120. var jAr = this.dataAr[j];
  121. if(jAr.letter == letter && (jAr.nickname.indexOf(this.keyword) >= 0 || jAr.remark.indexOf(this.keyword) >= 0 )) {
  122. if(tAr[letter] != null) {
  123. tAr[letter].data.push(jAr);
  124. } else {
  125. tAr[letter] = {'letter':letter,'data':[jAr]};
  126. }
  127. }
  128. }
  129. }
  130. var count = 0;
  131. var nAr = [];
  132. for(var j in tAr) {
  133. nAr.push(tAr[j]);
  134. count += tAr[j].data.length;
  135. }
  136. this.letter = nAr;
  137. this.count = count;
  138. },
  139. /**
  140. * 遍历字符串
  141. */
  142. getRanValue:function(str) {
  143. let value = str;
  144. if (value.indexOf(this.keyword)!==-1) {
  145. let reg = new RegExp(this.keyword, 'gi')
  146. return value.replace(reg, `<font style="color:#2fbec0">${this.keyword}</font>`)
  147. } else {
  148. return value
  149. }
  150. },
  151. /**
  152. * 打开字母
  153. */
  154. tapOpenLetter:function(item){
  155. this.isChoice = true;
  156. this.choice = item;
  157. setTimeout(()=>{this.isChoice = false;},500);
  158. this.toView = "letter_" + item;
  159. },
  160. /**
  161. * 打开
  162. * @param {Object} ev
  163. */
  164. tapOpen: function(ev) {
  165. let url = ev.currentTarget.dataset.url;
  166. this.utils.navigateTo(url);
  167. },
  168. }
  169. }
  170. </script>
  171. <style>
  172. .app{width: 100vw;height: 100vh;}
  173. /* #ifdef H5 */
  174. .app{height: calc(100vh - 95px);}
  175. /* #endif */
  176. .app-run .text{font-size: 24px;font-weight: bold;color: #737373;}
  177. .choice {
  178. width: 110rpx;
  179. height: 110rpx;
  180. position: fixed;
  181. top: 40%;
  182. left: 50%;
  183. transform: translate(-50%,-50%);
  184. background: rgba(0,0,0,0.3);
  185. color: #fff;
  186. border-radius: 20rpx;
  187. text-align: center;
  188. line-height: 110rpx;
  189. font-size: 45rpx;
  190. z-index: 2;
  191. }
  192. </style>