index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <layout-page>
  3. <uni-segmented-control :current="current" class="MiSans-Normal" :values="controlListText" @clickItem="handleChange" styleType="text" activeColor="#00B760"></uni-segmented-control>
  4. <scroll-view class="scrollBox defaultBgc" scroll-y="true" @scrolltolower="loadingMore" style="height: calc(100vh - 72rpx);">
  5. <view v-if="items.length" class="listBox">
  6. <m-list :items="items"></m-list>
  7. <uni-load-more :status="more" />
  8. </view>
  9. <view v-else class="nodata-img-parent">
  10. <image
  11. src="https://minio.citupro.com/dev/static/nodata.png"
  12. mode="widthFix"
  13. style="width: 100vw"
  14. ></image>
  15. </view>
  16. </scroll-view>
  17. </layout-page>
  18. </template>
  19. <script setup>
  20. import { ref, watch } from 'vue'
  21. import layoutPage from '@/layout'
  22. import MList from './list'
  23. import { getDict } from '@/hooks/useDictionaries.js'
  24. import { getRecommendationList } from '@/api/position.js'
  25. import { onLoad } from '@dcloudio/uni-app'
  26. import { userStore } from '@/store/user'
  27. const useUserStore = userStore()
  28. watch(() => useUserStore.refreshToken, (newVal, oldVal) => {
  29. if (useUserStore.refreshToken) {
  30. // 监听登录状态
  31. console.log('重新登录了')
  32. handleChange({ currentIndex: current.value })
  33. }
  34. })
  35. const current = ref(0)
  36. // 获取参数
  37. const controlList = ref([])
  38. const controlListText = ref([])
  39. const pageInfo = ref({
  40. pageNo: 1,
  41. pageSize: 10
  42. })
  43. const total = ref(0)
  44. const items = ref([])
  45. const loading = ref(false)
  46. const more = ref('more')
  47. async function initDict () {
  48. try {
  49. const { data } = await getDict('menduner_hire_job_cv_status')
  50. if (!data?.data) {
  51. return
  52. }
  53. controlList.value = data.data
  54. controlListText.value = data.data.map(e => e.label)
  55. // current.value = +controlList.value[0].value
  56. init()
  57. } catch (error) {
  58. // console.log(error)
  59. }
  60. }
  61. function handleChange (val) {
  62. current.value = val.currentIndex
  63. pageInfo.value.pageNo = 1
  64. total.value = 0
  65. items.value = []
  66. init()
  67. }
  68. function loadingMore () {
  69. if (total.value === items.value.length) {
  70. return
  71. }
  72. if (loading.value) {
  73. return
  74. }
  75. more.value = 'loading'
  76. pageInfo.value.pageNo++
  77. init()
  78. }
  79. async function init () {
  80. try {
  81. loading.value = true
  82. const { data } = await getRecommendationList({
  83. ...pageInfo.value,
  84. status: current.value
  85. })
  86. if (!data?.list) {
  87. pageInfo.value.pageNo--
  88. return
  89. }
  90. items.value.push(...data.list)
  91. total.value = +data.total
  92. more.value = items.value.length === total.value ? 'noMore' : 'more'
  93. } catch (error) {
  94. pageInfo.value.pageNo--
  95. } finally {
  96. loading.value = false
  97. }
  98. }
  99. onLoad(async (options) => {
  100. if (options?.id) {
  101. current.value = +options.id
  102. }
  103. initDict()
  104. })
  105. </script>
  106. <style lang="scss" scoped>
  107. </style>