فهرست منبع

fix: 数字计算保留真实位数

lanjianrong 4 سال پیش
والد
کامیت
89b463343c

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

@@ -26,6 +26,8 @@ interface iContentData {
   totalContractPriceShow: number
   totalReturnPriceShow?: number
   totalPaidPriceShow?: number
+  unTotalReturnPriceShow?: number
+  unTotalPaidPriceShow?: number
 }
 
 type iDualAxes = {
@@ -92,7 +94,7 @@ const Content: React.FC<iContentProps> = ({ data, type }) => {
         const obj = { name: '', value: formatMoney(datum.value) }
         if (datum.count || datum.count === 0) {
           obj.name = '占总金额比例'
-          obj.value = datum.count + '%'
+          obj.value = (isNaN(datum.count) ? 0 : datum.count) + '%'
           return obj
         }
         if (type === ContractType.INCOME) {
@@ -142,12 +144,12 @@ const Content: React.FC<iContentProps> = ({ data, type }) => {
       <div className="card-body card-border">
         <h5 className="card-title">{type === ContractType.INCOME ? '收入' : '支出'}合同结算进度</h5>
           <div className="progress-content">
-            <Tooltip title={type === ContractType.INCOME ? '已回款: ¥' : '已支付: ¥' + data.totalContractPriceShow}>
+            <Tooltip title={type === ContractType.INCOME ? ('已回款: ¥' + formatMoney(data.totalReturnPriceShow)): ('已支付: ¥' + formatMoney(data.totalPaidPriceShow))}>
               <div className={[ "progress-bar", type === ContractType.INCOME ? 'pi-bg-success' : 'pi-bg-red' ].join(' ')} style={{ width: data.progress + '%' }}>
                 {data.progress}%
               </div>
             </Tooltip>
-            <Tooltip title={type === ContractType.INCOME ? '未回款:¥' + data.totalReturnPriceShow : '未支付:¥' + data.totalPaidPriceShow}>
+            <Tooltip title={type === ContractType.INCOME ? ('未回款:¥' + formatMoney(data.unTotalReturnPriceShow)) : ('未支付:¥' + formatMoney(data.unTotalPaidPriceShow))}>
               <div className="progress-bar pi-bg-gray" style={{ width: (100 - data.progress) + '%' }} >
                 {parseFloat(new BigNumber(100).minus(data.progress).toFixed(2))}%
               </div>
@@ -165,7 +167,7 @@ const Content: React.FC<iContentProps> = ({ data, type }) => {
               <span className="pi-text-center">{type === ContractType.INCOME ? '收入' : '支出'}合同金额</span>
             </div>
             <div className="card-body card-border pi-flex-column pi-mg-tb-15">
-              <h5 className="card-title">{formatMoney(new BigNumber(data.totalContractPriceShow).minus(type === ContractType.INCOME ? data.totalReturnPriceShow || 0 : data.totalPaidPriceShow || 0))}</h5>
+              <h5 className="card-title">{formatMoney(parseFloat(new BigNumber(data.totalContractPriceShow).minus(type === ContractType.INCOME ? data.totalReturnPriceShow || 0 : data.totalPaidPriceShow || 0).toFixed(2)))}</h5>
               <span className="pi-text-center">{type === ContractType.INCOME ? '未回款' : '未支付'}</span>
             </div>
             <div className="card-body card-border pi-flex-column">

+ 12 - 5
src/pages/Contract/Content/Summary/index.tsx

@@ -87,15 +87,17 @@ export default function Summary() {
     }
 
     const newDualAxes = dualAxes.map(item => {
-
-      return { ...item, count: new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2) }
+      const isNan = new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).isNaN()
+      return { ...item, count: isNan ? 0 : parseFloat(new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2)) }
     })
 
 
     let progress = parseFloat(new BigNumber(totalPaidPriceShow).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2))
 
+    const unTotalPaidPriceShow = parseFloat(new BigNumber(totalContractPrice).minus(totalPaidPriceShow).toFixed(2))
+
     isNaN(progress) && (progress = 0)
-    return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalPaidPriceShow, progress }
+    return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalPaidPriceShow, unTotalPaidPriceShow, progress }
   }, [ state.expenditureData ])
 
 
@@ -125,12 +127,17 @@ export default function Summary() {
       }
     }
     const newDualAxes = dualAxes.map(item => {
-      return { ...item, count: new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2) }
+      const isNan = new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).isNaN()
+      return { ...item, count: isNan ? 0 : parseFloat(new BigNumber(item.value).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2)) }
     })
 
     let progress = parseFloat(new BigNumber(totalReturnPriceShow).dividedBy(totalContractPrice).multipliedBy(100).toFixed(2))
     isNaN(progress) && (progress = 0)
-    return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalReturnPriceShow, progress }
+
+    const unTotalReturnPriceShow = parseFloat(new BigNumber(totalContractPrice).minus(totalReturnPriceShow).toFixed(2))
+
+
+    return { pieData, returnDate: newDualAxes, totalContractPrice, totalContractPriceShow, totalReturnPriceShow, unTotalReturnPriceShow, progress }
   }, [ state.incomeData ])
   return (
     <div className="wrap-contaniner">

+ 15 - 8
src/pages/Quality/Content/Info/Detail/components/Modal/index.tsx

@@ -84,14 +84,13 @@ const AuditModal: React.FC<iAuditModalProps> = props => {
 
   useEffect(() => {
     if (visible && type === 'pass') {
-      if(curAuditor.progress === '1') {
+      if (curAuditor.progress === '1') {
         form.setFieldsValue({ opinion: '已按要求整改完成。' })
       }
 
       if (isLastAuditor && auditors.findIndex(item => item.progress === '1') !== -1) {
 
         const auditor = auditors.find(item => item.progress === '1')
-        console.log('auditor', auditor)
 
         auditor && (setUser({ ...user, id: auditor.audit_id, company: auditor.company, name: auditor.name, position: auditor.position }))
       }
@@ -140,7 +139,7 @@ const AuditModal: React.FC<iAuditModalProps> = props => {
   // 初始化审批退回下拉选择框
   const initAuditBackGroup = () => {
     const newGroup: iAccountGroupItem[] = []
-    for (let index = 0; index < 3; index++) {
+    for (let index = 0; index < 4; index++) {
       if (index === 0) {
         const newAuditors = auditors
           .filter(item => item.progress === '' && item.audit_order < curAuditor.auditOrder)
@@ -148,10 +147,10 @@ const AuditModal: React.FC<iAuditModalProps> = props => {
 
             return mapUser(item.name, item.id, item.position, item.company, item.mobile)
           })
-          newGroup.push({ value: '检查人', children: newAuditors })
-        }
-        if (index === 1) {
-          const newAuditors = auditors
+        newGroup.push({ value: '检查人', children: newAuditors })
+      }
+      if (index === 1) {
+        const newAuditors = auditors
           .filter(item => item.progress === '0' && item.audit_order < curAuditor.auditOrder)
           .map(item => {
             return mapUser(item.name, item.id, item.position, item.company, item.mobile)
@@ -166,6 +165,14 @@ const AuditModal: React.FC<iAuditModalProps> = props => {
           })
         newGroup.push({ value: '整改', children: newAuditors })
       }
+      if (index === 3) {
+        const newAuditors = auditors
+        .filter(item => item.progress === '2' && item.audit_order < curAuditor.auditOrder)
+        .map(item => {
+          return mapUser(item.name, item.id, item.position, item.company, item.mobile)
+        })
+      newGroup.push({ value: '复查', children: newAuditors })
+      }
 
     }
     function mapUser(name: string, id: string, position: string, company: string, mobile: string) {
@@ -289,7 +296,7 @@ const AuditModal: React.FC<iAuditModalProps> = props => {
               <>
                 <div className="pi-bordered pi-warning">
                   <span>已选择退回流程: </span>
-                  <span>{user.name}</span>
+                  <span>{user.name}-{user.position}-{user.company}</span>
                 </div>
                 <Form.Item name="opinion" label="审批意见">
                   <Input.TextArea rows={5} />

+ 1 - 1
src/utils/util.ts

@@ -209,7 +209,7 @@ const formatDate = (d: string) => {
 
 // 数字千分位
 const formatMoney = (num: string | number | undefined | BigNumber.Value) => {
-  if (!num) return '0.00'
+  if (!num) return '0'
   const newNum = new BigNumber(num).toFormat()
   return newNum.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
 }