Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

153 lines
3.4 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. if (!isDebit) {
  65. fee.amount = -1 * fee.amount || 0
  66. fee.perc = -1 * fee.perc || 0
  67. }
  68. fetch(`/api/fee`,
  69. {method: 'POST',
  70. body: JSON.stringify(fee),
  71. headers: {
  72. "Accept": "application/json",
  73. "Authorization": `Bearer ${props.token}`,
  74. },
  75. }).then(resp => {
  76. if (resp.ok && resp.status == 200) {
  77. return
  78. } else {
  79. // resp.text().then(t => this.errors = [t])
  80. // window.location.hash = 'new'
  81. resp.text().then(t => console.log(t))
  82. }
  83. })
  84. edit.value = null
  85. }
  86. function newType() {
  87. }
  88. function remove() {
  89. }
  90. function getEstimates() {
  91. fetch(`/api/estimates`,
  92. {method: 'GET',
  93. headers: {
  94. "Accept": "application/json",
  95. "Authorization": `Bearer ${props.token}`,
  96. },
  97. }).then(response => {
  98. if (response.ok) { return response.json() } else {
  99. response.text().then(t => console.log(t))
  100. }
  101. }).then (result => {
  102. if (!result || !result.length) return // Exit if token is invalid or no fees are saved
  103. estimates.value = result
  104. // console.log(result)
  105. })
  106. }
  107. function summarize() {
  108. fetch(`/api/estimate/summarize`,
  109. {method: 'POST',
  110. headers: {
  111. "Accept": "application/json",
  112. "Authorization": `Bearer ${props.token}`,
  113. },
  114. body: JSON.stringify(estimate.value),
  115. }).then(response => {
  116. if (response.ok) { return response.json() } else {
  117. response.text().then(t => console.log(t))
  118. }
  119. }).then(result => {
  120. if (!result || !result.length) return // Exit if token is invalid or no fees are saved
  121. console.log('done', result)
  122. })
  123. }
  124. onMounted(() => {
  125. getEstimates()
  126. })
  127. </script>