hejie 3 سال پیش
والد
کامیت
e90fe05e32
4فایلهای تغییر یافته به همراه50 افزوده شده و 4 حذف شده
  1. 46 0
      src/main.js
  2. 1 1
      src/pagesB/invoice/editinvoice.vue
  3. 1 1
      src/pagesB/invoice/invoiceList.vue
  4. 2 2
      src/pagesB/my/assistant.vue

+ 46 - 0
src/main.js

@@ -35,6 +35,52 @@ Vue.prototype.tidyTpye = (da) => {
     }
 }
 
+Number.prototype.toFixed = function (n) {
+ 
+    if (n > 20 || n < 0) {
+        throw new RangeError('toFixed() digits argument must be between 0 and 20');
+    }
+    const number = this;
+    if (isNaN(number) || number >= Math.pow(10, 21)) {
+        return number.toString();
+    }
+  
+    if (typeof (n) == 'undefined' || n == 0) {
+        return (Math.round(number)).toString();
+    }
+    let result = number.toString();
+    const arr = result.split('.');
+    // 整数的情况
+    if (arr.length < 2) {
+        result += '.';
+        for (let i = 0; i < n; i += 1) {
+            result += '0';
+        }
+        return result;
+    }
+    const integer = arr[0];
+    const decimal = arr[1];
+    if (decimal.length == n) {
+        return result;
+    }
+  
+    if (decimal.length < n) {
+        for (let i = 0; i < n - decimal.length; i += 1) {
+            result += '0';
+        }
+        return result;
+    }
+    result = integer + '.' + decimal.substr(0, n);
+    const last = decimal.substr(n, 1);
+    // 四舍五入,转换为整数再处理,避免浮点数精度的损失
+    if (parseInt(last, 10) >= 5) {
+        const x = Math.pow(10, n);
+        result = (Math.round((parseFloat(result) * x)) + 1) / x;
+        result = result.toFixed(n);
+    }
+    return result;
+  }
+
 // 自动适配接口域名
 import hosts from "@/request/config";
 Vue.prototype.$hosts = hosts;

+ 1 - 1
src/pagesB/invoice/editinvoice.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="editinvoice">
     <div class="top">
-      <span>本次共选择{{ list.length }}个订单,合计¥{{ money }}</span>
+      <span>本次共选择{{ list.length }}个订单,合计¥{{ money.toFixed(2) }}</span>
     </div>
     <div class="tit">发票详情</div>
     <div class="formBar">

+ 1 - 1
src/pagesB/invoice/invoiceList.vue

@@ -9,7 +9,7 @@
             </div>
             <div class="p2 flex_r flex_jb">
                 <div class="tit ellipsis1">电子发票</div>
-                <span class="money">金额{{ item.money }}</span>
+                <span class="money">金额{{ item.money.toFixed(2) }}</span>
             </div>
         </div>
       </div>

+ 2 - 2
src/pagesB/my/assistant.vue

@@ -32,7 +32,7 @@
                 <div class="tit ellipsis1">{{ item.goods_name }}</div>
                 <div class="num">数量 x{{ item.goods_num }}</div>
                 <div class="money flex_r flex_jb">
-                  <span>金额{{ item.total_amount }}</span>
+                  <span>金额{{ item.order_amount }}</span>
                   <!-- <span>奖励茶宝36</span> -->
                 </div>
               </div>
@@ -125,7 +125,7 @@ export default {
       for (let i of this.list) {
         if (i.isclick) {
           this.trueTotal++;
-          this.money = this.money + i.total_amount * 1;
+          this.money = this.money + i.order_amount * 1;
         }
       }
     },