Parcourir la source

Merge branch 'develop' of http://120.55.44.4:10080/xujunjie/gt_client_pad into develop

xujunjie il y a 1 an
Parent
commit
2c3a1c4d72
2 fichiers modifiés avec 110 ajouts et 40 suppressions
  1. 51 10
      src/pages/Home/ChemCostComparison.js
  2. 59 30
      src/pages/Home/EnergyCostComparison.js

+ 51 - 10
src/pages/Home/ChemCostComparison.js

@@ -6,8 +6,9 @@ import {
   getChemicalAgents,
   getComparisonData,
 } from '@/services/OperationManagement';
+import { queryConditionSnapshot } from '@/services/SmartOps';
 import { UnityAction } from '@/utils/utils';
-import { useParams } from '@umijs/max';
+import { useParams, useRequest } from '@umijs/max';
 import { Tabs, message } from 'antd';
 import dayjs from 'dayjs';
 import { useEffect, useState } from 'react';
@@ -63,14 +64,14 @@ const CostComparison = () => {
           className={`password-eye ${open ? 'open' : ''}`}
         ></div>
       </PageTitle>
-      <ChemCost open={open} />
+      <ChemCost open={open} showTheory />
     </PageContent>
   );
 };
 
 export default CostComparison;
 
-export const ChemCost = ({ open }) => {
+export const ChemCost = ({ open, showTheory = false }) => {
   const { projectId } = useParams();
 
   const [chartData, setChartData] = useState([]);
@@ -94,6 +95,35 @@ export const ChemCost = ({ open }) => {
     end: defaultTime.e_time,
   };
 
+  const getValue = (str) => {
+    const result = str?.match(/.*?(\d+(?:\.\d+)?)\D*$/);
+    if (result && result[1]) return result[1];
+    return 0;
+  };
+
+  const { data: snapshot } = useRequest(queryConditionSnapshot, {
+    defaultParams: [{ project_id: projectId }],
+    formatResult: (result) => {
+      const otcCost = Number(getValue(result.data.otc_cost_unit));
+      let resultText = `当前药耗持平理论值 ${
+        result?.data?.otc_unit_theory || 0
+      }KWh/m³`;
+      if (otcCost) {
+        if (otcCost > result.data.otc_unit_theory) {
+          resultText = `当前药耗高于理论值 ${result.data.otc_unit_theory}KWh/m³`;
+        }
+        if (otcCost === result.data.otc_unit_theory) {
+          resultText = `当前药耗持平理论值 ${result.data.otc_unit_theory}KWh/m³`;
+        }
+        if (otcCost < result.data.otc_unit_theory) {
+          resultText = `当前药耗低于理论值 ${result.data.otc_unit_theory}KWh/m³`;
+        }
+      }
+      console.log({ ...result.data, resultText });
+      return { ...result.data, resultText };
+    },
+  });
+
   const getChartData = () => {
     // 构建请求列表
     const queryList = [];
@@ -278,24 +308,35 @@ export const ChemCost = ({ open }) => {
   }, []);
 
   return (
-    <>
+    <div className="card-box" style={{ position: 'relative' }}>
+      <div
+        style={{
+          fontSize: '0.28rem',
+          position: 'absolute',
+          top: '-0.6rem',
+          right: '0.3rem',
+          display: `${showTheory ? '' : 'none'}`,
+        }}
+      >
+        {snapshot?.resultText}
+      </div>
       <div className={styles.curEnergyCost}>
         <div className={styles.item}>
           <div className={styles.value}>
-            {open ? topValues.chemPer : '***'}
+            {open ? getValue(snapshot?.otc_unit || '') : '***'}
             <span className={styles.unit}>kg/t</span>
           </div>
-          <div className={styles.name}>近一天吨水药耗</div>
+          <div className={styles.name}>近一小时吨水药耗</div>
         </div>
         <div className={styles.item}>
           <div className={styles.value}>
-            {open ? topValues.chemUser : '***'}
+            {open ? getValue(snapshot?.otc || '') : '***'}
             <span className={styles.unit}>kg</span>
           </div>
-          <div className={styles.name}>近一药量</div>
+          <div className={styles.name}>近一小时药量</div>
         </div>
       </div>
-      <div className="card-box" style={{ padding: '0.2rem' }}>
+      <div style={{ padding: '0.2rem' }}>
         {/* 使用Tabs来展示所有药的标签 */}
         <div className="tabs">
           {chemList?.map((item) => (
@@ -350,6 +391,6 @@ export const ChemCost = ({ open }) => {
           </div>
         )}
       </div>
-    </>
+    </div>
   );
 };

+ 59 - 30
src/pages/Home/EnergyCostComparison.js

@@ -3,9 +3,10 @@ import ChartModule from '@/components/ManagementPage/chartModule';
 import PageContent from '@/components/PageContent';
 import PageTitle from '@/components/PageTitle';
 import { getComparisonData } from '@/services/OperationManagement';
+import { queryConditionSnapshot } from '@/services/SmartOps';
 import { UnityAction } from '@/utils/utils';
 import { LineChartOutlined } from '@ant-design/icons';
-import { history, useParams } from '@umijs/max';
+import { history, useParams, useRequest } from '@umijs/max';
 import { message } from 'antd';
 import dayjs from 'dayjs';
 import { useEffect, useState } from 'react';
@@ -48,7 +49,7 @@ const CostComparison = () => {
           }}
           style={{ marginLeft: '0.1rem' }}
           className={`password-eye ${open ? 'open' : ''}`}
-        ></div>
+        />
       </PageTitle>
       <EnergyCost open={open} />
     </PageContent>
@@ -75,6 +76,34 @@ export const EnergyCost = ({ open, detailClick }) => {
     end: defaultTime.e_time,
   };
 
+  const getValue = (str) => {
+    const result = str?.match(/.*?(\d+(?:\.\d+)?)\D*$/);
+    if (result && result[1]) return result[1];
+    return 0;
+  };
+
+  const { data: snapshot } = useRequest(queryConditionSnapshot, {
+    defaultParams: [{ project_id: projectId }],
+    formatResult: (result) => {
+      const elec = Number(getValue(result.data.elec_unit));
+      let resultText = `当前电耗持平理论值 ${
+        result?.data?.elec_unit_theory || 0
+      }KWh/m³`;
+      if (elec) {
+        if (elec > result.data.elec_unit_theory) {
+          resultText = `当前电耗高于理论值 ${result.data.elec_unit_theory}KWh/m³`;
+        }
+        if (elec === result.data.elec_unit_theory) {
+          resultText = `当前电耗持平理论值 ${result.data.elec_unit_theory}KWh/m³`;
+        }
+        if (elec < result.data.elec_unit_theory) {
+          resultText = `当前电耗低于理论值 ${result.data.elec_unit_theory}KWh/m³`;
+        }
+      }
+      return { ...result.data, resultText };
+    },
+  });
+
   const getChartData = () => {
     // 构建请求列表
     const queryList = [];
@@ -260,6 +289,17 @@ export const EnergyCost = ({ open, detailClick }) => {
       className="card-box"
       style={{ padding: '0.2rem', position: 'relative' }}
     >
+      <div
+        style={{
+          fontSize: '0.28rem',
+          position: 'absolute',
+          top: '-0.6rem',
+          right: '0.3rem',
+          display: `${detailClick ? 'none' : ''}`,
+        }}
+      >
+        {snapshot?.resultText}
+      </div>
       <LineChartOutlined
         style={{
           fontSize: '0.4rem',
@@ -276,23 +316,12 @@ export const EnergyCost = ({ open, detailClick }) => {
             borderRight: '1px solid #eaeaea',
             borderBottom: '1px solid #eaeaea',
           }}
-          onClick={goEnergyDetail}
-        />
-        <div className={styles.curEnergyCost}>
-          <div
-            className={styles.item}
-            style={{
-              borderRight: '1px solid #eaeaea',
-              borderBottom: '1px solid #eaeaea',
-            }}
-          >
-            <div className={styles.value}>
-              {open ? curElecPerCost : '***'}
-              <span className={styles.unit}>kwh/m³</span>
-            </div>
-            <div className={styles.name}>近一天吨水电耗</div>
+        >
+          <div className={styles.value}>
+            {open ? getValue(snapshot?.elec_unit || '') : '***'}
+            <span className={styles.unit}>kWh/t</span>
           </div>
-          <div className={styles.name}>近一吨水电耗</div>
+          <div className={styles.name}>近一小时吨水电耗</div>
         </div>
         <div
           className={styles.item}
@@ -301,20 +330,20 @@ export const EnergyCost = ({ open, detailClick }) => {
           }}
         >
           <div className={styles.value}>
-            {open ? curElecUsed : '***'}
+            {open ? getValue(snapshot?.elec || '') : '***'}
             <span className={styles.unit}>kWh</span>
           </div>
-          <div
-            className={styles.item}
-            style={{
-              borderRight: '1px solid #eaeaea',
-            }}
-          >
-            <div className={styles.value}>
-              {open ? curElecPerCost : '***'}
-              <span className={styles.unit}>kwh/m³</span>
-            </div>
-            <div className={styles.name}>当月吨水电耗</div>
+          <div className={styles.name}>近一小时实际用电量</div>
+        </div>
+        <div
+          className={styles.item}
+          style={{
+            borderRight: '1px solid #eaeaea',
+          }}
+        >
+          <div className={styles.value}>
+            {open ? curElecPerCost : '***'}
+            <span className={styles.unit}>kWh/t</span>
           </div>
           <div className={styles.name}>当月吨水电耗</div>
         </div>