addressbook.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-blue">
  4. <block slot="content">通讯录</block>
  5. </cu-custom>
  6. <u-sticky>
  7. <view style="padding: 20upx; background-color: white;">
  8. <u-search placeholder="输入搜索的关键词" :clearabled="true" :showAction="false" v-model="searchUserName"></u-search>
  9. </view>
  10. </u-sticky>
  11. <view>
  12. <u-index-list :indexList="indexList">
  13. <template v-for="(item, index) in list">
  14. <!-- #ifdef APP-NVUE -->
  15. <u-index-anchor :text="list[index].letter" :key="index"></u-index-anchor>
  16. <!-- #endif -->
  17. <u-index-item :key="index">
  18. <!-- #ifndef APP-NVUE -->
  19. <u-index-anchor :text="list[index].letter"></u-index-anchor>
  20. <!-- #endif -->
  21. <view class="list" v-for="(user, index1) in list[index].data" :key="index1">
  22. <!-- 检查user.name是否不等于"管理员" -->
  23. <view class="list__item" v-if="user.name !== '管理员' || user.name !== 'admin'">
  24. <u-avatar shape="square" size="35" icon="account-fill" fontSize="26" randomBgColor></u-avatar>
  25. <!-- <view class="cu-avatar round " :style="'background-image:url('+(user.photo?user.photo:'/h5/static/user/flat-avatar.png')+');'"></view> -->
  26. <text class="list__item__user-name">{{user.name}}</text>
  27. <!-- 新增的展示其他信息的元素 -->
  28. <!-- 使用条件渲染检查 user.officeDTO.name 是否为 null -->
  29. <text class="list__item__additional-info" v-if="user.officeDTO">{{ user.officeDTO.name }}</text>
  30. <!-- 新的电话号码信息 -->
  31. <text class="list__item__phone-number">{{ user.mobile }}</text>
  32. </view>
  33. <u-line v-if="user.name !== '管理员'"></u-line>
  34. </view>
  35. </u-index-item>
  36. </template>
  37. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{total}}位好友</view>
  38. </u-index-list>
  39. <u-gap height="100" bgColor="#fff"></u-gap>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import userService from '@/api/sys/userService'
  45. export default {
  46. data() {
  47. return {
  48. indexList: [],
  49. userList: [],
  50. total: 0,
  51. searchUserName: ''
  52. }
  53. },
  54. created() {
  55. userService.list({current: 1, size: 10000}).then((data)=>{
  56. this.userList = data.records
  57. this.total = data.total
  58. }).catch((e)=>{
  59. throw e
  60. })
  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. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .list {
  103. &__item {
  104. @include flex;
  105. padding: 6px 12px;
  106. align-items: center;
  107. &__avatar {
  108. height: 35px;
  109. width: 35px;
  110. border-radius: 3px;
  111. }
  112. &__user-name {
  113. font-size: 16px;
  114. margin-left: 10px;
  115. color: $u-main-color;
  116. }
  117. }
  118. &__footer {
  119. color: $u-tips-color;
  120. font-size: 14px;
  121. text-align: center;
  122. margin: 15px 0;
  123. }
  124. }
  125. .list__item__additional-info {
  126. position: relative;
  127. top: 10px; /* Adjust as needed */
  128. left: 15px; /* Adjust as needed */
  129. font-size: 12px; /* Adjust the font size as needed */
  130. color: #999; /* Adjust the color as needed */
  131. }
  132. .list__item__phone-number {
  133. position: relative;
  134. top: 10px; /* Adjust as needed */
  135. margin-left: 20px; /* 根据需要调整间距 */
  136. font-size: 12px; /* 根据需要调整字体大小 */
  137. color: #999; /* 根据需要调整颜色 */
  138. }
  139. </style>