addressbook.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. <view style="padding: 20upx; background-color: white;">
  11. <u-search placeholder="部门" :clearabled="true" :showAction="false" v-model="officeName"></u-search>
  12. </view>
  13. <view style="padding: 20upx; background-color: white;">
  14. <u-search placeholder="手机号" :clearabled="true" :showAction="false" v-model="mobile"></u-search>
  15. </view>
  16. </u-sticky>
  17. <view>
  18. <u-index-list :indexList="indexList">
  19. <template v-for="(item, index) in list">
  20. <!-- #ifdef APP-NVUE -->
  21. <u-index-anchor :text="list[index].letter" :key="index"></u-index-anchor>
  22. <!-- #endif -->
  23. <u-index-item :key="index">
  24. <!-- #ifndef APP-NVUE -->
  25. <u-index-anchor :text="list[index].letter"></u-index-anchor>
  26. <!-- #endif -->
  27. <view class="list" v-for="(user, index1) in list[index].data" :key="index1">
  28. <!-- 检查user.name是否不等于"管理员" -->
  29. <view class="list__item" v-if="user.name !== '管理员'">
  30. <u-avatar shape="square" size="35" icon="account-fill" fontSize="26" randomBgColor></u-avatar>
  31. <!-- <view class="cu-avatar round " :style="'background-image:url('+(user.photo?user.photo:'/h5/static/user/flat-avatar.png')+');'"></view> -->
  32. <text class="list__item__user-name">{{user.name}}</text>
  33. <!-- 新增的展示其他信息的元素 -->
  34. <!-- 使用条件渲染检查 user.officeDTO.name 是否为 null -->
  35. <text class="list__item__additional-info" v-if="user.officeDTO">{{ user.officeDTO.name }}</text>
  36. <!-- 新的电话号码信息 -->
  37. <text class="list__item__phone-number">{{ user.mobile }}</text>
  38. </view>
  39. <u-line v-if="user.name !== '管理员'"></u-line>
  40. </view>
  41. </u-index-item>
  42. </template>
  43. <view style="font-size: 15px; color: gray; text-align: center; margin-top: 15px;">共{{total}}位好友</view>
  44. </u-index-list>
  45. <u-gap height="100" bgColor="#fff"></u-gap>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import userService from '@/api/sys/userService'
  51. export default {
  52. data() {
  53. return {
  54. indexList: [],
  55. userList: [],
  56. total: 0,
  57. searchUserName: '',
  58. officeName: '',
  59. mobile:''
  60. }
  61. },
  62. created() {
  63. userService.list({current: 1, size: 10000}).then((data)=>{
  64. this.userList = data.records
  65. this.total = data.total
  66. }).catch((e)=>{
  67. throw e
  68. })
  69. },
  70. computed: {
  71. list () {
  72. let resultList = this.userList.filter((item)=>{
  73. if(item.name.indexOf(this.searchUserName) >= 0){
  74. return true
  75. }
  76. })
  77. resultList = resultList.filter((item)=>{
  78. if(item.officeDTO && item.officeDTO.name){
  79. if(item.officeDTO.name.indexOf(this.officeName) >= 0){
  80. return true
  81. }
  82. }
  83. })
  84. resultList = resultList.filter((item)=>{
  85. if(item.mobile){
  86. if(item.mobile.indexOf(this.mobile) >= 0){
  87. return true
  88. }
  89. }
  90. })
  91. this.total = resultList.length
  92. return this.pySegSort(resultList)
  93. }
  94. },
  95. methods: {
  96. // 排序
  97. pySegSort(arr) {
  98. if(!String.prototype.localeCompare)
  99. return null;
  100. var letters = "0abcdefghjklmnopqrstwxyz".split('');
  101. var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
  102. var segs = [];
  103. this.indexList = [];
  104. var curr;
  105. letters.forEach((item,i) => {
  106. curr = {letter: item, data:[]};
  107. arr.forEach((item2) => {
  108. if((!zh[i-1] || zh[i-1].localeCompare(item2.name) <= 0) && item2.name.localeCompare(zh[i]) == -1) {
  109. curr.data.push(item2);
  110. }
  111. });
  112. if(curr.data.length) {
  113. segs.push(curr);
  114. this.indexList.push(curr.letter)
  115. curr.data.sort((a,b)=>{
  116. return a.name.localeCompare(b.name);
  117. });
  118. }
  119. });
  120. return segs;
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. .list {
  127. &__item {
  128. @include flex;
  129. padding: 6px 12px;
  130. align-items: center;
  131. &__avatar {
  132. height: 35px;
  133. width: 35px;
  134. border-radius: 3px;
  135. }
  136. &__user-name {
  137. font-size: 16px;
  138. margin-left: 10px;
  139. color: $u-main-color;
  140. }
  141. }
  142. &__footer {
  143. color: $u-tips-color;
  144. font-size: 14px;
  145. text-align: center;
  146. margin: 15px 0;
  147. }
  148. }
  149. .list__item__additional-info {
  150. position: relative;
  151. top: 10px; /* Adjust as needed */
  152. left: 15px; /* Adjust as needed */
  153. font-size: 12px; /* Adjust the font size as needed */
  154. color: #999; /* Adjust the color as needed */
  155. }
  156. .list__item__phone-number {
  157. position: relative;
  158. top: 10px; /* Adjust as needed */
  159. margin-left: 20px; /* 根据需要调整间距 */
  160. font-size: 12px; /* 根据需要调整字体大小 */
  161. color: #999; /* 根据需要调整颜色 */
  162. }
  163. </style>