Browse Source

账户金额格式化

xiaohaizhao 1 year ago
parent
commit
4faaab9462
2 changed files with 23 additions and 9 deletions
  1. 19 5
      packageA/account/index.js
  2. 4 4
      packageA/account/index.wxml

+ 19 - 5
packageA/account/index.js

@@ -1,4 +1,9 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    currency = require("../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 import {
     formatTime
 } from "../../utils/getTime";
@@ -27,7 +32,12 @@ Page({
         }).then(res => {
             console.log(res)
             this.setData({
-                accountList: res.data
+                accountList: res.data.map(v => {
+                    v.creditquota = CNY(v.creditquota);
+                    v.usable = CNY(currency(v.creditquota).add(v.balance));
+                    v.balance = CNY(v.balance)
+                    return v
+                })
             });
             this.getList(true);
         })
@@ -66,12 +76,16 @@ Page({
                     earning = 0; //支出
                 if (res.data.total.length) {
                     let expendObj = res.data.total.find(v => v.type == 1);
-                    if (expendObj) expend = expendObj.sumamount;
+                    if (expendObj) expend = CNY(expendObj.sumamount);
                     let earningObj = res.data.total.find(v => v.type == 0);
-                    if (earningObj) earning = earningObj.sumamount;
+                    if (earningObj) earning = CNY(earningObj.sumamount);
                 }
                 this.setData({
-                    recordList: res.data.rows,
+                    recordList: res.data.rows.map(v => {
+                        v.amount = CNY(v.amount)
+                        v.showBalance = CNY(v.balance)
+                        return v
+                    }),
                     expend,
                     earning
                 })

+ 4 - 4
packageA/account/index.wxml

@@ -27,7 +27,7 @@
             <view class="item">
                 <view class="name">可用额度(元)</view>
                 <view class="price">
-                    {{item.creditquota+item.balance}}
+                    {{item.usable}}
                 </view>
             </view>
         </view>
@@ -43,13 +43,13 @@
 
 <navigator url="#" class="record" wx:for="{{recordList}}" wx:key="sa_accountclassid">
     <view class="content">
-        <view class="title">{{item.type==0?'支出':'收入'}}-{{item.source}}</view>
-        <view class="exp">{{item.accountname}}:{{item.balance}}</view>
+        <view class="title">{{item.type==0?'支出':'收入'}}{{item.source?'-'+item.source:""}}</view>
+        <view class="exp">{{item.accountname}}:{{item.showBalance}}</view>
         <view class="exp">交易备注:{{item.remarks || ' --'}}</view>
         <view class="exp">{{item.createdate}}</view>
     </view>
     <view class="price" style="color:{{item.balance>=0?'#DB0D27':'var(--success)'}} ;">
-        {{item. amount}}
+        {{item. amount}}
     </view>
 </navigator>