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.

240 lines
6.3 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. mounted () {
  89. //this.$segment.page('dates');
  90. this.$segment.track('dates__mount-page', {
  91. origin: this.$route.params.o,
  92. destination: this.$route.params.d
  93. });
  94. const emailCookie = this.$cookies.get('email')
  95. if(emailCookie){
  96. this.$segment.identify(emailCookie, {
  97. email: emailCookie
  98. });
  99. }
  100. },
  101. created () {
  102. // console.log(this.$route.path)
  103. if (this.$route && this.$route.params && this.$route.params.o) {
  104. this.fetchSingleAirport(this.$route.params.o, true)
  105. }
  106. if (this.$route && this.$route.params && this.$route.params.d) {
  107. this.fetchSingleAirport(this.$route.params.d, false)
  108. }
  109. },
  110. methods: {
  111. daysList (days) {
  112. const list = days.split(', ').map((day) => {
  113. const name = day.toLowerCase().slice(0, -1)
  114. let num
  115. switch (name) {
  116. case 'su':
  117. num = 0
  118. break
  119. case 'mo':
  120. num = 1
  121. break
  122. case 'tu':
  123. num = 2
  124. break
  125. case 'we':
  126. num = 3
  127. break
  128. case 'th':
  129. num = 4
  130. break
  131. case 'fr':
  132. num = 5
  133. break
  134. case 'sa':
  135. num = 6
  136. break
  137. default:
  138. break
  139. }
  140. return {
  141. name,
  142. num
  143. }
  144. })
  145. return list.sort(function (a, b) {
  146. return a.num - b.num
  147. })
  148. },
  149. goBack () {
  150. this.$segment.track('dates__go_back',{
  151. origin: this.$route.params.o,
  152. destination: this.$route.params.d
  153. })
  154. //this.$router.go(-1)
  155. this.$router.push({
  156. path: '/go/' + this.$route.params.o + "/" + this.$route.params.d
  157. })
  158. },
  159. book (schedule) {
  160. if (schedule.fields.IsExpedia[0] === 'true') {
  161. this.startingDate = new Date()
  162. this.selectedSchedule = schedule.fields
  163. this.selectedDays = this.daysList(schedule.fields.Frequency_Convert)
  164. } else {
  165. window.open(schedule.fields['BookingLink (from Carriers_Alaska)'][0])
  166. }
  167. },
  168. clearSelectedSchedule () {
  169. //console.log('clear')
  170. this.startingDate = ''
  171. this.selectedSchedule = {}
  172. },
  173. async fetchSingleAirport (iata, isOrig) {
  174. const airportFetchFilterFormula =
  175. isOrig
  176. ? `AND(Is_Origin=1,{IsCurrent-AsOrigin}="Yes",Airport_IATA="${iata}")`
  177. : `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",Airport_IATA="${iata}")`
  178. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchFilterFormula}`, {
  179. method: 'GET',
  180. headers: {
  181. 'Content-Type': 'application/x-www-form-urlencoded',
  182. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  183. }
  184. })
  185. const mapData = await response.json()
  186. const thisAirport = {
  187. iata: mapData.records[0].fields.Airport_IATA,
  188. lat: mapData.records[0].fields.Latitude_Deg,
  189. long: mapData.records[0].fields.Longitude_Deg,
  190. icon: mapData.records[0].fields.Icon_Url,
  191. name: mapData.records[0].fields.Airport_Name,
  192. municipality: mapData.records[0].fields.Municipality,
  193. type: mapData.records[0].fields.Type,
  194. search: mapData.records[0].fields.Search_Field
  195. }
  196. switch (isOrig) {
  197. case true:
  198. this.selectedOrig = { ...thisAirport }
  199. break
  200. case false:
  201. this.selectedDest = { ...thisAirport }
  202. break
  203. default:
  204. break
  205. }
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .main-with-header {
  212. margin-top: clamp(20px + 1.75rem, 4rem + 1.75rem, 50px + 1.75rem);
  213. }
  214. </style>