index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!-- 检索列表页 - 职位检索 -->
  2. <template>
  3. <div class="default-width">
  4. <div class="py-3" style="z-index: 998; background-color: #fff">
  5. <div class="stickyBox">
  6. <headSearch
  7. v-model="headSearchText"
  8. text="中国"
  9. @handleSearch="val => handleQueryChange('content', val)"
  10. ></headSearch>
  11. </div>
  12. <cityFilter class="mx-5 mb-3" ref="cityFilterRef" @change="handleQueryChange"></cityFilter>
  13. <conditionFilter class="mx-5 mb-3" ref="conditionFilterRef" @change="handleQueryChange"></conditionFilter>
  14. </div>
  15. <div class="d-flex mt-3">
  16. <div class="mr-3" style="min-width: 884px;">
  17. <Empty v-if="!items?.length"></Empty>
  18. <PositionLongStrip v-else :items="items"></PositionLongStrip>
  19. </div>
  20. <rightRecommend></rightRecommend>
  21. </div>
  22. <CtPagination
  23. v-if="total > 0"
  24. :total="total"
  25. :page="pageInfo.pageNo"
  26. :limit="pageInfo.pageSize"
  27. @handleChange="handleChangePage"
  28. ></CtPagination>
  29. </div>
  30. </template>
  31. <script setup>
  32. import rightRecommend from './components/rightRecommend'
  33. import cityFilter from './components/cityFilter'
  34. import conditionFilter from './components/conditionFilter'
  35. import headSearch from '@/components/headSearch'
  36. import PositionLongStrip from '@/components/PositionLongStrip/item.vue'
  37. import Empty from '@/components/Empty'
  38. import { getJobAdvertisedSearch } from '@/api/position'
  39. import CtPagination from '@/components/CtPagination'
  40. import { provide, reactive, ref } from 'vue'
  41. import { dealDictObjData } from '@/views/recruit/position/components/dict'
  42. import { useRoute, useRouter } from 'vue-router'
  43. defineOptions({name: 'retrieval-position-page'})
  44. const route = useRoute(); const router = useRouter()
  45. const cityFilterRef = ref(); const conditionFilterRef = ref()
  46. const pageInfo = { pageNo: 1, pageSize: 20}
  47. const items = ref([])
  48. const total = ref(0)
  49. let routeQuery = (route?.query && route.query && Object.keys(route?.query).length) ? reactive(route.query) : reactive({})
  50. // if (routeQuery && Object.keys(routeQuery).length) {
  51. // if ()
  52. // }
  53. provide('routeQuery', routeQuery)
  54. const headSearchText = ref(routeQuery?.content || '')
  55. // 职位搜索
  56. const getData = async () => {
  57. const pageReqVO = { ...pageInfo }
  58. // route.query参数
  59. if (routeQuery && Object.keys(routeQuery).length) {
  60. const passingStrings = ['content'] // 传递字符串
  61. const passingOneId = ['positionId'] // 单选且传递整型
  62. Object.keys(routeQuery).forEach(key => {
  63. if (key === 'city') { // 工作地区id集合,示例值([])
  64. const city = routeQuery[key]
  65. const areaIds = []
  66. const levelCountArr = city.split('__')
  67. levelCountArr?.forEach(levelIds => {
  68. const idArr = levelIds.split('_')
  69. if (idArr?.length) {
  70. idArr.forEach(idItem => areaIds.push(idItem))
  71. }
  72. })
  73. pageReqVO.areaIds = areaIds
  74. }
  75. else if (passingStrings.includes(key)) pageReqVO[key] = routeQuery[key] // 传给后端字符串
  76. else if (passingOneId.includes(key)) pageReqVO[key] = +routeQuery[key] // 传给后端单选且传递整型
  77. else pageReqVO[key] = routeQuery[key].split('_') // 传给后端Arr
  78. })
  79. }
  80. console.log('getData参数pageReqVO', pageReqVO)
  81. const { list, total: number } = await getJobAdvertisedSearch(pageReqVO)
  82. items.value = list.map(e => {
  83. e.job = { ...e.job, ...dealDictObjData({}, e.job) }
  84. e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise) }
  85. return e
  86. })
  87. total.value = number
  88. }
  89. // 页面刷新
  90. if (routeQuery && Object.keys(routeQuery).length) getData()
  91. // 参数改变后刷新路由,触发数据刷新
  92. const updateRouter = () => {
  93. const str = Object.keys(routeQuery).length ? Object.keys(routeQuery).reduce((res, _key) => {
  94. if (routeQuery[_key] !== '') res += `${res ? '&' : ''}${_key}=${routeQuery[_key]}`
  95. return res
  96. }, '') : ''
  97. router.push(`${route.path}?${str}`)
  98. getData()
  99. }
  100. // 参数改变
  101. const handleQueryChange = (key, val) => { // val为字符串,数组的话用_下划线分隔
  102. routeQuery[key] = val
  103. updateRouter()
  104. }
  105. // 分页
  106. const handleChangePage = (index) => {
  107. pageInfo.pageNo = index
  108. getData()
  109. }
  110. </script>