ソースを参照

首页计数器过滤器判空,修复询价后台无法访问时报错问题

yangc 7 年 前
コミット
5749a2261e
1 ファイル変更34 行追加30 行削除
  1. 34 30
      components/home/count/displayCard.vue

+ 34 - 30
components/home/count/displayCard.vue

@@ -87,44 +87,48 @@
         this.cardShow = false
       },
       formatNumber (num, type) {
-        if (num.toString().indexOf('E') !== -1) {
-          let arr = num.toString().split('E')
-          num = arr[0] * Math.pow(10, arr[1])
-        }
-        if (num > 99999999) {
-          let str2 = num.toString()
-          num = Math.floor(num / 100000000)
-          if (parseInt(str2.charAt(str2.length - 8)) > 8) {
-            num = num + 1
-          }
-          num += '<span style="color: #333">亿</span>'
-        } else if (num > 9999) {
-          let str = num.toString()
-          num = Math.floor(num / 10000)
-          if (parseInt(str.charAt(str.length - 4)) > 4) {
-            num = num + 1
+        if (num) {
+          if (num.toString().indexOf('E') !== -1) {
+            let arr = num.toString().split('E')
+            num = arr[0] * Math.pow(10, arr[1])
           }
-          num += '<span style="color: #333">万</span>'
-        } else {
-          if (type === 1 || type === 2) {
-            num += '<span style="color: #333">元</span>'
+          if (num > 99999999) {
+            let str2 = num.toString()
+            num = Math.floor(num / 100000000)
+            if (parseInt(str2.charAt(str2.length - 8)) > 8) {
+              num = num + 1
+            }
+            num += '<span style="color: #333">亿</span>'
+          } else if (num > 9999) {
+            let str = num.toString()
+            num = Math.floor(num / 10000)
+            if (parseInt(str.charAt(str.length - 4)) > 4) {
+              num = num + 1
+            }
+            num += '<span style="color: #333">万</span>'
           } else {
-            num += ''
+            if (type === 1 || type === 2) {
+              num += '<span style="color: #333">元</span>'
+            } else {
+              num += ''
+            }
           }
         }
         return num
       },
       formatDouble (num) {
-        if (num.toString().indexOf('E') !== -1) {
-          let arr = num.toString().split('E')
-          num = arr[0] * Math.pow(10, arr[1])
-        }
-        if (num > 99999999) {
-          num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '亿'
-        } else if (num > 9999) {
-          num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '万'
-        } else {
+        if (num) {
+          if (num.toString().indexOf('E') !== -1) {
+            let arr = num.toString().split('E')
+            num = arr[0] * Math.pow(10, arr[1])
+          }
+          if (num > 99999999) {
+            num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '亿'
+          } else if (num > 9999) {
+            num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '万'
+          } else {
             num += ''
+          }
         }
         return num
       },