Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div v-if="valid && props.loan.result">
  3. <section class="form inputs">
  4. <h3>Monthly Payment - ${{format(loan.result.totalMonthly)}}</h3>
  5. <label>Loan payment: ${{format(loan.result.loanPayment)}}</label>
  6. <label v-if="loan.mi.monthly">
  7. Mortgage insurance: ${{format(loan.amount*loan.mi.rate/100/12)}}
  8. </label>
  9. <label>Property taxes: ${{format(loan.tax)}}</label>
  10. <label>Homeowner's Insurance: ${{format(loan.hoi)}}</label>
  11. <label v-if="loan.hazard">
  12. Hazard insurance: ${{format(loan.hazard)}}
  13. </label>
  14. </section>
  15. <section class="form inputs">
  16. <h3>Cash to Close - ${{format(loan.result.cashToClose)}}</h3>
  17. <label>Closing costs: ${{format(loan.result.totalFees)}}</label>
  18. <label v-if="loan.result.totalCredits">
  19. Credits: ${{format(loan.result.totalCredits)}}
  20. </label>
  21. <label>Down payment: ${{format(downpayment)}}</label>
  22. <label v-if="!loan.mi.monthly">
  23. Mortgage insurance: ${{format(loan.mi.upfront)}}
  24. </label>
  25. </section>
  26. <section class="form inputs">
  27. <button :disabled="saved" @click="create">Save Estimate</button>
  28. <button @click="() => download(props.estimate)">Generate PDF</button>
  29. </section>
  30. <DDialog v-if="dlink" @close="() => dlink = ''"
  31. :fileName="`estimate-${props.estimate.id}.pdf`" :url="dlink">
  32. </DDialog>
  33. </div>
  34. </template>
  35. <script setup>
  36. import { ref, computed, onMounted } from 'vue'
  37. import { format } from '../../helpers.js'
  38. import DDialog from "../download-dialog.vue"
  39. const props = defineProps(['downpayment', 'loan', 'token', 'estimate'])
  40. const emit = defineEmits(['update'])
  41. let valid = ref(false)
  42. let saved = ref(false)
  43. let dlink = ref('')
  44. function amortize(principle, rate, periods) {
  45. return principle * rate*(1+rate)**periods / ((1+rate)**periods - 1)
  46. }
  47. function validate() {
  48. fetch(`/api/estimate/validate`,
  49. {method: 'POST',
  50. body: JSON.stringify(props.estimate),
  51. headers: {
  52. "Accept": "application/json",
  53. "Authorization": `Bearer ${props.token}`,
  54. },
  55. }).then(resp => {
  56. if (resp.ok && resp.status == 200) {
  57. valid.value = true
  58. summarize()
  59. }
  60. })
  61. }
  62. function summarize() {
  63. fetch(`/api/estimate/summarize`,
  64. {method: 'POST',
  65. body: JSON.stringify(props.estimate),
  66. headers: {
  67. "Accept": "application/json",
  68. "Authorization": `Bearer ${props.token}`,
  69. },
  70. }).then(resp => {
  71. if (resp.ok && resp.status == 200) return resp.json()
  72. }).then(e => {
  73. emit('update', e)
  74. })
  75. }
  76. function create() {
  77. saved.value = true
  78. fetch(`/api/estimate`,
  79. {method: 'POST',
  80. body: JSON.stringify(props.estimate),
  81. headers: {
  82. "Accept": "application/json",
  83. "Authorization": `Bearer ${props.token}`,
  84. },
  85. }).then(resp => {
  86. if (resp.ok && resp.status == 200) {
  87. saved.value = true
  88. return
  89. } else {
  90. resp.text().then(t => console.log(t))
  91. saved.value = false
  92. }
  93. })
  94. }
  95. function download(estimate) {
  96. fetch(`/api/pdf`,
  97. {method: 'POST',
  98. body: JSON.stringify(estimate),
  99. headers: {
  100. "Accept": "application/json",
  101. "Authorization": `Bearer ${props.token}`,
  102. },
  103. }).then(response => {
  104. if (response.ok) { return response.blob() }
  105. }).then (result => {
  106. if (!result) return // Exit if token is invalid or blank file returned
  107. dlink.value = URL.createObjectURL(result)
  108. })
  109. }
  110. onMounted(() => {validate()})
  111. </script>