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.
 
 
 
 
 
 

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