فهرست منبع

fix: 合同管理-概括页精度计算

lanjianrong 4 سال پیش
والد
کامیت
108c5a1920

+ 6 - 3
src/pages/Contract/Content/Summary/components/Content/index.tsx

@@ -6,6 +6,8 @@ import './index.scss'
 import { dayjsFormat, formatMoney } from '@/utils/util'
 import { Tooltip } from 'antd'
 import { DualAxesConfig } from '@ant-design/charts/es/dualAxes'
+import BigNumber from 'bignumber.js'
+import { ContractType } from '@/store/mobx/contract'
 G2.registerTheme('custom-pie', {
   colors10: [ '#C7B8A1', '#9CA8B8', '#7B8B6F' ],
   colors29: [ '#DACAB1', '#ABB8CA', '#87987A' ]
@@ -29,13 +31,14 @@ interface iContentData {
 type iDualAxes = {
   month: string
   value: number
-  count: number
+  count: BigNumber.Value
 }[]
 interface iContentProps {
   data: iContentData
   type: 'expenditure' | 'income'
 }
 const Content: React.FC<iContentProps> = ({ data, type }) => {
+
   const pieConfig: PieConfig = {
     data: data.pieData,
     autoFit: true,
@@ -136,10 +139,10 @@ const Content: React.FC<iContentProps> = ({ data, type }) => {
   return (
     <div className="pi-flex-column ">
       <div className="card-body card-border">
-        <h5 className="card-title">{type === 'expenditure' ? '收入' : '支出'}合同结算进度</h5>
+        <h5 className="card-title">{type === ContractType.INCOME ? '收入' : '支出'}合同结算进度</h5>
           <div className="progress-content">
             <Tooltip title={type === 'expenditure' ? '已回款: ¥' : '已支付: ¥' + data.totalContractPriceShow}>
-              <div className={[ "progress-bar", type === 'expenditure' ? 'pi-bg-success' : 'pi-bg-red' ].join(' ')} style={{ width: (data.progress * 100) + '%' }}>
+              <div className={[ "progress-bar", type === ContractType.INCOME ? 'pi-bg-success' : 'pi-bg-red' ].join(' ')} style={{ width: (data.progress * 100) + '%' }}>
                 {data.progress * 100}%
               </div>
             </Tooltip>

+ 10 - 6
src/pages/Contract/Content/Summary/index.tsx

@@ -5,7 +5,7 @@ import React, { useEffect, useState, useMemo } from 'react'
 import { apiGetContractSurvey } from './api'
 import Content from './components/Content'
 import './index.scss'
-
+import { BigNumber } from 'bignumber.js'
 type ireturnDate = {
   [key: string]: number
 }
@@ -87,9 +87,12 @@ export default function Summary() {
     }
 
     const newDualAxes = dualAxes.map(item => {
-      return { ...item, count: (isNaN(item.value / totalContractPrice) ? 0 : (parseFloat((item.value / totalContractPrice).toFixed(2))) * 100) }
+
+      return { ...item, count: new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2) }
     })
-    const progress = totalPaidPriceShow ? (totalPaidPriceShow / totalContractPrice) : 0
+
+    let progress = parseFloat(new BigNumber(totalPaidPriceShow).dividedBy(totalContractPrice).toFixed(2))
+    isNaN(progress) && (progress = 0)
     return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalPaidPriceShow, progress }
   }, [ state.expenditureData ])
 
@@ -119,17 +122,18 @@ export default function Summary() {
       }
     }
     const newDualAxes = dualAxes.map(item => {
-      return { ...item, count: (isNaN(item.value / totalContractPrice) ? 0 : (parseFloat((item.value / totalContractPrice).toFixed(2))) * 100) }
+      return { ...item, count: new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2) }
     })
-    const progress = totalReturnPriceShow ? (totalReturnPriceShow / totalContractPrice) : 0
+    let progress = parseFloat(new BigNumber(totalReturnPriceShow).dividedBy(totalContractPrice).toFixed(2))
+    isNaN(progress) && (progress = 0)
     return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalReturnPriceShow, progress }
   }, [ state.incomeData ])
   return (
     <div className="wrap-contaniner">
       <Header title="合同概况" />
       <div className="wrap-content p-3 pi-grid pi-col-2 pi-col-space-3">
-        <Content data={expenditurePieData} type="expenditure" />
         <Content data={incomePieData} type="income" />
+        <Content data={expenditurePieData} type="expenditure" />
       </div>
     </div>
   )

+ 1 - 1
src/pages/Quality/Content/Info/Summary/columnChart.tsx

@@ -30,7 +30,7 @@ const ColumnChart: React.FC<{ data: iColumnChartProps }> = props => {
     tooltip: {
       formatter: datum => {
         const obj = { name: '', value: '' }
-        if (datum.percentage) {
+        if (Object.prototype.hasOwnProperty.call(datum, 'percentage')) {
           obj.name = '整改占总数比例'
           obj.value = datum.percentage + '%'
         } else if (datum.name && datum.name === 'rectifyed') {

+ 1 - 1
src/pages/Safe/Content/Info/Summary/columnChart.tsx

@@ -30,7 +30,7 @@ const ColumnChart: React.FC<{ data: iColumnChartProps }> = props => {
     tooltip: {
       formatter: datum => {
         const obj = { name: '', value: '' }
-        if (datum.percentage) {
+        if (Object.prototype.hasOwnProperty.call(datum, 'percentage')) {
           obj.name = '整改占总数比例'
           obj.value = datum.percentage + '%'
         } else if (datum.name && datum.name === 'rectifyed') {