similar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view>
  3. <view class="box defaultBgc">
  4. <scroll-view class="scrollBox" :scroll-y="true" :scroll-top="scrollTop" @scrolltolower="loadingMore" @scroll="onScroll" style="position:relative;">
  5. <PositionList :list="positionListData" :noMore="false"></PositionList>
  6. <uni-load-more :status="more" />
  7. </scroll-view>
  8. </view>
  9. </view>
  10. </template>
  11. <script setup>
  12. import { ref, reactive } from 'vue'
  13. import PositionList from '@/components/PositionList'
  14. import { dealDictArrayData } from '@/utils/position'
  15. import { getSimilarPosition } from '@/api/position'
  16. const props = defineProps({
  17. id: String
  18. })
  19. const more = ref('more')
  20. const total = ref(0)
  21. const positionListData = ref([])
  22. const query = reactive({
  23. pageSize: 10,
  24. pageNo: 1,
  25. id: props.id
  26. })
  27. console.log(props.id, '==================')
  28. const getData = async () => {
  29. try {
  30. const res = await getSimilarPosition(query)
  31. const arr = res?.data?.list || []
  32. // 推荐接口返回数据需要拼接
  33. const list = arr
  34. positionListData.value.push(...dealDictArrayData(list))
  35. total.value = res?.data?.total || 0
  36. if (positionListData.value.length === total.value) {
  37. more.value = 'noMore'
  38. return
  39. }
  40. } catch (error) {
  41. query.pageNo--
  42. more.value = 'more'
  43. }
  44. }
  45. const scrollTop = ref(0)
  46. const old = ref({
  47. scrollTop: 0
  48. })
  49. const onScroll = (e) =>{
  50. old.value.scrollTop = e.detail.scrollTop
  51. }
  52. // 加载更多
  53. const loadingMore = () => {
  54. if (total.value <= 0) return
  55. more.value = 'loading'
  56. query.pageNo++
  57. getData()
  58. }
  59. </script>
  60. <style scoped lang="scss">
  61. .stick {
  62. z-index: 1;
  63. position: sticky;
  64. top: 0;
  65. }
  66. .stickFilter {
  67. z-index: 1;
  68. position: sticky;
  69. box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
  70. top: 120rpx;
  71. }
  72. .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
  73. .pb-10 {
  74. padding-bottom: 10px;
  75. }
  76. .pb-20 { padding-bottom: 20px; }
  77. .px-5 { padding-left: 5px; padding-right: 5px; }
  78. .px-10 { padding-left: 10px; padding-right: 10px; }
  79. .mx-10 { margin-left: 10px; margin-right: 10px }
  80. .mx-20 { margin-left: 20px; margin-right: 20px; }
  81. .mb-10 { margin-bottom: 10px; }
  82. .box {
  83. height: 100vh;
  84. overflow: hidden;
  85. padding-bottom: 120rpx;
  86. box-sizing: border-box;
  87. display: flex;
  88. flex-direction: column;
  89. }
  90. .scrollBox{
  91. flex: 1;
  92. height: 0 !important;
  93. padding-bottom: 24rpx;
  94. box-sizing: border-box;
  95. }
  96. :deep(.uni-searchbar__box) {
  97. width: calc(100% - 105px);
  98. height: 40px !important;
  99. border: 1px solid #00B760;
  100. padding-right: 20px;
  101. flex: none;
  102. }
  103. .search-btn {
  104. position: absolute;
  105. right: 11px;
  106. top: 10px;
  107. width: 110px;
  108. height: 40px;
  109. font-size: 16px;
  110. background-color: #00B760;
  111. color: #fff;
  112. border-radius: 0 5px 5px 0;
  113. z-index: 9;
  114. }
  115. :deep(.picker-view) {
  116. padding-bottom: 80px !important;
  117. }
  118. </style>