您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

bondCaclculator.vue 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div>
  3. <h2 id="modal-bondcal">Bond Calculator</h2>
  4. <p>Calculate the value of the property you could buy</p>
  5. <input
  6. type="text"
  7. class="form-control mb-2"
  8. name="income"
  9. id="gross-income"
  10. placeholder="Gross Monthly Household Income"
  11. v-model="amount"
  12. @input="displayValue()"
  13. />
  14. <input
  15. type="text"
  16. class="form-control mb-2"
  17. name="deposit"
  18. id="deposit"
  19. placeholder="Deposit Amount – May be Required"
  20. v-model="deposit"
  21. @input="displayDeposit()"
  22. />
  23. <div class="slidecontainer mt-4">
  24. <input type="range" min="5" max="30" value="10" class="slider" id="myRange" v-model="term" />
  25. </div>
  26. <p>{{ term }} Years</p>
  27. <input
  28. type="text"
  29. class="form-control mb-2"
  30. name="interest"
  31. id="interest"
  32. placeholder="Interest Rate (Percent)"
  33. v-model="rate"
  34. />
  35. <!-- <button @click="calculate()" class="btn-solid-blue scrollto">CALCULATE</button> -->
  36. <div class="container p-0 mt-5">
  37. <div class="row">
  38. <div class="col-md-7">
  39. Monthly Repayment
  40. </div>
  41. <div class="col-md-5">
  42. <strong>{{ totalMonthlyPayment | toCurrency }}</strong>
  43. </div>
  44. </div>
  45. <hr />
  46. <div class="row">
  47. <div class="col-md-7">
  48. Gross Montly Income
  49. </div>
  50. <div class="col-md-5">
  51. <strong>{{ grossIncome | toCurrency }}</strong>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. /* eslint-disable */
  59. export default {
  60. data() {
  61. return {
  62. amount: "R1000000",
  63. deposit: "R0",
  64. term: 10,
  65. rate: 7,
  66. isInputActive: false
  67. };
  68. },
  69. props: ["value"],
  70. methods: {
  71. calculate() {
  72. var rate = this.calcRate();
  73. var years = this.term * 12;
  74. var topPart = rate * Math.pow(1 + rate, years);
  75. var bottomPart = Math.pow(1 + rate, years) - 1;
  76. var netAmnt = this.amount - this.deposit;
  77. var bond = (netAmnt * topPart) / bottomPart;
  78. },
  79. calcRate() {
  80. var answer = this.rate / 100 / 12;
  81. return answer;
  82. },
  83. displayValue() {
  84. const formatter = new Intl.NumberFormat("en-US", {
  85. minimumFractionDigits: 2
  86. });
  87. if (this.amount.charAt(0) !== "R") {
  88. this.amount = "R" + formatter.format(this.amount);
  89. if (this.amount < 1) {
  90. this.amount = "R" + 0;
  91. }
  92. }
  93. },
  94. displayDeposit() {
  95. if (this.deposit.charAt(0) !== "R") {
  96. if (this.deposit < 1) {
  97. this.deposit = "R" + 0;
  98. }
  99. }
  100. }
  101. },
  102. computed: {
  103. totalMonthlyPayment() {
  104. var rate = this.calcRate;
  105. var years = this.term * 12;
  106. var topPart = rate * Math.pow(1 + rate, years);
  107. var bottomPart = Math.pow(1 + rate, years) - 1;
  108. var netAmnt = parseFloat(this.amount.substring(1)) - parseFloat(this.deposit.substring(1));
  109. var bond = (netAmnt * topPart) / bottomPart;
  110. if (isNaN(bond)) {
  111. return 0;
  112. } else {
  113. return bond;
  114. }
  115. },
  116. calcRate() {
  117. var answer = this.rate / 100 / 12;
  118. return answer;
  119. },
  120. grossIncome() {
  121. return this.totalMonthlyPayment * 3.335120643;
  122. }
  123. }
  124. };
  125. </script>
  126. <style lang="scss" scoped></style>