UserPullForm.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view>
  3. <u-sticky>
  4. <view style="padding: 20upx; background-color: white;">
  5. <u-search placeholder="输入搜索的关键词" :clearabled="true" :showAction="false" v-model="searchUserName"></u-search>
  6. </view>
  7. </u-sticky>
  8. <view>
  9. <u-index-list :indexList="indexList">
  10. <template v-for="(item, index) in list">
  11. <!-- #ifdef APP-NVUE -->
  12. <u-index-anchor :text="list[index].letter" :key="index"></u-index-anchor>
  13. <!-- #endif -->
  14. <u-index-item :key="index">
  15. <!-- #ifndef APP-NVUE -->
  16. <u-index-anchor :text="list[index].letter"></u-index-anchor>
  17. <!-- #endif -->
  18. <view class="list" v-for="(user, index1) in list[index].data" :key="index1">
  19. <view class="list__item">
  20. <u-avatar shape="square" size="35" icon="account-fill" fontSize="26" randomBgColor></u-avatar>
  21. <!-- <view class="cu-avatar round " :style="'background-image:url('+(user.photo?user.photo:'/h5/static/user/flat-avatar.png')+');'"></view> -->
  22. <text class="list__item__user-name" @click="selectUser(user)">{{user.name}}</text>
  23. <!-- 新增的展示其他信息的元素 -->
  24. <text class="list__item__additional-info">{{ user.officeDTO.name }}</text>
  25. <!-- 新的电话号码信息 -->
  26. <text class="list__item__phone-number">{{ user.mobile }}</text>
  27. </view>
  28. <u-line></u-line>
  29. </view>
  30. </u-index-item>
  31. </template>
  32. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{total}}位好友</view>
  33. </u-index-list>
  34. <u-gap height="100" bgColor="#fff"></u-gap>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import userService from '@/api/sys/userService'
  40. export default {
  41. data() {
  42. return {
  43. indexList: [],
  44. userList: [],
  45. total: 0,
  46. searchUserName: '',
  47. index: ''
  48. }
  49. },
  50. created() {
  51. userService.list({current: 1, size: 10000}).then((data)=>{
  52. this.userList = data.records
  53. this.total = data.total
  54. }).catch((e)=>{
  55. throw e
  56. })
  57. },
  58. onLoad(options) {
  59. // 从 URL 参数中获取传递过来的index
  60. this.index = options.index;
  61. },
  62. computed: {
  63. list () {
  64. let resultList = this.userList.filter((item)=>{
  65. if(item.name.indexOf(this.searchUserName) >= 0){
  66. return true
  67. }
  68. })
  69. return this.pySegSort(resultList)
  70. }
  71. },
  72. methods: {
  73. // 排序
  74. pySegSort(arr) {
  75. if(!String.prototype.localeCompare)
  76. return null;
  77. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  78. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  79. var segs = [];
  80. var curr;
  81. letters.forEach((item,i) => {
  82. curr = {letter: item, data:[]};
  83. arr.forEach((item2) => {
  84. if((!zh[i-1] || zh[i-1].localeCompare(item2.name) <= 0) && item2.name.localeCompare(zh[i]) == -1) {
  85. curr.data.push(item2);
  86. }
  87. });
  88. if(curr.data.length) {
  89. segs.push(curr);
  90. this.indexList.push(curr.letter)
  91. curr.data.sort((a,b)=>{
  92. return a.name.localeCompare(b.name);
  93. });
  94. }
  95. });
  96. return segs;
  97. },
  98. selectUser(user) {
  99. // 当用户点击某个用户时触发的方法
  100. // 这里可以处理所选用户的信息并将其传递回原页面
  101. user.index = this.index
  102. uni.navigateBack({
  103. delta: 1,
  104. success() {
  105. uni.$emit('eventName', user); // 通过事件向上一页传递数据
  106. }
  107. });
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss">
  113. .list {
  114. &__item {
  115. @include flex;
  116. padding: 6px 12px;
  117. align-items: center;
  118. &__avatar {
  119. height: 35px;
  120. width: 35px;
  121. border-radius: 3px;
  122. }
  123. &__user-name {
  124. font-size: 16px;
  125. margin-left: 10px;
  126. color: $u-main-color;
  127. }
  128. }
  129. &__footer {
  130. color: $u-tips-color;
  131. font-size: 14px;
  132. text-align: center;
  133. margin: 15px 0;
  134. }
  135. }
  136. .list__item__additional-info {
  137. position: relative;
  138. top: 10px; /* Adjust as needed */
  139. left: 15px; /* Adjust as needed */
  140. font-size: 12px; /* Adjust the font size as needed */
  141. color: #999; /* Adjust the color as needed */
  142. }
  143. .list__item__phone-number {
  144. position: relative;
  145. top: 10px; /* Adjust as needed */
  146. margin-left: 20px; /* 根据需要调整间距 */
  147. font-size: 12px; /* 根据需要调整字体大小 */
  148. color: #999; /* 根据需要调整颜色 */
  149. }
  150. </style>