Browse Source

修改保存现金流时计算psr_json_data出错问题

Renxy 1 năm trước cách đây
mục cha
commit
88e0619fd5
1 tập tin đã thay đổi với 86 bổ sung67 xóa
  1. 86 67
      src/pages/PSRManage/detail.js

+ 86 - 67
src/pages/PSRManage/detail.js

@@ -38,95 +38,100 @@ const ZeroNineType = {
   Construction: '09-060', //土建分包费用(包括增值税)
 };
 
-const preActConfig = [
+const actConfig = [
+  //实际支出
   {
     type: ZeroNineType.Equipment,
-    originC: 6,
+    originC: 8,
     originR: { begin: 6, end: 297 }, //总的减上面所有的
-    fill: { c: 5, r: 36 },
-    num: 293,
+    fill: { c: 3, r: 36 },
+    num: 291,
   },
   {
     type: ZeroNineType.Production,
-    originC: 6,
+    originC: 8,
     originR: { begin: 17, end: 27 },
     //填充到psr表中的位置
-    fill: { c: 5, r: 37 },
-    num: 301,
+    fill: { c: 3, r: 37 },
+    num: 299,
   },
   {
     type: ZeroNineType.UF,
-    originC: 6,
+    originC: 8,
     originR: { begin: 6, end: 16 },
-    fill: { c: 5, r: 38 },
-    num: 309,
+    fill: { c: 3, r: 38 },
+    num: 307,
   },
   {
     type: ZeroNineType.AI,
-    originC: 6,
+    originC: 8,
     originR: { begin: 172, end: 192 },
-    fill: { c: 5, r: 39 },
-    num: 317,
+    fill: { c: 3, r: 39 },
+    num: 315,
   },
   {
     type: ZeroNineType.Install,
-    originC: 6,
+    originC: 8,
     originR: { begin: 214, end: 224 },
-    fill: { c: 5, r: 40 },
-    num: 325,
+    fill: { c: 3, r: 40 },
+    num: 323,
   },
   {
     type: ZeroNineType.Construction,
-    originC: 6,
-    originR: { begin: 214, end: 224 },
-    fill: { c: 5, r: 41 },
-    num: 333,
+    originC: 8,
+    originR: { begin: 225, end: 235 },
+    fill: { c: 3, r: 41 },
+    num: 331,
   },
+];
+const preCeConfig = [
+  //预测列
   {
     type: ZeroNineType.Equipment,
-    originC: 8,
+    originC: 6,
     originR: { begin: 6, end: 297 }, //总的减上面所有的
-    fill: { c: 3, r: 36 },
-    num: 291,
+    fill: { c: 5, r: 36 },
+    num: 293,
   },
   {
     type: ZeroNineType.Production,
-    originC: 8,
+    originC: 6,
     originR: { begin: 17, end: 27 },
     //填充到psr表中的位置
-    fill: { c: 3, r: 37 },
-    num: 299,
+    fill: { c: 5, r: 37 },
+    num: 301,
   },
   {
     type: ZeroNineType.UF,
-    originC: 8,
+    originC: 6,
     originR: { begin: 6, end: 16 },
-    fill: { c: 3, r: 38 },
-    num: 307,
+    fill: { c: 5, r: 38 },
+    num: 309,
   },
   {
     type: ZeroNineType.AI,
-    originC: 8,
+    originC: 6,
     originR: { begin: 172, end: 192 },
-    fill: { c: 3, r: 39 },
-    num: 315,
+    fill: { c: 5, r: 39 },
+    num: 317,
   },
   {
     type: ZeroNineType.Install,
-    originC: 8,
+    originC: 6,
     originR: { begin: 214, end: 224 },
-    fill: { c: 3, r: 40 },
-    num: 323,
+    fill: { c: 5, r: 40 },
+    num: 325,
   },
   {
     type: ZeroNineType.Construction,
-    originC: 8,
-    originR: { begin: 214, end: 224 },
-    fill: { c: 3, r: 41 },
-    num: 331,
+    originC: 6,
+    originR: { begin: 225, end: 235 },
+    fill: { c: 5, r: 41 },
+    num: 333,
   },
 ];
 const curMonthConfig = [
+  //当月发生额
   {
     type: ZeroNineType.Equipment,
     originC: null,
@@ -165,7 +170,7 @@ const curMonthConfig = [
   {
     type: ZeroNineType.Construction,
     originC: null,
-    originR: { begin: 214, end: 224 },
+    originR: { begin: 225, end: 235 },
     fill: { c: 7, r: 41 },
     num: 335,
   },
@@ -558,9 +563,7 @@ const PSRDetail = () => {
           return { ...item, originC };
         });
       }
-      allData = getPsrDataByAct([...preActConfig, ...newMonthConfig]);
-
-      console.log(allData);
+      allData = getPsrDataByAct(actConfig, preCeConfig, newMonthConfig);
     }
 
     const params = {
@@ -585,32 +588,48 @@ const PSRDetail = () => {
     return originC;
   };
 
-  const getPsrDataByAct = (configList) => {
+  const getPsrDataByAct = (...list) => {
     const luckyData = luckysheetRef.current?.toJson();
-    let otherValueTotal = 0; //获取除设备费之外的所有费用的和
-    const preValues = configList.map((item) => {
-      const celldata = luckyData.data[0].celldata;
-      const {
-        type,
-        originC,
-        num,
-        originR: { begin, end },
-      } = item;
-
-      let value = 0;
-      for (let i = begin; i <= end; i++) {
-        const item = celldata.find((item) => item.c == originC && item.r == i);
-        if (item?.v?.v) value += item.v.v;
-      }
-      if (type !== ZeroNineType.Equipment) otherValueTotal += value;
-      return { num, value };
+    const fun = (configList) => {
+      let otherValueTotal = 0; //获取除设备费之外的所有费用的和
+      const preValues = configList.map((item) => {
+        const celldata = luckyData.data[0].celldata;
+        const {
+          type,
+          originC,
+          num,
+          originR: { begin, end },
+        } = item;
+
+        let value = 0;
+        for (let i = begin; i <= end; i++) {
+          const item = celldata.find(
+            (item) => item.c == originC && item.r == i,
+          );
+          if (item?.v?.v) value += item.v.v;
+        }
+        if (type !== ZeroNineType.Equipment) otherValueTotal += value;
+        return { num, value };
+      });
+      //获取设备值
+      const EquPreItem = preValues.find((item) => {
+        const shebeiNum = configList.find(
+          (cur) => cur.type == ZeroNineType.Equipment,
+        )?.num;
+        return item.num == shebeiNum;
+      });
+      //全部的费用 减去 除设备费之外的所有费用的和 得到设备费
+      if (EquPreItem?.value)
+        EquPreItem.value = EquPreItem?.value - otherValueTotal;
+      return preValues;
+    };
+    let result = [];
+    list.forEach((item) => {
+      const list = fun(item);
+      result = [...result, ...list];
     });
-    const EquPreItem = preValues.find(
-      (item) => item.type == ZeroNineType.Equipment,
-    );
-    if (EquPreItem?.value)
-      EquPreItem.value = EquPreItem?.value - otherValueTotal; //全部的费用 减去 除设备费之外的所有费用的和 得到设备费
-    console.log('------预算列的值---------', preValues);
+
+    console.log('------预算列的值---------', result);
     return preValues;
   };