소스 검색

计算器-

panyong 3 년 전
부모
커밋
ba4d876461

+ 1 - 0
htmldev/loan/.eslintrc.js

@@ -22,6 +22,7 @@ module.exports = {
     'generator-star-spacing': 'off',
     // allow debugger during development
     indent: 0,
+    'no-useless-escape': 0,
     'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
   }
 }

+ 1 - 0
htmldev/loan/src/filter/toThousands.js

@@ -4,5 +4,6 @@ export const toThousands = (num) => {
   } else if (Object.prototype.toString.call(num) === '[object Number]') {
     num = num.toString()
   }
+  console.log(num.replace(/(\d)(?=(\d{3})+$)/g, '$1,'))
   return num.replace(/(\d)(?=(\d{3})+$)/g, '$1,')
 }

+ 0 - 1
htmldev/loan/src/views/loan/calculator/config/calculate.js

@@ -2,7 +2,6 @@
 export const calcute = {
   // 商贷或公积金贷款统一函数 type: 还款方式 1等额本息 2等额本金 num: 贷款金额 year: 贷款年限 lilv: 贷款基准利率
   singleDk (type, num, year, lilv) {
-    console.log(arguments)
     if (type === 1) {
       return this.benxi(type, num, year, lilv)
     } else if (type === 2) {

+ 29 - 3
htmldev/loan/src/views/loan/calculator/index.vue

@@ -169,7 +169,7 @@
                  class="ttyf-van-cell">
         <template #label>
           <p>
-              <span v-for="(str, index) in '总共支付利息(元)'"
+              <span v-for="(str, index) in '总共支付利息(元)'"
                     :key="index">{{ str }}</span>
           </p>
         </template>
@@ -426,11 +426,30 @@ export default {
       }
       this.showPicker5 = false
     },
+    // 将数值四舍五入(保留2位小数)后格式化成金额形式
+    formatCurrency (val) {
+      let num = val.toString().replace(/\$|\,/g, '')
+      if (isNaN(num)) {
+        num = '0'
+      }
+      num = Math.floor(num * 100 + 0.50000000001)
+      let cents = num % 100
+      num = Math.floor(num / 100).toString()
+      if (cents < 10) {
+        cents = '0' + cents
+      }
+      for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
+        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3))
+      }
+      return num + '.' + cents
+    },
     async handleComputed () {
       await this.$nextTick()
       const sdlilv = this.columns4[this.sdlilvIndex]
       const gjjlilv = this.columns2[this.gjjlilvIndex]
       let result = {}
+      let yuegong = ''
+      let totalLixi = ''
       // 还款方式
       const payType = this.hkfangshi.value
       switch (this.loanType.value) {
@@ -451,8 +470,15 @@ export default {
           break
       }
 
-      this.meiyuehuanchuan = result.yuegong * 1 > 0 ? result.yuegong.toFixed(2) : 0
-      this.zonglixi = result.totalLixi * 1 > 0 ? result.totalLixi.toFixed(2) : 0
+      if (result.yuegong) {
+        yuegong = this.formatCurrency(result.yuegong)
+      }
+
+      if (result.totalLixi) {
+        totalLixi = this.formatCurrency(result.totalLixi / 10000)
+      }
+      this.meiyuehuanchuan = yuegong
+      this.zonglixi = totalLixi
     }
   },
   beforeDestroy () {