瀏覽代碼

refactor: 全仓分转元手工换算统一替换为 fenToYuan,订单页修复千分位正则失效

skyline 3 周之前
父節點
當前提交
14918c6d8c

+ 4 - 3
charge-front/src/api/user.ts

@@ -1,13 +1,14 @@
 import Http from "../utils/http";
 import { host, isDebug } from "../utils/constant";
+import { fenToYuan } from "../utils/money";
 
 const userHttp = new Http(host);
 
 export function fetchProfile() {
   return userHttp.get("/user/me").then((res) => {
-    res.balance = (Number(res.balance) / 100).toFixed(2);
-    res.discountAmount = (Number(res.discountAmount) / 100).toFixed(2);
-    res.refundableAmount = (Number(res.refundableAmount) / 100).toFixed(2);
+    res.balance = fenToYuan(res.balance);
+    res.discountAmount = fenToYuan(res.discountAmount);
+    res.refundableAmount = fenToYuan(res.refundableAmount);
     // if (isDebug) {
     //   res.userRechargeRightsList = [
     //     {

+ 4 - 6
charge-front/src/pages-charge/card/card.vue

@@ -38,7 +38,7 @@
                       @click.stop="to(`/pages-common/activity/activity?id=${item.activityId}`)">
                   <view class="fs-26 color-999">到期时间:{{ item.endTime }}</view>
                   <view class="flex-align-center" v-if="mode === 0">
-                    <view class="fs-26 color-999">权益余额:{{ ((item.rightsBalance || 0) / 100).toFixed(2) }}元
+                    <view class="fs-26 color-999">权益余额:{{ fenToYuan(item.rightsBalance) }}元
                       <text class="color-primary">详细规则</text>
                       <text class="fs-24 ml-4 color-primary">>></text>
                     </view>
@@ -103,7 +103,7 @@
                   ></image>
                   <view></view>
                   <view class="fs-48 lh-58 color-000 fw-500 ml-16" v-if="item.couponType=='FullDiscount'">
-                    {{ ((item.discount || 0) / 100).toFixed(2) }}元
+                    {{ fenToYuan(item.discount) }}元
                   </view>
 
                   <view class="fs-48 lh-58 color-000 fw-500 ml-16" v-else>
@@ -131,7 +131,7 @@
                       @click.stop="to(`/pages-common/activity/activity?id=${item.activityId}`)">
                   <view class="fs-26 color-999">到期时间:{{ item.endTime }}</view>
                   <view class="flex-align-center">
-                    <view class="fs-26 color-999">服务费门槛:{{ ((item.minServiceMoney || 0) / 100).toFixed(2) }}元
+                    <view class="fs-26 color-999">服务费门槛:{{ fenToYuan(item.minServiceMoney) }}元
                       <text class="color-primary">详细规则</text>
                       <text class="fs-24 ml-4 color-primary">>></text>
                     </view>
@@ -162,13 +162,12 @@ import {onPullDownRefresh, onShow} from "@dcloudio/uni-app";
 import {ref} from "vue";
 import {to} from "../../utils/navigate";
 import {fetchRightsAndCoupons} from "@/api/user";
+import { fenToYuan } from "@/utils/money";
 
 const mode = ref(0);
 const list = ref<any[]>([]);
 const couponList = ref<any[]>([]);
-const activity = ref();
 const checkIndex = ref(-1);
-const needRefresh = ref(false);
 
 onPullDownRefresh(() => {
   loadData();
@@ -184,7 +183,6 @@ const loadData = () => {
   });
   fetchRightsAndCoupons().then((res) => {
     uni.stopPullDownRefresh();
-    console.log(res)
     uni.hideLoading();
     let {userCouponList, userRechargeRightsList} = res;
     list.value = userRechargeRightsList;

+ 2 - 4
charge-front/src/pages-charge/discount/discount.vue

@@ -78,6 +78,7 @@ import { onLoad, onShow } from "@dcloudio/uni-app";
 import { ref } from "vue";
 import { to } from "../../utils/navigate";
 import { fetchProfile } from "@/api/user";
+import { fenToYuan } from "@/utils/money";
 
 const mode = ref(-1);
 const list = ref<any[]>([]);
@@ -97,7 +98,7 @@ const setUserRecharge = (_list: any[]) => {
   _list.forEach((item: any) => {
     item.endTimeFormat = item.endTime.split(" ")[0];
     item.rightsBalanceFormat = Number(
-      (Number(item.rightsBalance) / 100).toFixed(2)
+      fenToYuan(item.rightsBalance)
     );
   });
   list.value = _list;
@@ -106,9 +107,6 @@ const setUserRecharge = (_list: any[]) => {
 
 const checkDiscount = (index: number) => {
   checkIndex.value = index;
-  getApp<any>().globalData.lastData.discount = {
-    index,
-  };
 };
 
 onLoad((options: any) => {

+ 10 - 30
charge-front/src/pages-charge/order/order.vue

@@ -108,6 +108,8 @@ import { onLoad } from "@dcloudio/uni-app";
 import { ref } from "vue";
 import OrderCouponDetail from "@/components/order-coupon-detail/order-coupon-detail.vue";
 import { to } from "@/utils/navigate";
+import { formatDuration, parseDate } from "@/utils/date";
+import { formatMoney, fenToYuan } from "@/utils/money";
 
 const list = ref<any[]>();
 const price = ref();
@@ -115,7 +117,6 @@ const orderDetail = ref();
 const order_coupon_detail_ref = ref();
 
 const handleClickDesc = () => {
-  console.log("handleClickDesc")
   let {startChargeSeq,discountType} = orderDetail.value;
   order_coupon_detail_ref.value?.open(startChargeSeq,discountType);
 }
@@ -140,28 +141,12 @@ onLoad((options: any) => {
   fetchOrder(options.id)
     .then((res) => {
       orderDetail.value = res;
-      const totalMoney = (res.totalMoney / 100).toFixed(2);
-      const elecMoney = res.elecMoney ? (res.elecMoney / 100).toFixed(2) : '0.00';
-      const serviceMoney = res.serviceMoney ? (res.serviceMoney / 100).toFixed(2) : '0.00';
-      const discountAmount = (res.discountAmount / 100).toFixed(2);
+      const discountAmount = fenToYuan(res.discountAmount);
       const discountAmountText = res.rightsDesc;
       const startChargeSeq = res.startChargeSeq;
-      const reg = new RegExp("\B(?=(\d{3})+(?!\d))", "g");
-      const start = new Date(res.startTime.replace(/-/g, "/"));
-      const end = res.endTime
-        ? new Date(res.endTime.replace(/-/g, "/"))
-        : new Date();
-      let diff = parseInt(`${(end.getTime() - start.getTime()) / 1000}`);
-      if (diff <= 0) {
-        diff = 60;
-      }
-      const min = parseInt(`${diff / 60}`);
-      const time =
-        min >= 60
-          ? `${parseInt(`${min / 60}`)}小时${parseInt(
-              `${min - parseInt(`${min / 60}`) * 60}`
-            )}分钟`
-          : `${parseInt(`${diff / 60}`)}分钟`;
+      const start = parseDate(res.startTime);
+      const end = res.endTime ? parseDate(res.endTime) : new Date();
+      const time = formatDuration(start, end, 1);
       const _list = [
         {
           label: "充电站点",
@@ -173,21 +158,16 @@ onLoad((options: any) => {
         },
         {
           label: "电费",
-          value: `${elecMoney.replace(reg, ",")}元`,
+          value: `${formatMoney(res.elecMoney)}元`,
         },
         {
           label: "服务费",
-          value: `${serviceMoney.replace(reg, ",")}元`,
+          value: `${formatMoney(res.serviceMoney)}元`,
         },
         {
           label: "订单金额",
-          value: `${totalMoney.replace(reg, ",")}元`,
+          value: `${formatMoney(res.totalMoney)}元`,
         },
-       /* {
-          label: "折扣金额",
-          value: `${discountAmount.replace(reg, ",")}元`,
-          discount:true
-        },*/
         {
           label: "开始时间",
           value: res.startTime,
@@ -217,7 +197,7 @@ onLoad((options: any) => {
         });
       }
       list.value = _list;
-      price.value = (res.payAmount / 100).toFixed(2);
+      price.value = fenToYuan(res.payAmount);
     })
     .catch(() => {
       uni.showModal({

+ 2 - 1
charge-front/src/pages-common/invoice/invoice.vue

@@ -33,6 +33,7 @@
 import { fetchInvoiceList, fetchInvoicePDF } from "@/api";
 import { onLoad } from "@dcloudio/uni-app";
 import { ref } from "vue";
+import { fenToYuan } from "@/utils/money";
 
 const openInvoiceId = ref();
 const email = ref();
@@ -70,7 +71,7 @@ onLoad((options: any) => {
         list.value[4].value = res[fd].bankName || "-";
         list.value[5].value = res[fd].bankAccount || "-";
         list.value[6].value = res[fd].remark || "-";
-        list.value[7].value = `${(Number(res[fd].invoiceAmount) / 100).toFixed(2)}`;
+        list.value[7].value = `${fenToYuan(res[fd].invoiceAmount)}`;
         list.value[8].value = res[fd].createTime || "-";
         openInvoiceId.value = res[fd].id;
         email.value = res[fd].email || "";

+ 3 - 2
charge-front/src/pages-user/wallet/wallet.vue

@@ -122,6 +122,7 @@ import {fetchProfile, fetchWallet, listRefund} from "../../api/user";
 import {to} from "../../utils/navigate";
 import {ref} from "vue";
 import { requireAuth } from "@/utils/auth";
+import { fenToYuan } from "@/utils/money";
 
 const user = ref();
 
@@ -220,7 +221,7 @@ const loadData = () => {
     fetchWallet(tab.value, 1, 1000).then((res: any) => {
       if (res && res.length) {
         res.forEach((item: any) => {
-          item.amount = (Number(item.amount) / 100).toFixed(2);
+          item.amount = fenToYuan(item.amount);
         });
       }
       dataList.value = res;
@@ -238,7 +239,7 @@ const loadData = () => {
         .then((u: any) => listRefund({userId: u.id, pageSize: 1000}))
         .then((res: any) => {
           let list = (res.list || []).map((item: any) => {
-            item.amount = (Number(item.refund) / 100).toFixed(2);
+            item.amount = fenToYuan(item.refund);
             item.type = 2;
             if (Array.isArray(item.successTime) && item.successTime.length >= 6) {
               item.transactionTime = item.successTime.slice(0, 3).join("-") + " " + item.successTime.slice(3, 6).join(":")