Просмотр исходного кода

账户金额与日期格式化

xiaohaizhao 2 лет назад
Родитель
Сommit
abe6ea802d
2 измененных файлов с 26 добавлено и 10 удалено
  1. 22 6
      packageA/account/index.js
  2. 4 4
      packageA/account/index.wxml

+ 22 - 6
packageA/account/index.js

@@ -1,6 +1,12 @@
 const _Http = getApp().globalData.http;
 let pageNumber = 1,
-    pageTotal = 1;
+    pageTotal = 1,
+    currency = require("../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
+
 import {
     formatTime
 } from "../../utils/getTime";
@@ -29,7 +35,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);
         })
@@ -49,7 +60,7 @@ Page({
         this.getList();
     },
     getList(init = false) {
-        if (init){
+        if (init) {
             pageNumber = 1;
             pageTotal = 1
         }
@@ -74,10 +85,15 @@ Page({
                     earning = 0; //支出
                 if (res.data.length) {
                     let expendObj = res.data[0].total.find(v => v.type == 1);
-                    if (expendObj) expend = expendObj.sumamount;
+                    if (expendObj) expend = CNY(expendObj.sumamount);
                     let earningObj = res.data[0].total.find(v => v.type == 0);
-                    if (earningObj) earning = earningObj.sumamount;
+                    if (earningObj) earning = CNY(earningObj.sumamount);
                 }
+                res.data = res.data.map(v=>{
+                    v.amount = CNY(v.amount)
+                    v.showBalance = CNY(v.balance)
+                    return v
+                })
                 pageNumber += 1;
                 pageTotal = res.pageTotal;
                 this.setData({
@@ -88,7 +104,7 @@ Page({
             }
         })
     },
-    onReachBottom(){
+    onReachBottom() {
         this.getList();
     }
 })

+ 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>