users.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view>
  3. <view class="top">
  4. <u-search placeholder="输入姓名搜索" v-model="searchContent" @custom="search()" @search="search()"></u-search>
  5. </view>
  6. <scroll-view scroll-y class="indexes" :scroll-into-view="'indexes-'+ listCurID" :style="[{height:'calc(100vh - 88rpx)'}]"
  7. :scroll-with-animation="true" :enable-back-to-top="true">
  8. <view v-for="(item,index) in list" :key="index">
  9. <view :class="'indexItem-' + item.firstLetter" :id="'indexes-' + item.firstLetter" :data-index="item.firstLetter">
  10. <view class="zm">{{item.firstLetter}}</view>
  11. <view class="user-list">
  12. <view class="user-item" v-for="(subitem) in item.list" @click="navTo(subitem)" >
  13. <view class="avatar" >
  14. <image class="img" :src="subitem.avatar?(baseUrl+subitem.avatar):avatar" mode="aspectFill"></image>
  15. </view>
  16. <view class="content">
  17. <view class="name">
  18. {{subitem.nickName}}
  19. </view>
  20. <view class="dept">
  21. {{subitem.deptName}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. <view class="indexBar" :style="[{height:'calc(100vh - 88rpx)'}]">
  30. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  31. <view class="indexBar-item" v-for="(item,index) in list" :key="index" :id="index" @touchstart="getCur" @touchend="setCur"> {{item.firstLetter}}</view>
  32. </view>
  33. </view>
  34. <!--选择显示-->
  35. <view v-show="!hidden" class="indexToast">
  36. {{listCur}}
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {getAllUsers} from '@/api/user.js';
  42. export default {
  43. data() {
  44. return {
  45. baseUrl:uni.getStorageSync('requestPath'),
  46. avatar:"/static/images/default.png",
  47. CustomBar: 0,
  48. hidden: true,
  49. listCurID: '',
  50. list: [],
  51. listCur: '',
  52. searchContent:"",
  53. }
  54. },
  55. onLoad() {
  56. this.getUser();
  57. },
  58. onReady() {
  59. let that = this;
  60. uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  61. that.boxTop = res.top
  62. }).exec();
  63. uni.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  64. that.barTop = res.top
  65. }).exec()
  66. },
  67. methods: {
  68. getUser(){
  69. var data = {searchKey:this.searchContent};
  70. var that=this;
  71. getAllUsers(data).then(
  72. res => {
  73. if(res.code==200){
  74. that.list=res.users;
  75. }
  76. },
  77. rej => {}
  78. );
  79. },
  80. //获取文字信息
  81. getCur(e) {
  82. this.hidden = false;
  83. this.listCur = this.list[e.target.id].firstLetter;
  84. },
  85. setCur(e) {
  86. this.hidden = true;
  87. this.listCur = this.listCur
  88. },
  89. //滑动选择Item
  90. tMove(e) {
  91. let y = e.touches[0].clientY,
  92. offsettop = this.boxTop,
  93. that = this;
  94. //判断选择区域,只有在选择区才会生效
  95. if (y > offsettop) {
  96. let num = parseInt((y - offsettop) / 20);
  97. console.log(num);
  98. if(num<that.list.length){
  99. this.listCur = that.list[num].firstLetter
  100. }
  101. };
  102. },
  103. //触发全部开始选择
  104. tStart() {
  105. this.hidden = false
  106. },
  107. //触发结束选择
  108. tEnd() {
  109. this.hidden = true;
  110. this.listCurID = this.listCur
  111. },
  112. indexSelect(e) {
  113. let that = this;
  114. let barHeight = this.barHeight;
  115. let list = this.list;
  116. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  117. for (let i = 0; i < list.length; i++) {
  118. if (scrollY < i + 1) {
  119. that.listCur = list[i].firstLetter;
  120. that.movableY = i * 20
  121. return false
  122. }
  123. }
  124. },
  125. navTo(subitem){
  126. uni.navigateTo({
  127. url: './userInfo?userId='+subitem.userId
  128. })
  129. },
  130. search(){
  131. this.getUser()
  132. }
  133. }
  134. }
  135. </script>
  136. <style >
  137. page {
  138. }
  139. .top{
  140. height: 88rpx;
  141. background-color: #fff;
  142. padding: 0rpx 15rpx;
  143. }
  144. .indexes {
  145. position: relative;
  146. }
  147. .indexBar {
  148. position: fixed;
  149. right: 0px;
  150. bottom: 0px;
  151. padding: 20upx 20upx 20upx 60upx;
  152. display: flex;
  153. align-items: center;
  154. }
  155. .indexBar .indexBar-box {
  156. width: 40upx;
  157. height: auto;
  158. background: #fff;
  159. display: flex;
  160. flex-direction: column;
  161. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  162. border-radius: 10upx;
  163. }
  164. .indexBar-item {
  165. flex: 1;
  166. width: 40upx;
  167. height: 40upx;
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. font-size: 24upx;
  172. color: #888;
  173. }
  174. movable-view.indexBar-item {
  175. width: 40upx;
  176. height: 40upx;
  177. z-index: 9;
  178. position: relative;
  179. }
  180. movable-view.indexBar-item::before {
  181. content: "";
  182. display: block;
  183. position: absolute;
  184. left: 0;
  185. top: 10upx;
  186. height: 20upx;
  187. width: 4upx;
  188. background-color: #f37b1d;
  189. }
  190. .indexToast {
  191. position: fixed;
  192. top: 0;
  193. right: 80upx;
  194. bottom: 0;
  195. background: rgba(0, 0, 0, 0.5);
  196. width: 100upx;
  197. height: 100upx;
  198. border-radius: 10upx;
  199. margin: auto;
  200. color: #fff;
  201. line-height: 100upx;
  202. text-align: center;
  203. font-size: 48upx;
  204. }
  205. .zm{
  206. height:50rpx;
  207. padding: 0rpx 20rpx;
  208. }
  209. .user-list{
  210. background-color: #fff;
  211. }
  212. .user-item{
  213. padding: 15rpx;
  214. width: 100%;
  215. display: flex;
  216. align-items: center;
  217. justify-content: flex-start;
  218. border-bottom: 1px solid #f7f7f7;
  219. }
  220. .user-item .avatar{
  221. width: 100upx;
  222. height: 100upx;
  223. }
  224. .user-item .avatar .img{
  225. border-radius: 50%;
  226. width: 100%;
  227. height: 100%;
  228. }
  229. .user-item .content{
  230. margin-left: 15rpx;
  231. }
  232. .user-item .content .name{
  233. font-size: 26rpx;
  234. color: #111;
  235. }
  236. .user-item .content .dept{
  237. font-size: 24rpx;
  238. color: #888;
  239. margin-top: 15rpx;
  240. }
  241. </style>