Xiaopeng Zhang 6 mēneši atpakaļ
vecāks
revīzija
f1482493ee
3 mainītis faili ar 99 papildinājumiem un 37 dzēšanām
  1. 53 7
      front/src/Qingdan.js
  2. 43 17
      front/src/Service.js
  3. 3 13
      front/src/editor.js

+ 53 - 7
front/src/Qingdan.js

@@ -162,6 +162,8 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
     const cldeRef = React.useRef(null);
     const isQdrcj = React.useRef(false);
     const [selectedRowKeys, setSelectedRowKeys] = React.useState([]);
+
+    const [expandedRowKeys, setExpandedRowKeys] = React.useState([]);
     const rowSelection = {
      selectedRowKeys,
      onChange: (selectedRowKeys) => {
@@ -326,7 +328,12 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
 
       
       const handleSelection = (row) => {
-          if (row == null || row.length == 0) return;
+          if (row == null || row.length == 0) {
+               setRcjhl([]);
+               isQdrcj.current = true;
+               highlight.current = [];
+               return;
+          }
                         let qd = detail.filter(x=>x['key'] == row[0]);
                         if (qd.length > 0) {
                              Service.generateQingdanrcj(name, bh,bt,qd[0]['清单编码']).then(x=>{
@@ -439,21 +446,52 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                    <Box>
                    <Stack direction='row' spacing={2}>
                    <Button variant="outlined" onClick={() => {
-                      const [success, data] = danxiangdinge(selectedRow.current);
-                      if(success) {
-                         setDetail(data);
+                      if (selectedRowKeys.length > 0) {
+                         const [success, data] = danxiangdinge(selectedRowKeys[0]);
+                         if(success) {
+                            setDetail(data);
+                            setExpandedRowKeys([...expandedRowKeys, selectedRowKeys[0]]);
+                         }
                       }
                  
                       
                       }}
                    >单项定额</Button>
+                      <Button variant="outlined" onClick={() => {
+                      if (selectedRowKeys.length > 0) {
+                          let newData = shanchu(selectedRowKeys[0]);
+                          setDetail(newData);
+                          if (newData.filter(x=>x['key'] == selectedRowKeys[0]).length == 0) {
+                              setSelectedRowKeys([]);
+                              handleSelection([]);
+                          }
+                          
+                          
+                      }
+                      
+                 
+                      
+                      }}
+                   >删除</Button>
                    <Button variant="outlined" onClick={() => {
-                      setDetail(undo());
+                      let newData = undo();
+                      setDetail(newData);
+                      if (newData.filter(x=>x['key'] == selectedRowKeys[0]).length == 0
+                      && newData.filter(x=>x["children"].filter(y=>y['key']==selectedRowKeys[0]).length > 0).length == 0) {
+                         setSelectedRowKeys([]);
+                         handleSelection([]);
+                     }
                       
                       }}
                    >撤销</Button>
                    <Button variant="outlined" onClick={() => {
-                      setDetail(redo());
+                      let newData = redo();
+                      setDetail(newData);
+                      if (newData.filter(x=>x['key'] == selectedRowKeys[0]).length == 0
+                      && newData.filter(x=>x["children"].filter(y=>y['key']==selectedRowKeys[0]).length > 0).length == 0) {
+                         setSelectedRowKeys([]);
+                         handleSelection([]);
+                     }
                       
                       }}
                    >重做</Button>
@@ -469,6 +507,14 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                     ref = {hotRef}
                     expandable = {
                          {
+                              expandedRowKeys,
+                              onExpand: (expandable, record) => {
+                                   if (expandable) {
+                                     setExpandedRowKeys([...expandedRowKeys, record.key]);
+                                   } else {
+                                     setExpandedRowKeys(expandedRowKeys.filter((id) => record.key !== id));
+                                   }
+                                 },
                               expandRowByClick: true
                          }
                     }
@@ -556,7 +602,7 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                              ref = {hotRcjRef}
                              afterChange={(changes, source) => {
                               //console.log(hotRcjRef.current?.hotInstance?.getData());
-                              updateDercj(selectedRow.current, hotRcjRef.current?.hotInstance?.getData());
+                              updateDercj(hotRcjRef.current?.hotInstance?.getData());
                             }}
                              licenseKey="non-commercial-and-evaluation" // for non-commercial use only
                            />

+ 43 - 17
front/src/Service.js

@@ -1,3 +1,4 @@
+import { getTableHeadUtilityClass } from '@mui/material';
 import {copy, danxiangdinge_index} from './utils';
 import { v4 as uuidv4 } from 'uuid';
 class Service{
@@ -561,7 +562,7 @@ class Service{
             }
         }
         let qd = this.cache.filter(x=>x["清单编码"] == qdbm)[0];
-        let de = qd["__children"].filter(x=>x["清单编码"]==debm)[0];
+        let de = qd["children"].filter(x=>x["清单编码"]==debm)[0];
         return de["dercj"];
         
         
@@ -808,23 +809,47 @@ async generateQingdanTuijian(name, bh, bt, bm) {
         return copy(this.cache);
     }
 
-    shanchu(qdbm, debm) {
-        let newData = this.cache.map(x=>{
-            if (x["清单编码"] == qdbm) {
-                let y = copy(x);
-                let origin = y["__children"];
-                let trans = origin.filter(z=>z["清单编码"]!=debm);
-                y["__children"] = trans;
-                return y;
-            } else {
-                return x;
-            }
-        });
-        //////////push op
+    shanchu(key) {
+        if (this.cache.filter(x=>x['key'] == key).length > 0) {
+            ///qd
+            let newData = this.cache.map(x=>{
+                if (x["key"] == key) {
+                    let y = copy(x);
+                    
+                    y["children"] = [];
+                    return y;
+                } else {
+                    return x;
+                }
+            });
+            //////////push op
+            this.push_op(newData);
+            /////////////////
+            this.cache = copy(newData);
+            return newData;
+
+        } else {
+            let qd = this.cache.filter(x=>x["children"].filter(y=>y['key'] == key).length > 0)[0];
+            let qdbm = qd['清单编码'];
+            let newData = this.cache.map(x=>{
+                if (x["清单编码"] == qdbm) {
+                    let y = copy(x);
+                    let origin = y["children"];
+                    let trans = origin.filter(z=>z["key"]!=key);
+                    y["children"] = trans;
+                    return y;
+                } else {
+                    return x;
+                }
+            });
+            //////////push op
         this.push_op(newData);
         /////////////////
         this.cache = copy(newData);
         return newData;
+        }
+        
+        
 
 
     }
@@ -856,10 +881,11 @@ async generateQingdanTuijian(name, bh, bt, bm) {
 
     danxiangdinge(row) {
         let bh = danxiangdinge_index(this.cache);
-        let selected = this.cache[row];
-        if (selected && selected["序号"] != null && selected["序号"].length > 0) {
+        
+        if (this.cache.filter(x=>x['key'] == row).length > 0) {
+            let selected = this.cache.filter(x=>x['key'] == row)[0];
             let danwei = selected["单位"];
-            let children = selected["__children"];
+            let children = selected["children"];
             children.push({
                 '操作': '',
                 '序号': null,

+ 3 - 13
front/src/editor.js

@@ -19,21 +19,11 @@ export const redo = () => {
     return newData;
 };
 
-export const shanchu = (hotRef, selectedRow) => {
+export const shanchu = ( selectedRow) => {
    
-    let deleted = hotRef.current?.hotInstance?.getData()[selectedRow.current][2];
-    //hotRef.current?.hotInstance?.alter('remove_row', selectedRow.current, 1);
-    let qdbm = null;
-            for (let i = selectedRow.current - 1;  i > -1; i= i - 1) {
-                let above = hotRef.current?.hotInstance?.getData()[i];
-                if (above[1] != null) {
-                    qdbm = above[2];
-                    break;
-                }
-                 
-            }
     
-    let newData = Service.shanchu(qdbm, deleted);
+    
+    let newData = Service.shanchu(selectedRow);
     
     return newData;
   };