index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="contact_container">
  3. <uv-index-list :index-list="indexList">
  4. <template v-for="(items, index) in itemArr" :key="index">
  5. <uv-index-item>
  6. <uv-index-anchor :text="indexList[index]" size="16"></uv-index-anchor>
  7. <view class="chat_list">
  8. <uni-list :border="true">
  9. <uni-list-chat v-for="(item, index) in items" @click="clickChat(item)" :title="item.name"
  10. :avatar="item.avatar || config.baseUrlPre+config.defaultAvatarPath" :note="item.desktop_phone" :clickable="true"
  11. :avatar-circle="true" :key="index">
  12. <view class="chat-custom-right">
  13. <text class="chat-custom-text" v-text="item.dept"></text>
  14. </view>
  15. </uni-list-chat>
  16. </uni-list>
  17. </view>
  18. </uv-index-item>
  19. </template>
  20. </uv-index-list>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { onMounted, ref } from 'vue'
  25. import $tab from '@/plugins/tab.js'
  26. import { getContactAllUser } from '@/api/contacts.js'
  27. import { useUserStore } from '@/store/user.js'
  28. import { onShow } from '@dcloudio/uni-app'
  29. import config from '@/config';
  30. const userStore = useUserStore()
  31. onMounted(() => {
  32. // 获取 通讯录 索引列表
  33. let unitId = userStore.user.unitId
  34. if ( unitId === 0 ) unitId = userStore.user.groupid
  35. // getContactAllUser(userStore.user.groupid).then(res => {
  36. getContactAllUser(unitId).then(res => {
  37. getContactList(res.returnParams)
  38. })
  39. })
  40. onShow(()=>{
  41. uni.$emit('showTabBarBadge')
  42. })
  43. // 索引列表
  44. const indexList = ref([])
  45. const itemArr = ref([])
  46. function getContactList(data) {
  47. for (let key in data) {
  48. // hasOwnProperty 排除 __proto__等数据
  49. if (data.hasOwnProperty(key)) {
  50. // 过滤 userState 为 0 的 user
  51. data[key] = data[key].filter(user => user.userState !== '0' && user.name.slice(-3) !== '管理员')
  52. } else {
  53. continue
  54. }
  55. // 删除 过滤后 数据为0的 索引
  56. if (data[key].length === 0) delete data[key]
  57. }
  58. // 获取索引
  59. indexList.value = Object.keys(data)
  60. // 获取索引数据
  61. itemArr.value = Object.values(data)
  62. }
  63. // function clickTop() {
  64. // console.log('clickTop');
  65. // }
  66. // 点击通讯录列表
  67. function clickChat(e) {
  68. $tab.navigateTo('/pages/mine/personal_message/personal_message?useId=' + e.useId)
  69. }
  70. </script>
  71. <style lang="scss">
  72. .contact_container {
  73. .top {
  74. .top_slot_container {
  75. height: 100%;
  76. width: 100%;
  77. ::v-deep .uni-icons {
  78. background-color: #468bf0;
  79. border-radius: 50%;
  80. }
  81. .top_text {
  82. font-size: 24px;
  83. }
  84. }
  85. }
  86. .chat_list {
  87. .chat-custom-right {
  88. .chat-custom-text {
  89. margin-right: 10px;
  90. }
  91. }}
  92. }
  93. </style>