index.vue 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <z-paging ref="paging" v-model="list" @query="handleQuery" @on-refresh="handleRefresh">
  3. <template #top>
  4. <mx-nav-bar title="职业库"/>
  5. <view class="px-20 py-10 bg-white">
  6. <mx-search v-model="name" placeholder="输入职业名称" @search="handleSearch" @clear="handleSearch"/>
  7. </view>
  8. <uv-line/>
  9. </template>
  10. <view v-for="(levelOne) in list" :class="levelOne.children ? 'mt-20 bg-white' : ''">
  11. <view v-if="levelOne.children">
  12. <view class="py-20 pl-30 text-lg font-bold">{{ levelOne.name }}</view>
  13. <view v-for="item in levelOne.children">
  14. <uv-cell :value="`${item.children.length}个职业`" @click="handleExpand(item)">
  15. <template #title>
  16. <view class="fx-row items-center">
  17. <uv-icon labelColor="black" :labelSize="12" name="arrow-right"
  18. :class="item.expand ? 'active expand' : 'expand'">
  19. </uv-icon>
  20. <text>{{ item.name }}</text>
  21. </view>
  22. </template>
  23. </uv-cell>
  24. <uv-transition :show="item.expand">
  25. <view class="bg-slate-100">
  26. <uv-cell v-for="last in item.children" class="text-main pl-40" :border="false" isLink
  27. :title="last.name" @click="goDetail(last)">
  28. </uv-cell>
  29. </view>
  30. </uv-transition>
  31. </view>
  32. </view>
  33. <uv-cell v-else class="text-main bg-white" :border="false" isLink
  34. :title="levelOne.name" @click="goDetail(levelOne)">
  35. </uv-cell>
  36. </view>
  37. </z-paging>
  38. </template>
  39. <script setup>
  40. import {ref} from 'vue';
  41. import {useCacheStore} from "@/hooks/useCacheStore";
  42. import {useTransfer} from "@/hooks/useTransfer";
  43. import {getAllVocation} from "@/api/webApi/collegemajor";
  44. const paging = ref(null)
  45. const list = ref([])
  46. const name = ref('')
  47. const {dispatchCache, removeCache} = useCacheStore()
  48. const {transferTo} = useTransfer()
  49. const handleSearch = () => paging.value.reload()
  50. const handleExpand = (item) => item.expand = !item.expand
  51. const handleRefresh = () => {
  52. removeCache(getAllVocation)
  53. }
  54. const handleQuery = () => {
  55. let payload = undefined
  56. if (name.value) payload = {name: name.value}
  57. dispatchCache(getAllVocation, payload)
  58. .then(res => {
  59. res.data.forEach(v => {
  60. if (v.children) {
  61. // 默认收起
  62. v.children.forEach(c => c.expand = false)
  63. }
  64. })
  65. paging.value.completeByNoMore(res.data, true)
  66. })
  67. .catch(e => paging.value.complete(false))
  68. }
  69. const goDetail = (item) => {
  70. transferTo('/pages/vocation-library/detail/detail', ['code'], item)
  71. }
  72. </script>
  73. <style scoped lang="scss">
  74. .expand {
  75. margin-right: 5px;
  76. }
  77. .active {
  78. transform: rotate(90deg);
  79. transition: transform 200ms;
  80. }
  81. </style>