addressbook.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <view class="list__item">
  23. <u-avatar shape="square" size="35" icon="account-fill" fontSize="26" randomBgColor></u-avatar>
  24. <!-- <view class="cu-avatar round " :style="'background-image:url('+(user.photo?user.photo:'/h5/static/user/flat-avatar.png')+');'"></view> -->
  25. <text class="list__item__user-name">{{user.name}}</text>
  26. <!-- 部门名称 -->
  27. <text class="list__item__additional-info">{{ user.officeDTO.name }}</text>
  28. <!-- 电话号码信息 -->
  29. <text class="list__item__phone-number">{{ user.mobile }}</text>
  30. </view>
  31. <u-line></u-line>
  32. </view>
  33. </u-index-item>
  34. </template>
  35. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{total}}位好友</view>
  36. </u-index-list>
  37. <u-gap height="100" bgColor="#fff"></u-gap>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import userService from '@/api/sys/userService'
  43. export default {
  44. data() {
  45. return {
  46. indexList: [],
  47. userList: [],
  48. total: 0,
  49. searchUserName: ''
  50. }
  51. },
  52. created() {
  53. userService.list({current: 1, size: 10000}).then((data)=>{
  54. this.userList = data.records
  55. this.total = data.total
  56. }).catch((e)=>{
  57. throw e
  58. })
  59. },
  60. computed: {
  61. list () {
  62. let resultList = this.userList.filter((item)=>{
  63. if(item.name.indexOf(this.searchUserName) >= 0){
  64. return true
  65. }
  66. })
  67. return this.pySegSort(resultList)
  68. }
  69. },
  70. methods: {
  71. // 排序
  72. pySegSort(arr) {
  73. if(!String.prototype.localeCompare)
  74. return null;
  75. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  76. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  77. var segs = [];
  78. var curr;
  79. letters.forEach((item,i) => {
  80. curr = {letter: item, data:[]};
  81. arr.forEach((item2) => {
  82. if((!zh[i-1] || zh[i-1].localeCompare(item2.name) <= 0) && item2.name.localeCompare(zh[i]) == -1) {
  83. curr.data.push(item2);
  84. }
  85. });
  86. if(curr.data.length) {
  87. segs.push(curr);
  88. this.indexList.push(curr.letter)
  89. curr.data.sort((a,b)=>{
  90. return a.name.localeCompare(b.name);
  91. });
  92. }
  93. });
  94. return segs;
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss">
  100. .list {
  101. &__item {
  102. @include flex;
  103. padding: 6px 12px;
  104. align-items: center;
  105. &__avatar {
  106. height: 35px;
  107. width: 35px;
  108. border-radius: 3px;
  109. }
  110. &__user-name {
  111. font-size: 16px;
  112. margin-left: 10px;
  113. color: $u-main-color;
  114. }
  115. }
  116. &__footer {
  117. color: $u-tips-color;
  118. font-size: 14px;
  119. text-align: center;
  120. margin: 15px 0;
  121. }
  122. }
  123. .list__item__additional-info {
  124. position: relative;
  125. top: 10px; /* Adjust as needed */
  126. left: 15px; /* Adjust as needed */
  127. font-size: 12px; /* Adjust the font size as needed */
  128. color: #999; /* Adjust the color as needed */
  129. }
  130. .list__item__phone-number {
  131. position: relative;
  132. top: 10px; /* Adjust as needed */
  133. margin-left: 20px; /* 根据需要调整间距 */
  134. font-size: 12px; /* 根据需要调整字体大小 */
  135. color: #999; /* 根据需要调整颜色 */
  136. }
  137. </style>