StepOne.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <h3 class="ptc-title">Choose a store</h3>
  3. <div class="ptc-block">
  4. <div class="ptc-inner-md pr">
  5. <form class="search-wrap" action="">
  6. <input
  7. type="search"
  8. class="search-input ptc-input"
  9. placeholder="Search by zip code"
  10. @input="autocomplete"
  11. />
  12. <div role="button" class="search-btn ptc-button"></div>
  13. </form>
  14. <div v-if="showSuggestions" class="search-suggestions">
  15. <div class="suggestion">PTC Browns Plains Kiosk</div>
  16. <div class="suggestion">PTC Browns Plains Kiosk</div>
  17. </div>
  18. <div class="shop-wrap">
  19. <div class="tip">Nearby shops</div>
  20. <InfiniteList
  21. class="shop-list-wrap"
  22. :loading="loading"
  23. :has-more="hasMore"
  24. scroll-target=".shop-list-wrap"
  25. @loadmore="fetchData"
  26. >
  27. <ul class="shop-list">
  28. <li
  29. v-for="(item, index) of list"
  30. :key="index"
  31. class="shop-item border-bottom"
  32. @click="state.step++"
  33. >
  34. <div class="shop-name">
  35. <span>{{ item.name }}</span>
  36. <span>3.5KM</span>
  37. </div>
  38. <div class="shop-address">
  39. {{ item.shop_detail }},{{ item.address }}
  40. </div>
  41. <div class="shop-mark" :class="{ danger: !item.can_appointment }">
  42. <i class="icon"></i
  43. >{{
  44. item.can_appointment
  45. ? item.can_appointment_day
  46. : 'No appointments available for the next 7 days'
  47. }}
  48. </div>
  49. </li>
  50. </ul>
  51. </InfiniteList>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script setup lang="ts">
  57. import { ref, reactive } from 'vue'
  58. import { state } from './store'
  59. import { getShopList } from '@/service/repair'
  60. import getLocation from '@/utils/getLocation'
  61. import InfiniteList from '@/components/infinite-list/index.vue'
  62. const showSuggestions = ref(false)
  63. const loading = ref(false)
  64. const hasMore = ref(true)
  65. const list = ref<any[]>()
  66. let pageNo = 1
  67. let coords: any = null
  68. async function fetchData() {
  69. loading.value = true
  70. try {
  71. if (!list.value) {
  72. list.value = []
  73. const res = await getLocation({ timeout: 2000 })
  74. coords = res?.coords
  75. }
  76. const { results, pageBean } = await getShopList({})
  77. list.value.push(...results)
  78. pageNo++
  79. hasMore.value = list.value.length === pageBean.totalCount
  80. } catch {}
  81. loading.value = false
  82. }
  83. function autocomplete(e: any) {
  84. showSuggestions.value = e.target.value.length > 0
  85. }
  86. </script>