Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

new.vue 5.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div id="new" class="page">
  3. <h2>New Loan</h2>
  4. <section class="loans-list">
  5. <h3 v-for="(l, indx) in loans"
  6. :class="sel == indx ? 'sel' : ''"
  7. @click="() => sel = indx"
  8. >
  9. {{l.title}}
  10. </h3>
  11. <div class="add">
  12. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
  13. fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16"> <path d="M8 4a.5.5 0
  14. 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0
  15. 0 1 8 4z"/> </svg>
  16. </div>
  17. </section>
  18. <section class="form inputs">
  19. <h3>Loan</h3>
  20. <label>Name</label>
  21. <input :value="loans[sel].title"
  22. @input="(e) => loans[sel].title = stripLetters(e)">
  23. <button @click="del">Delete</button>
  24. </section>
  25. <section class="form inputs">
  26. <h3>Borrower</h3>
  27. <label>Number of Borrowers</label>
  28. <input :value="loans[sel].borrowers"
  29. @input="(e) => loans.forEach(l => l.borrowers = strip(e))">
  30. <label>Credit Score</label>
  31. <input :value="loans[sel].creditScore"
  32. @input="(e) => loans[sel].creditScore = strip(e)">
  33. <label>Monthly Income ($)</label>
  34. <input :value="loans[sel].mIncome"
  35. @input="(e) => loans[sel].mIncome = strip(e)">
  36. </section>
  37. <section class="radios form">
  38. <h3>Transaction Type</h3>
  39. <input type="radio" name="transaction_type" value="transaction"
  40. @input="e => loans[sel].transaction = 0"
  41. selected="loans[sel].transaction == 0">
  42. <label>Purchase</label>
  43. <input type="radio" name="transaction_type" value="refinance"
  44. @input="e => loans[sel].transaction = 1"
  45. selected="loans[sel].transaction == 1">
  46. <label>Refinance</label>
  47. </section>
  48. <section class="form inputs">
  49. <h3>Property Details</h3>
  50. <label>Price ($)</label>
  51. <input :value="loans[sel].price" @input="setPrice">
  52. <label>Type</label>
  53. <select id="" name="" v-model="loans[sel].property">
  54. <option value="attched">Single Family Attached</option>
  55. <option value="detached">Single Family Detached</option>
  56. <option value="lorise">Lo-rise (4 stories or less)</option>
  57. <option value="hirise">Hi-rise (over 4 stories)</option>
  58. </select>
  59. </section>
  60. <section class="radios form">
  61. <h3>Loan Type</h3>
  62. <input type="radio" name="loan_type" value="conv" v-model="loans[sel].type"
  63. >
  64. <label>Conventional</label>
  65. <input type="radio" name="loan_type" value="fha" v-model="loans[sel].type">
  66. <label>FHA</label>
  67. <input type="radio" name="loan_type" value="va" v-model="loans[sel].type">
  68. <label>VA</label>
  69. <input type="radio" name="loan_type" value="usda" v-model="loans[sel].type">
  70. <label>USDA</label>
  71. </section>
  72. <section class="form inputs">
  73. <h3>Loan Details</h3>
  74. <label>Loan Term (years)</label>
  75. <input :value="loans[sel].term"
  76. @input="(e) => loans[sel].term = parseInt(e.target.value.replace(/[^0-9]/g, ''))">
  77. <label>Loan Program</label>
  78. <select id="" name="" v-model="loans[sel].program">
  79. <option value="none">None</option>
  80. </select>
  81. <label>Loan to Value (%)</label>
  82. <input :value="loans[sel].ltv" @input="setLtv">
  83. <label>Loan Amount ($)</label>
  84. <input :value="loans[sel].amount"
  85. @input="setAmount">
  86. <label>Housing Expense DTI (%) - Optional</label>
  87. <input :value="loans[sel].housingDti" @input="setHousingDti">
  88. <label>Total DTI (%) - Optional</label>
  89. <input :value="loans[sel].dti" @input="setDti">
  90. </section>
  91. </div>
  92. </template>
  93. <script>
  94. // Strips non-digits from an input box event and returns it's rounded integer
  95. function strip(e) {
  96. return parseInt(e.target.value.replace(/\D/g, '') || 0)
  97. }
  98. function stripLetters(e) {
  99. let value = (e.target.value.replace(/[^\w\s]/g, '').slice(0, 20) || '')
  100. e.target.value = value
  101. return value
  102. }
  103. function del() {
  104. if (this.loans.length > 1) {
  105. let x = this.sel
  106. this.sel = 0
  107. this.loans.splice(x, 1)
  108. }
  109. }
  110. function setLtv(e) {
  111. let ltv = strip(e)
  112. let loan = this.loans[this.sel]
  113. if (!loan.price) return
  114. if (ltv > 100) ltv = 100
  115. if (ltv < 0) ltv = 0
  116. loan.ltv = ltv
  117. e.target.value = ltv
  118. loan.amount = Math.round(ltv / 100 * loan.price)
  119. }
  120. function setAmount(e) {
  121. let amount = strip(e)
  122. let loan = this.loans[this.sel]
  123. if (!loan.price) return
  124. if (amount > loan.price) amount = loan.price
  125. if (amount < 0) amount = 0
  126. loan.amount = amount
  127. e.target.value = amount
  128. loan.ltv = Math.round(amount / loan.price * 100)
  129. }
  130. function setPrice(e) {
  131. let loan = this.loans[this.sel]
  132. let value = strip(e)
  133. loan.price = value
  134. e.target.value = value
  135. loan.amount = Math.round(loan.ltv / 100 * value)
  136. }
  137. function setDti(e) {
  138. let dti = strip(e)
  139. let loan = this.loans[this.sel]
  140. if (!loan.price) return
  141. if (dti > 100) dti = 100
  142. if (dti < 0) dti = 0
  143. e.target.value = dti
  144. loan.dti = dti
  145. }
  146. function setHousingDti(e) {
  147. let housingDti = strip(e)
  148. let loan = this.loans[this.sel]
  149. if (!loan.price) return
  150. if (housingDti > 100) housingDti = 100
  151. if (housingDti < 0) housingDti = 0
  152. e.target.value = housingDti
  153. loan.housingDti = housingDti
  154. }
  155. const loans = [
  156. {
  157. title: "Loan Example",
  158. property: "",
  159. transaction: 0,
  160. type: "",
  161. price: 0,
  162. term: 0,
  163. ltv: 0,
  164. borrowers: 0,
  165. creditScore: 0,
  166. mIncome: 0,
  167. dti: 0,
  168. housingDti: 0,
  169. amount: 0,
  170. program: "",
  171. pud: false,
  172. zip: ''
  173. },
  174. {
  175. title: "Another One",
  176. property: "",
  177. transaction: 0,
  178. type: "",
  179. price: 0,
  180. term: 0,
  181. ltv: 0,
  182. borrowers: 0,
  183. creditScore: 0,
  184. mIncome: 0,
  185. dti: 0,
  186. housingDti: 0,
  187. program: "",
  188. pud: true,
  189. zip: ''
  190. }
  191. ]
  192. export default {
  193. methods: {
  194. setPrice, setLtv, setAmount, setDti, setHousingDti,
  195. strip, stripLetters, del
  196. },
  197. props: ['user'],
  198. data() {
  199. return {
  200. loans: loans, sel: 0, loan: loans[0],
  201. }
  202. }
  203. }
  204. </script>