Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
 
 
 
 
 
 

126 lines
2.7 KiB

  1. <template>
  2. <form>
  3. <div>
  4. <label>Given name</label>
  5. <input required type="text" name="gname" v-model="user.firstName"/>
  6. </div>
  7. <div>
  8. <label>Surname</label>
  9. <input required type="text" name="sname" v-model="user.lastName"/>
  10. </div>
  11. <div>
  12. <label>Email</label>
  13. <input type="email" name="email" v-model="user.email"/>
  14. </div>
  15. <div>
  16. <label>Password</label>
  17. <input requried type="password" name="pass" v-model="user.pass"/>
  18. </div>
  19. <div>
  20. <label>Country</label>
  21. <select name="country">
  22. <option value="USA">USA</option>
  23. <option value="Canada">Canada</option>
  24. </select>
  25. </div>
  26. <div class="address-entry">
  27. <label for="">Address</label>
  28. <input type="text" @input="searchLocation" :value="address.full">
  29. <dropdown v-if="addresses && addresses.length"
  30. :entries="addresses.map(a => ({text: a.full_address, value: a}))"
  31. @select="setAddress"
  32. >
  33. </dropdown>
  34. </div>
  35. <div><label>NMLS ID</label><input type="text" name="nmls"/></div>
  36. <div><span class="error">{{error}}</span></div>
  37. <div>
  38. <button class="btn" @click="submit" type="button">Continue</button>
  39. </div>
  40. </form>
  41. </template>
  42. <script setup>
  43. import { ref } from "vue"
  44. import Dropdown from "./dropdown.vue"
  45. const addresses = ref([])
  46. const user = ref({})
  47. const address = ref({})
  48. const locationsId = ref(null)
  49. const props = defineProps(['error'])
  50. const emit = defineEmits(['submit'])
  51. function searchLocation(e) {
  52. address.value.full = e.target.value
  53. clearTimeout(locationsId.value)
  54. locationsId.value = setTimeout(getLocations, 1000, e)
  55. }
  56. function getLocations(e) {
  57. let prefix = "https://api.mapbox.com/search/searchbox/v1/suggest?"
  58. let search = e.target.value
  59. let key = encodeURIComponent(process.env.MAPBOX_API_KEY)
  60. if (!search) return
  61. fetch(`${prefix}q=${search}&proximity=ip&access_token=${key}&session_token=1`
  62. ).then(resp => resp.json()).then(entries => {
  63. if (!entries?.suggestions) {
  64. addresses.value = null
  65. return
  66. }
  67. addresses.value = entries.suggestions.filter(e => e.full_address)
  68. })
  69. }
  70. function setAddress(a) {
  71. address.value = {
  72. id: address.value.id,
  73. full: a.full_address,
  74. street: a.address,
  75. city: a.context?.place.name ?? '',
  76. region: a.context?.region?.name ?? '',
  77. country: a.context?.country?.name ?? '',
  78. zip: a.context?.postcode?.name ?? '',
  79. }
  80. addresses.value = null
  81. }
  82. function submit() {
  83. user.value.address = address.value
  84. emit('submit', user.value)
  85. }
  86. </script>
  87. <style scoped>
  88. form > div {
  89. display: flex;
  90. justify-content: space-between;
  91. margin: 10px;
  92. position: relative;
  93. }
  94. button {
  95. margin: auto;
  96. min-width: 90px;
  97. display: block;
  98. }
  99. span.error {
  100. margin: 10px auto;
  101. color: darkred;
  102. }
  103. </style>