DestinationPage.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <q-page>
  3. <div class="row justify-center text-blue-6 text-h4 q-pt-xl">
  4. {{ $t("seasonal_recommendation") }}
  5. </div>
  6. <div class="row justify-center q-mt-md">
  7. <q-input
  8. class="col-12 col-sm-8 col-md-6"
  9. rounded
  10. dense
  11. outlined
  12. v-model="query"
  13. @update:model-value="(val) => updateQuery(val)"
  14. :label="$t('search_by_title')"
  15. />
  16. </div>
  17. <div class="row justify-left">
  18. <div
  19. class="col-12 col-sm-4 col-md-3"
  20. v-for="item in globalDestinationCards"
  21. :key="item.destinationId"
  22. >
  23. <div class="q-pa-md">
  24. <q-card
  25. class="destination-card cursor-pointer rounded-borders"
  26. @mouseenter="hoverFlag = true"
  27. @mouseleave="hoverFlag = true"
  28. >
  29. <q-img
  30. @click="goPage('/destination-detail/' + item.destinationId)"
  31. class="rounded-borders"
  32. style="height: 100%"
  33. :src="normalizeMultiImageUrl(item.destinationProfileImage)"
  34. >
  35. <div class="absolute-bottom">
  36. <div class="text-h6 text-white">
  37. <a
  38. style="color: inherit"
  39. :href="'./destination-detail/' + item.destinationId"
  40. >{{ item.destinationName }}</a
  41. >
  42. </div>
  43. <div class="text-subtitle2">
  44. {{ item.parentDestinationName }}
  45. </div>
  46. </div>
  47. </q-img>
  48. </q-card>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="row">
  53. <div class="col-12">
  54. <p class="text-center" style="background-color: #b4b4b4">
  55. Scroll to load more
  56. </p>
  57. </div>
  58. </div>
  59. </q-page>
  60. </template>
  61. <script>
  62. import { ref, onMounted } from "vue";
  63. import { api } from "boot/axios";
  64. import { debounce } from "lodash";
  65. export default {
  66. name: "DestinationPage",
  67. setup() {
  68. const pageSize = ref(44);
  69. const currentPage = ref(1);
  70. const destinationCards = ref([]);
  71. const globalDestinationCards = ref([]);
  72. const totalDestinationCount = ref(-1);
  73. const query = ref("");
  74. const hoverFlag = ref(true);
  75. function loadMore() {
  76. currentPage.value += 1;
  77. var maxPage = totalDestinationCount.value / pageSize.value;
  78. if (currentPage.value <= maxPage + 1) {
  79. loadDestinations();
  80. }
  81. }
  82. function getNextBatch() {
  83. window.onscroll = debounce(function () {
  84. let bottomOfWindow =
  85. document.documentElement.scrollTop + window.innerHeight + 100 >
  86. document.documentElement.scrollHeight;
  87. if (bottomOfWindow) {
  88. loadMore();
  89. }
  90. }, 500);
  91. }
  92. const updateQuery = debounce((value) => {
  93. globalDestinationCards.value = [];
  94. currentPage.value = 1;
  95. loadDestinations();
  96. }, 500);
  97. function loadDestinations() {
  98. destinationCards.value = [];
  99. var params = {};
  100. params.pageSize = pageSize.value;
  101. console.log("loading page: " + currentPage.value);
  102. params.page = currentPage.value;
  103. params.query = query.value;
  104. api
  105. .get("/api/public/destination/list", { params: params })
  106. .then(function (response) {
  107. destinationCards.value = response.data.data.data;
  108. totalDestinationCount.value = response.data.data.total;
  109. globalDestinationCards.value = globalDestinationCards.value.concat(
  110. destinationCards.value
  111. );
  112. })
  113. .catch(function (error) {
  114. console.log(error);
  115. });
  116. }
  117. function logPv() {
  118. api
  119. .post("/api/public/pagestats/pv/destination")
  120. .then((res) => {
  121. console.log("log pv:");
  122. console.log(res.data);
  123. })
  124. .catch((err) => {
  125. console.error("Error:", err);
  126. });
  127. }
  128. onMounted(() => {
  129. logPv();
  130. loadDestinations();
  131. getNextBatch();
  132. });
  133. return {
  134. query,
  135. globalDestinationCards,
  136. hoverFlag,
  137. updateQuery,
  138. };
  139. },
  140. };
  141. </script>
  142. <style lang="sass" scoped>
  143. .destination-card
  144. width: 100%
  145. max-width: 550px
  146. height: 300px
  147. </style>