index.client.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="">
  3. <van-sticky :offset-top="50">
  4. <van-dropdown-menu ref="menuRef">
  5. <van-dropdown-item :title="currentAreaFilterLabel" ref="areaFilterRef">
  6. <van-tree-select
  7. height="340px"
  8. v-model:active-id="activeCountryId"
  9. v-model:main-active-index="activeAreaIndex"
  10. :items="areaOptions"
  11. @click-nav="handleAreaClick"
  12. @click-item="handleCountryClick"
  13. />
  14. </van-dropdown-item>
  15. </van-dropdown-menu>
  16. </van-sticky>
  17. <van-empty
  18. v-if="!listData.length && !loading"
  19. image="search"
  20. description="暂无相关旅游项目"
  21. />
  22. <div class="px-15" v-else-if="listData.length">
  23. <van-list
  24. class=""
  25. v-model:loading="loading"
  26. :finished="finished"
  27. finished-text="-- 没有更多了 --"
  28. @load="onLoadMore"
  29. :immediate-check="false"
  30. >
  31. <TravelProjectItem
  32. v-for="item in listData"
  33. :key="item.id"
  34. :item-data="item"
  35. >
  36. </TravelProjectItem>
  37. </van-list>
  38. </div>
  39. </div>
  40. </template>
  41. <script setup>
  42. const currentArea = ref({});
  43. const currentCountry = ref({});
  44. const currentAreaFilterLabel = computed(() => {
  45. if (!currentArea.value?.id) {
  46. return "全部区域";
  47. }
  48. return `${currentArea.value.text || ""}${currentCountry.value.text || ""}`;
  49. });
  50. const requestQuery = reactive({
  51. pageNum: 1,
  52. pageSize: 10,
  53. areaId: computed(() => currentArea.value?.id ?? ""),
  54. countryId: computed(() => currentCountry.value?.id ?? ""),
  55. });
  56. const listData = ref([]);
  57. const loading = ref(false);
  58. const finished = ref(false);
  59. async function getList() {
  60. loading.value = true;
  61. const { data } = await request("/website/tourism/project/list", {
  62. query: requestQuery,
  63. });
  64. listData.value = listData.value.concat(data.dataList);
  65. loading.value = false;
  66. if (data.totalCount <= listData.value.length) {
  67. finished.value = true;
  68. }
  69. }
  70. function onLoadMore() {
  71. requestQuery.pageNum++;
  72. getList();
  73. }
  74. // 地区筛选
  75. const areaFilterRef = ref(null);
  76. const activeAreaIndex = ref(0);
  77. const activeCountryId = ref(0);
  78. const areaOptions = ref([]);
  79. function handleAreaClick(index) {
  80. activeCountryId.value = null;
  81. if (index === 0) {
  82. currentArea.value = areaOptions.value[index];
  83. currentCountry.value = {};
  84. areaFilterRef.value.toggle();
  85. reSearch();
  86. }
  87. }
  88. function handleCountryClick(item) {
  89. currentArea.value = areaOptions.value[activeAreaIndex.value];
  90. currentCountry.value = item;
  91. areaFilterRef.value.toggle();
  92. reSearch();
  93. }
  94. function reSearch() {
  95. requestQuery.pageNum = 1;
  96. listData.value = [];
  97. getList();
  98. }
  99. async function getFilterAddress() {
  100. const { data } = await request(
  101. "/website/tourism/projectTravelNotes/travelNotesDirectoryList"
  102. );
  103. data.forEach((item) => {
  104. item.text = item.areaName;
  105. item.id = item.areaId;
  106. item.children.forEach((subItem) => {
  107. subItem.text = subItem.countryName;
  108. subItem.id = subItem.countryId;
  109. });
  110. item.children.unshift({ text: "全部", id: "" });
  111. });
  112. data.unshift({ text: "全部", id: "" });
  113. areaOptions.value = data;
  114. }
  115. onMounted(() => {
  116. getList();
  117. getFilterAddress();
  118. });
  119. </script>
  120. <style lang="scss" scoped>
  121. :deep(.van-tree-select__item) {
  122. font-weight: normal;
  123. }
  124. </style>