addressbook.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. </view>
  27. <u-line></u-line>
  28. </view>
  29. </u-index-item>
  30. </template>
  31. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{total}}位好友</view>
  32. </u-index-list>
  33. <u-gap height="100" bgColor="#fff"></u-gap>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import userService from '@/api/sys/userService'
  39. export default {
  40. data() {
  41. return {
  42. indexList: [],
  43. userList: [],
  44. total: 0,
  45. searchUserName: ''
  46. }
  47. },
  48. created() {
  49. userService.list({current: 1, size: 10000}).then((data)=>{
  50. this.userList = data.records
  51. this.total = data.total
  52. }).catch((e)=>{
  53. throw e
  54. })
  55. },
  56. computed: {
  57. list () {
  58. let resultList = this.userList.filter((item)=>{
  59. if(item.name.indexOf(this.searchUserName) >= 0){
  60. return true
  61. }
  62. })
  63. return this.pySegSort(resultList)
  64. }
  65. },
  66. methods: {
  67. // 排序
  68. pySegSort(arr) {
  69. if(!String.prototype.localeCompare)
  70. return null;
  71. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  72. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  73. var segs = [];
  74. var curr;
  75. letters.forEach((item,i) => {
  76. curr = {letter: item, data:[]};
  77. arr.forEach((item2) => {
  78. if((!zh[i-1] || zh[i-1].localeCompare(item2.name) <= 0) && item2.name.localeCompare(zh[i]) == -1) {
  79. curr.data.push(item2);
  80. }
  81. });
  82. if(curr.data.length) {
  83. segs.push(curr);
  84. this.indexList.push(curr.letter)
  85. curr.data.sort((a,b)=>{
  86. return a.name.localeCompare(b.name);
  87. });
  88. }
  89. });
  90. return segs;
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. .list {
  97. &__item {
  98. @include flex;
  99. padding: 6px 12px;
  100. align-items: center;
  101. &__avatar {
  102. height: 35px;
  103. width: 35px;
  104. border-radius: 3px;
  105. }
  106. &__user-name {
  107. font-size: 16px;
  108. margin-left: 10px;
  109. color: $u-main-color;
  110. }
  111. }
  112. &__footer {
  113. color: $u-tips-color;
  114. font-size: 14px;
  115. text-align: center;
  116. margin: 15px 0;
  117. }
  118. }
  119. </style>