address_book.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框区域 -->
  4. <common-search placeholder="请输入校友姓名" @change="handleChange"></common-search>
  5. <!-- 分段器区域 -->
  6. <view class="control">
  7. <common-controlTag :tagList="tagList" rangekey="name" @change="changeIndex"></common-controlTag>
  8. </view>
  9. <!-- 列表区域 -->
  10. <view class="list">
  11. <!-- 每一条通讯录区域 -->
  12. <view class="list_box" v-for="item in dataList" :key="item.id">
  13. <view class="box">
  14. <view class="box_key">学院和班级:</view>
  15. <view class="box_value">{{ item.collegeName }}</view>
  16. </view>
  17. <view class="box">
  18. <view class="box_key">联系人:</view>
  19. <view class="box_value">{{ item.name }}</view>
  20. </view>
  21. <view class="box" v-if="item.orgName">
  22. <view class="box_key">组织:</view>
  23. <view class="box_value">{{ item.orgName }}</view>
  24. </view>
  25. <view class="box" v-if="item.phone">
  26. <view class="box_key">联系方式:</view>
  27. <view class="box_value" @click="clickPhone(item.phone)">{{ item.phone }}</view>
  28. <uni-icons type="phone" size="20" color="#007AFF" @click="clickPhone(item.phone)"></uni-icons>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 没有数据时展示的页面 -->
  33. <noData v-if="!dataList.length"></noData>
  34. </view>
  35. </template>
  36. <script setup>
  37. import { onLoad, onReachBottom } from '@dcloudio/uni-app'
  38. import { ref } from 'vue'
  39. import { getAddressBookType, getAddressBookData } from '@/api/index.js'
  40. // 分段器数组
  41. const tagList = ref([])
  42. // 分段器当前索引
  43. const currentIndex = ref(0)
  44. // 搜索框绑定数据
  45. const inputValue = ref('')
  46. // 当前页
  47. const currentPage = ref(1)
  48. // 每页多少条
  49. const pageCount = ref(6)
  50. // 总条数
  51. const total = ref(0)
  52. // 数据列表
  53. const dataList = ref([])
  54. onLoad(() => {
  55. // 获取通讯录类型列表
  56. getType()
  57. })
  58. // 页面触底触发的函数
  59. onReachBottom(() => {
  60. if (total.value > dataList.value.length) {
  61. currentPage.value++
  62. getData()
  63. } else {
  64. uni.showToast({
  65. title: '没有更多数据了~~',
  66. icon: 'none'
  67. })
  68. }
  69. })
  70. // 获取通讯录类型列表
  71. const getType = async () => {
  72. const res = await getAddressBookType()
  73. // console.log(res)
  74. tagList.value = res.data
  75. // 获取通讯录分页数据
  76. getData()
  77. }
  78. // 获取通讯录分页数据
  79. const getData = async () => {
  80. let data = {
  81. currentPage: currentPage.value,
  82. pageCount: pageCount.value,
  83. typeId: tagList.value[currentIndex.value].id,
  84. name: inputValue.value
  85. }
  86. const res = await getAddressBookData(data)
  87. // console.log(res)
  88. dataList.value = [...dataList.value, ...res.data.list]
  89. total.value = res.data.totalCount
  90. }
  91. // 输入框搜索回调
  92. const handleChange = (e) => {
  93. inputValue.value = e
  94. currentPage.value = 1
  95. dataList.value = []
  96. getData()
  97. }
  98. // 切换分段器时的回调
  99. const changeIndex = (e) => {
  100. if (currentIndex.value != e) {
  101. currentIndex.value = e
  102. currentPage.value = 1
  103. dataList.value = []
  104. getData()
  105. }
  106. }
  107. // 拨打电话回调
  108. const clickPhone = (phoneNumber) => {
  109. uni.makePhoneCall({
  110. phoneNumber
  111. })
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .container {
  116. padding: 20rpx 18rpx;
  117. min-height: 100vh;
  118. .control {
  119. margin-top: 20rpx;
  120. }
  121. .list {
  122. margin-top: 20rpx;
  123. font-size: 28rpx;
  124. .list_box {
  125. display: flex;
  126. flex-direction: column;
  127. justify-content: space-between;
  128. padding: 30rpx;
  129. margin-bottom: 20rpx;
  130. width: 714rpx;
  131. border-radius: 28rpx;
  132. box-shadow: 0 4rpx 34rpx rgba(211, 211, 211, 0.32);
  133. .box {
  134. display: flex;
  135. margin-bottom: 20rpx;
  136. .box_key {
  137. font-weight: bold;
  138. }
  139. .box_value {
  140. flex: 1;
  141. margin-right: 10rpx;
  142. color: #666666;
  143. overflow: hidden;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. </style>