Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

estimates.vue 3.8 KiB

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