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

132 lines
2.9 KiB

  1. <template>
  2. <div class="page">
  3. <h2>Estimates</h2>
  4. <section class="form inputs">
  5. <h3>Default Fees</h3>
  6. <div
  7. v-for="(fee, indx) in fees"
  8. :key="fee.name + indx" class="fee"
  9. >
  10. <label @click="() => edit = fee">
  11. ${{fee.amount/100}}{{ fee.perc ? ` ${fee.perc}%` : ''}} - {{fee.name}}<br>
  12. {{fee.type}}
  13. </label>
  14. <img width="21" height="21" src="/assets/image/icon/x-red.svg"
  15. @click="() => remove(indx, 1)">
  16. </div>
  17. <button @click="() => edit = {}">New Fee</button>
  18. </section>
  19. <fee-dialog v-if="edit"
  20. :heading="'Fee'"
  21. :initial="edit"
  22. :price="0"
  23. @close="() => edit = null"
  24. @save="newFee"
  25. />
  26. <section class="inputs estimates">
  27. <h3>Saved Estimates</h3>
  28. <div class="entry" v-for="e in estimates" v-if="!estimate"
  29. @click="() => estimate = e" key="e.id">
  30. <span>
  31. {{e.id}} - {{e.property}} - ${{(e.price/100).toLocaleString()}}
  32. </span>
  33. </div>
  34. <div class="details" v-if="estimate">
  35. <label>
  36. #{{estimate.id}} -
  37. {{estimate.transaction}} -
  38. {{estimate.property}} -
  39. ${{(estimate.price / 100).toLocaleString()}}
  40. </label>
  41. <label>Borrowers: {{estimate.borrower.num}}</label>
  42. <label>Credit: {{estimate.borrower.credit}}</label>
  43. <label>Income: {{(estimate.borrower.income/100).toLocaleString()}}</label>
  44. <div v-for="(l, i) in estimate.loans" class="details">
  45. <h4>{{l.title}}</h4>
  46. <label>{{l.type.name}}</label>
  47. <label>Total monthly: ${{format(estimate.results[i].totalMonthly)}}</label>
  48. <label>Cash to close: ${{format(estimate.results[i].cashToClose)}}</label>
  49. </div>
  50. <button @click="() => estimate = null">Cancel</button>
  51. </div>
  52. </section>
  53. </div>
  54. </template>
  55. <script setup>
  56. import { ref, computed, onMounted } from 'vue'
  57. import FeeDialog from "./fee-dialog.vue"
  58. import { format } from "../helpers.js"
  59. const props = defineProps(['user', 'fees', 'token'])
  60. let edit = ref(null)
  61. let estimates = ref([])
  62. let estimate = ref()
  63. function newFee(fee, isDebit) {
  64. this.edit = null
  65. }
  66. function newType() {
  67. }
  68. function remove() {
  69. }
  70. function getEstimates() {
  71. fetch(`/api/estimates`,
  72. {method: 'GET',
  73. headers: {
  74. "Accept": "application/json",
  75. "Authorization": `Bearer ${props.token}`,
  76. },
  77. }).then(response => {
  78. if (response.ok) { return response.json() } else {
  79. response.text().then(t => console.log(t))
  80. }
  81. }).then (result => {
  82. if (!result || !result.length) return // Exit if token is invalid or no fees are saved
  83. estimates.value = result
  84. // console.log(result)
  85. })
  86. }
  87. function summarize() {
  88. fetch(`/api/estimate/summarize`,
  89. {method: 'POST',
  90. headers: {
  91. "Accept": "application/json",
  92. "Authorization": `Bearer ${props.token}`,
  93. },
  94. body: JSON.stringify(estimate.value),
  95. }).then(response => {
  96. if (response.ok) { return response.json() } else {
  97. response.text().then(t => console.log(t))
  98. }
  99. }).then(result => {
  100. if (!result || !result.length) return // Exit if token is invalid or no fees are saved
  101. console.log('done', result)
  102. })
  103. }
  104. onMounted(() => {
  105. getEstimates()
  106. })
  107. </script>