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.

218 lines
5.7 KiB

3 years ago
3 years ago
  1. <template>
  2. <div class="white-bkg">
  3. <header>
  4. <div class="header__col">
  5. <button class="btn btn--primary" @click="goBack">
  6. <svg
  7. xmlns="http://www.w3.org/2000/svg"
  8. class="icon icon-tabler icon-tabler-chevrons-left"
  9. width="24"
  10. height="24"
  11. viewBox="0 0 24 24"
  12. stroke-width="3"
  13. stroke="#ffffff"
  14. fill="none"
  15. stroke-linecap="round"
  16. stroke-linejoin="round"
  17. >
  18. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  19. <polyline points="11 7 6 12 11 17" />
  20. <polyline points="17 7 12 12 17 17" />
  21. </svg> back
  22. </button>
  23. </div>
  24. <div class="header__col">
  25. <Logo />
  26. </div>
  27. <div class="header__col" />
  28. </header>
  29. <main class="main-with-header">
  30. <ChosenFlights
  31. :selected-orig="selectedOrig"
  32. :selected-dest="selectedDest"
  33. style="margin: 0 1rem;"
  34. />
  35. <!-- <pre>
  36. {{ schedules }}
  37. </pre> -->
  38. <DatePicker
  39. :starting-date="startingDate"
  40. :selected-dows="selectedDows"
  41. />
  42. </main>
  43. </div>
  44. </template>
  45. <script>
  46. export default {
  47. data () {
  48. return {
  49. schedules: [],
  50. startingDate: new Date(),
  51. selectedSchedule: {},
  52. selectedDays: [],
  53. selectedOrig: {},
  54. selectedDest: {}
  55. }
  56. },
  57. async fetch () {
  58. // console.log(this.$route.params.o)
  59. const today = new Date().toLocaleDateString('en-CA')
  60. const scheduleFetchFilterFormula = `AND(Is_Current="Yes",Origin_IATA="${this.$route.params.o}",Destination_IATA="${this.$route.params.d}",Effective_End>"${today}")`
  61. const scheduleFetchSort = '&sort[0][field]=Departure_TimeL&sort[0][direction]=asc'
  62. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Schedule?filterByFormula=${scheduleFetchFilterFormula}${scheduleFetchSort}`, {
  63. method: 'GET',
  64. headers: {
  65. 'Content-Type': 'application/x-www-form-urlencoded',
  66. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  67. }
  68. })
  69. const data = await response.json()
  70. // console.log(data)
  71. this.schedules = [...data.records]
  72. },
  73. computed: {
  74. selectedDows () {
  75. const mappedDows = this.schedules.map((schedule) => {
  76. // console.log(schedule.fields)
  77. return {
  78. Flight_Number: schedule.fields.Flight_Number,
  79. DowsList: this.daysList(schedule.fields.Frequency_Convert),
  80. Effective_Start: schedule.fields.Effective_Start,
  81. Effective_End: schedule.fields.Effective_End,
  82. Departure_TimeL: schedule.fields.Departure_TimeL
  83. }
  84. })
  85. return mappedDows
  86. }
  87. },
  88. created () {
  89. // console.log(this.$route.path)
  90. if (this.$route && this.$route.params && this.$route.params.o) {
  91. this.fetchSingleAirport(this.$route.params.o, true)
  92. }
  93. if (this.$route && this.$route.params && this.$route.params.d) {
  94. this.fetchSingleAirport(this.$route.params.d, false)
  95. }
  96. },
  97. methods: {
  98. daysList (days) {
  99. const list = days.split(', ').map((day) => {
  100. const name = day.toLowerCase().slice(0, -1)
  101. let num
  102. switch (name) {
  103. case 'su':
  104. num = 0
  105. break
  106. case 'mo':
  107. num = 1
  108. break
  109. case 'tu':
  110. num = 2
  111. break
  112. case 'we':
  113. num = 3
  114. break
  115. case 'th':
  116. num = 4
  117. break
  118. case 'fr':
  119. num = 5
  120. break
  121. case 'sa':
  122. num = 6
  123. break
  124. default:
  125. break
  126. }
  127. return {
  128. name,
  129. num
  130. }
  131. })
  132. return list.sort(function (a, b) {
  133. return a.num - b.num
  134. })
  135. },
  136. goBack () {
  137. this.$router.go(-1)
  138. },
  139. book (schedule) {
  140. if (schedule.fields.IsExpedia[0] === 'true') {
  141. this.startingDate = new Date()
  142. this.selectedSchedule = schedule.fields
  143. this.selectedDays = this.daysList(schedule.fields.Frequency_Convert)
  144. } else {
  145. window.open(schedule.fields['BookingLink (from Carriers_Alaska)'][0])
  146. }
  147. },
  148. clearSelectedSchedule () {
  149. console.log('clear')
  150. this.startingDate = ''
  151. this.selectedSchedule = {}
  152. },
  153. async fetchSingleAirport (iata, isOrig) {
  154. const airportFetchFilterFormula =
  155. isOrig
  156. ? `AND(Is_Origin=1,{IsCurrent-AsOrigin}="Yes",Airport_IATA="${iata}")`
  157. : `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",Airport_IATA="${iata}")`
  158. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchFilterFormula}`, {
  159. method: 'GET',
  160. headers: {
  161. 'Content-Type': 'application/x-www-form-urlencoded',
  162. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  163. }
  164. })
  165. const mapData = await response.json()
  166. const thisAirport = {
  167. iata: mapData.records[0].fields.Airport_IATA,
  168. lat: mapData.records[0].fields.Latitude_Deg,
  169. long: mapData.records[0].fields.Longitude_Deg,
  170. icon: mapData.records[0].fields.Icon_Url,
  171. name: mapData.records[0].fields.Airport_Name,
  172. municipality: mapData.records[0].fields.Municipality,
  173. type: mapData.records[0].fields.Type,
  174. search: mapData.records[0].fields.Search_Field
  175. }
  176. switch (isOrig) {
  177. case true:
  178. this.selectedOrig = { ...thisAirport }
  179. break
  180. case false:
  181. this.selectedDest = { ...thisAirport }
  182. break
  183. default:
  184. break
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .main-with-header {
  192. margin-top: clamp(20px + 1.75rem, 4rem + 1.75rem, 50px + 1.75rem);
  193. }
  194. </style>