index.vue 3.0 KB

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