You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.4 KiB

  1. <template>
  2. <div class="picker-wrap">
  3. <v-select :options="testlist" label="slug">
  4. <template #option="option">
  5. <span>{{ option.slug }}</span>
  6. <span>{{ option.title }}</span>
  7. </template>
  8. </v-select>
  9. <v-select :options="airports" label="iata" :filter-by="filterBy" @input="setSelectedOrigin">
  10. <template #no-options="{ search, searching }">
  11. <template v-if="searching">
  12. No results found for <em>{{ search }}</em>.
  13. </template>
  14. <em v-else style="opacity: 0.5;">Start typing to search for an airport.</em>
  15. </template>
  16. <template #option="option">
  17. <div class="picker-item">
  18. <div class="picker-item__section">
  19. <div class="picker-item__iata">
  20. {{ option.iata }}
  21. </div>
  22. </div>
  23. <div class="picker-item__section">
  24. <div class="picker-item__name">
  25. {{ option.name }}
  26. </div>
  27. <div class="picker-item__muni">
  28. {{ option.municipality }}
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. </v-select>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. props: {
  39. testlist: {
  40. type: [Array, Object],
  41. default () {
  42. return []
  43. }
  44. }
  45. },
  46. data () {
  47. return {
  48. mountains: [],
  49. airports: [],
  50. airportFetch_url: 'https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA',
  51. airportFetch_filterFormula: 'AND(Is_Origin=1,{IsCurrent-AsOrigin}=\'Yes\')',
  52. airportFetch_fields: [
  53. 'Airport_IATA',
  54. 'Icon_Url',
  55. 'Latitude_Deg',
  56. 'Longitude_Deg',
  57. 'Municipality',
  58. 'Airport_Name',
  59. 'Type',
  60. 'Search_Field'
  61. ],
  62. airportFetch_sort: '&sort[0][field]=Airport_IATA&sort[0][direction]=asc',
  63. filterBy: (option, label, search) => {
  64. const temp = search.toLowerCase()
  65. return option.search.toLowerCase().includes(temp)
  66. },
  67. selectedOrigin: {},
  68. selectedDestination: {}
  69. }
  70. },
  71. async fetch () {
  72. let response2 = {}
  73. let mapData2 = {}
  74. const response = await fetch(`${this.airportFetch_url}?filterByFormula=${this.airportFetch_filterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}`, {
  75. method: 'GET',
  76. headers: {
  77. 'Content-Type': 'application/x-www-form-urlencoded',
  78. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  79. }
  80. })
  81. if (await response.offset) {
  82. response2 = fetch(`${this.airportFetch_url}?filterByFormula=${this.filterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}&offset=${response.offset}`, {
  83. method: 'GET',
  84. headers: {
  85. 'Content-Type': 'application/x-www-form-urlencoded',
  86. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  87. }
  88. })
  89. mapData2 = await response2.json()
  90. }
  91. const mapData = await response.json()
  92. const r1 = mapData.records
  93. const r2 = mapData2.records
  94. console.log(r2)
  95. // const mapDataTotal = [...r1, ...r2]
  96. const mapDataTotal = [...r1]
  97. this.airports = mapDataTotal.map((record) => {
  98. return {
  99. iata: record.fields.Airport_IATA,
  100. lat: record.fields.Latitude_Deg,
  101. long: record.fields.Longitude_Deg,
  102. icon: record.fields.Icon_Url,
  103. name: record.fields.Airport_Name,
  104. municipality: record.fields.Municipality,
  105. type: record.fields.Type,
  106. search: record.fields.Search_Field
  107. }
  108. })
  109. },
  110. computed: {
  111. airportFetch_fields_string () {
  112. const vm = this
  113. const array = vm.airportFetch_fields.map((field) => {
  114. return '&fields[]=' + field
  115. })
  116. return array.join('')
  117. }
  118. },
  119. methods: {
  120. setSelectedOrigin (value) {
  121. this.selectedOrigin = value
  122. this.$router.push('/go/' + value.iata)
  123. },
  124. setSelectedDestination (value) {
  125. this.selectedDestination = value
  126. this.$router.push('/go/' + this.selectedOrigin + '/' + value.iata)
  127. }
  128. }
  129. }
  130. </script>
  131. <style>
  132. html {
  133. color: black;
  134. }
  135. .picker-wrap {
  136. margin: 1rem;
  137. }
  138. .vs__search {
  139. font-size: 2rem !important;
  140. }
  141. .picker-item {
  142. padding: 0.5rem;
  143. display: flex;
  144. flex-direction: row;
  145. align-items: center;
  146. gap: 1rem;
  147. }
  148. .picker-item__section {
  149. display: flex;
  150. flex-direction: column;
  151. }
  152. .picker-item__name {
  153. font-size: 1rem;
  154. }
  155. .picker-item__muni {
  156. color: blue;
  157. }
  158. .picker-item__iata {
  159. font-size: 3rem;
  160. }
  161. </style>