Sfoglia il codice sorgente

处理单据浮点失真

huangbin 4 anni fa
parent
commit
b692d4d904

+ 10 - 2
src/common/setup/table/list.ts

@@ -1,12 +1,13 @@
 import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
+import { getDecimalsNum } from '@/utils/number';
 import { ref } from 'vue';
 
 /**
  * 请求表格数据通用方法
- * @param fn 
+ * @param ishandleFloatErr 是否处理浮点失真问题 
  * @returns 
  */
-export function queryTableList<T>() {
+export function queryTableList<T>(ishandleFloatErr = false) {
     // 加载状态
     const loading = ref<boolean>(false);
     // 表格数据
@@ -24,6 +25,13 @@ export function queryTableList<T>() {
                         return { ...e, key: String(i) };
                     }
                 })
+                if (ishandleFloatErr) {  // 折中方案:处理浮点失真,如果页面卡顿,则需要服务处理
+                    result?.forEach((e: T, i: number) => {
+                        for (const item in e) {
+                            e[item] = getDecimalsNum(e[item])
+                        }
+                    });
+                }
                 tableList.value = result
                 return result
             })

+ 19 - 0
src/utils/number/index.ts

@@ -0,0 +1,19 @@
+/**
+ * 折中方案:处理浮点失真,如果页面卡顿,则需要服务处理
+ * @param val 
+ * @param decimal 需要保留小数位 默认2 
+ * @param maxCount 最大小数位 超过的时候需要对数值进行处理 
+ * @returns 
+ */
+export function getDecimalsNum(val: any, decimal = 2, maxCount = 6) {
+    let result = val
+    if (typeof val === 'number') {
+        const str = val.toString();
+        const num = str.indexOf('.') + 1;
+        const count = str.length - num;
+        if (count > maxCount) {
+            result = val.toFixed(decimal)
+        }
+    }
+    return result
+}

+ 5 - 5
src/views/platinum/platinum_document_query/list/order/index.vue

@@ -15,10 +15,10 @@
           <BtnList :btnList="firstBtn"
                    @onClick="btnClick(record)" />
         </template>
-          <!-- 账户类型 -->
-          <template #userinfotype="{ record }">
-              <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
-          </template>
+        <!-- 账户类型 -->
+        <template #userinfotype="{ record }">
+          <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
+        </template>
       </a-table>
     </contextMenu>
     <!-- <ControlModal :selectedRow="selectedRow" /> -->
@@ -44,7 +44,7 @@ export default defineComponent({
         // 表格操作按钮列表
         const [firstBtn] = _getBtnList('platinum_document_query_order', false).value;
         // 表格列表数据
-        const { loading, tableList, queryTable } = queryTableList();
+        const { loading, tableList, queryTable } = queryTableList(true);
         function search(value: any) {
             const { includesub, goodsid, filtername, userid, ordertime, userinfotype } = value;
             const len = ordertime.length;

+ 5 - 5
src/views/platinum/platinum_document_query/list/position/index.vue

@@ -15,10 +15,10 @@
           <BtnList :btnList="firstBtn"
                    @onClick="btnClick(record)" />
         </template>
-          <!-- 账户类型 -->
-          <template #userinfotype="{ record }">
-              <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
-          </template>
+        <!-- 账户类型 -->
+        <template #userinfotype="{ record }">
+          <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
+        </template>
       </a-table>
     </contextMenu>
     <!-- <ControlModal :selectedRow="selectedRow" /> -->
@@ -44,7 +44,7 @@ export default defineComponent({
         // 表格操作按钮列表
         const [firstBtn] = _getBtnList('platinum_document_query_position', false).value;
         // 表格列表数据
-        const { loading, tableList, queryTable } = queryTableList<QueryTradePositionRsp>();
+        const { loading, tableList, queryTable } = queryTableList<QueryTradePositionRsp>(true);
         function search(value: any) {
             const { includesub, goodsid, filtername, userid, userinfotype } = value;
             const param: QueryTradePositionReq = {

+ 9 - 9
src/views/platinum/platinum_document_query/list/success/index.vue

@@ -15,14 +15,14 @@
           <BtnList :btnList="firstBtn"
                    @onClick="btnClick(record)" />
         </template>
-          <!-- 账户类型 -->
-          <template #userinfotype="{ record }">
-              <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
-          </template>
-          <!-- 成交类型 -->
-          <template #buyorsell="{ record }">
-              <a>{{ record.buyorsell === 1 ? "卖" : "买" }}</a>
-          </template>
+        <!-- 账户类型 -->
+        <template #userinfotype="{ record }">
+          <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
+        </template>
+        <!-- 成交类型 -->
+        <template #buyorsell="{ record }">
+          <a>{{ record.buyorsell === 1 ? "卖" : "买" }}</a>
+        </template>
       </a-table>
     </contextMenu>
     <!-- <ControlModal :selectedRow="selectedRow" /> -->
@@ -49,7 +49,7 @@ export default defineComponent({
         // 表格操作按钮列表
         const [firstBtn] = _getBtnList('platinum_document_query_success', false).value;
         // 表格列表数据
-        const { loading, tableList, queryTable } = queryTableList();
+        const { loading, tableList, queryTable } = queryTableList(true);
         function search(value: any) {
             const { includesub, goodsid, filtername, userid, ordertime, userinfotype } = value;
             const len = ordertime.length;

+ 5 - 5
src/views/platinum/platinum_document_query/list/waiting/index.vue

@@ -15,10 +15,10 @@
           <BtnList :btnList="firstBtn"
                    @onClick="btnClick(record)" />
         </template>
-          <!-- 账户类型 -->
-          <template #userinfotype="{ record }">
-              <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
-          </template>
+        <!-- 账户类型 -->
+        <template #userinfotype="{ record }">
+          <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
+        </template>
       </a-table>
     </contextMenu>
     <!-- <ControlModal :selectedRow="selectedRow" /> -->
@@ -44,7 +44,7 @@ export default defineComponent({
         // 表格操作按钮列表
         const [firstBtn] = _getBtnList('platinum_document_query_waiting', false).value;
         // 表格列表数据
-        const { loading, tableList, queryTable } = queryTableList();
+        const { loading, tableList, queryTable } = queryTableList(true);
         function search(value: any) {
             const { includesub, goodsid, filtername, userid, ordertime, userinfotype } = value;
             const len = ordertime.length;

+ 2 - 13
src/views/report/setup.ts

@@ -1,6 +1,7 @@
 import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo'
 import { getUsrId } from '@/services/bus/user'
 import { FinanceReportReq } from "@/services/go/ermcp/report/interface"
+import { getDecimalsNum } from '@/utils/number'
 import moment, { Moment } from "moment"
 import { ref, SetupContext } from "vue"
 import { reportCycleType, reportCyleTimeType } from "./enum"
@@ -103,6 +104,7 @@ export function queryTableList<T>(fn: Function) {
         queryResultLoadingAndInfo(fn, loading, param).then(res => {
             const result = res?.map((e: T, i: number) => {
                 for (const item in e) {
+                    // 折中方案:处理浮点失真,如果页面卡顿,则需要服务处理
                     e[item] = getDecimalsNum(e[item])
                 }
                 return { ...e, key: String(i) };
@@ -112,16 +114,3 @@ export function queryTableList<T>(fn: Function) {
     }
     return { loading, tableList, queryTable }
 }
-
-function getDecimalsNum(val: any) {
-    let result = val
-    if (typeof val === 'number') {
-        const str = val.toString();
-        const num = str.indexOf('.') + 1;
-        const count = str.length - num;
-        if (count > 6) {
-            result = val.toFixed(2)
-        }
-    }
-    return result
-}