position.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="box defaultBgc">
  3. <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="loadingMore" style="position:relative;">
  4. <view>
  5. <view class="white-bgc stick">
  6. <uni-search-bar
  7. v-model="query.content"
  8. radius="8"
  9. placeholder="请输入关键字"
  10. cancelButton="none"
  11. :focus="false"
  12. @confirm="onSearch($event.value)"
  13. @clear="query.content = ''; onSearch()"
  14. />
  15. </view>
  16. <SwiperAd :list="swiperAdList"></SwiperAd>
  17. <view class="white-bgc px-10 mb-10 stickFilter">
  18. <FilterList :list="filterList" idValue="label" @change="handleSearch"></FilterList>
  19. </view>
  20. <PositionList :list="positionListData" :noMore="false"></PositionList>
  21. <uni-load-more :status="more" />
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </template>
  26. <script setup>
  27. import SwiperAd from '@/components/SwiperAd'
  28. import FilterList from '@/components/FilterList'
  29. import PositionList from '@/components/PositionList'
  30. import { swiperAdListTest } from '@/utils/testData'
  31. import { dealDictObjData } from '@/utils/position'
  32. import { getJobAdvertisedSearch } from '@/api/position';
  33. import { onShow } from '@dcloudio/uni-app'
  34. import { ref, reactive } from 'vue'
  35. // 设置自定义tabbar选中值
  36. onShow(() => {
  37. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  38. const currentTabBar = currentPage?.getTabBar?.();
  39. // 设置当前tab页的下标index
  40. currentTabBar?.setData({ selected: 0 });
  41. })
  42. const more = ref('more')
  43. const swiperAdList = ref(swiperAdListTest)
  44. const filterList = ref([
  45. { label: '城市', dictType: 'areaTreeData', key: 'areaIds', map: { text: 'name', value: 'id' } },
  46. { label: '行业', dictType: 'industryTreeData',key: 'industryIds', map: { text: 'nameCn', value: 'id' } },
  47. { label: '求职类型', dictType: 'menduner_job_type', key: 'jobType' },
  48. { label: '薪资待遇', dictType: 'menduner_pay_scope', key: 'payScope' },
  49. { label: '工作经验', dictType: 'menduner_exp_type', key: 'expType' },
  50. ])
  51. //
  52. const positionListData = ref([])
  53. const query = reactive({
  54. pageSize: 20,
  55. pageNo: 1,
  56. content: '',
  57. areaIds: [],
  58. industryIds: [],
  59. jobType: [],
  60. payScope: [],
  61. expType: []
  62. })
  63. //
  64. const getData = async () => {
  65. try {
  66. const res = await getJobAdvertisedSearch(query)
  67. const list = res?.data?.list || []
  68. positionListData.value.push(...list.map(e => {
  69. if (!e) {
  70. return e
  71. }
  72. e.job = { ...e.job, ...dealDictObjData({}, e.job) }
  73. e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise)}
  74. return e
  75. }))
  76. if (positionListData.value.length === +res.data.total) {
  77. more.value = 'noMore'
  78. return
  79. }
  80. } catch (error) {
  81. query.pageNo--
  82. more.value = 'more'
  83. }
  84. }
  85. getData()
  86. const handleSearch = (key, value) => {
  87. query[key] = value ? [value] : []
  88. onSearch()
  89. }
  90. const onSearch = () => {
  91. query.pageNo = 1
  92. positionListData.value = []
  93. getData()
  94. }
  95. const loadingMore = () => { // 加载更多
  96. more.value = 'loading'
  97. query.pageNo++
  98. getData()
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .stick {
  103. z-index: 1;
  104. position: sticky;
  105. top: 0;
  106. }
  107. .stickFilter {
  108. z-index: 1;
  109. position: sticky;
  110. box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
  111. top: 112rpx;
  112. }
  113. .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
  114. .pb-10 {
  115. padding-bottom: 10px;
  116. }
  117. .pb-20 { padding-bottom: 20px; }
  118. .px-5 { padding-left: 5px; padding-right: 5px; }
  119. .px-10 { padding-left: 10px; padding-right: 10px; }
  120. .mx-10 { margin-left: 10px; margin-right: 10px }
  121. .mx-20 { margin-left: 20px; margin-right: 20px; }
  122. .mb-10 { margin-bottom: 10px; }
  123. .box {
  124. height: 100vh;
  125. overflow: hidden;
  126. padding-bottom: 120rpx;
  127. // box-sizing: border-box;
  128. // padding-bottom: 160rpx;
  129. box-sizing: border-box;
  130. display: flex;
  131. flex-direction: column;
  132. }
  133. .scrollBox{
  134. // height: 100%;
  135. flex: 1;
  136. height: 0 !important;
  137. padding-bottom: 24rpx;
  138. box-sizing: border-box;
  139. // padding-bottom: 160rpx;
  140. }
  141. </style>