Rcjhz.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import * as React from 'react';
  2. import Box from "@mui/material/Box";
  3. import { Grid } from '@mui/material';
  4. import Tab from "@mui/material/Tab";
  5. import TabContext from "@mui/lab/TabContext";
  6. import TabList from "@mui/lab/TabList";
  7. import TabPanel from "@mui/lab/TabPanel";
  8. import Stack from "@mui/material/Stack";
  9. //registerPlugin(NestedRows);
  10. import Service from './Service';
  11. import EditableSelect from './EditableSelect';
  12. import EditableSelectGC from './EditableSelectGC';
  13. import Editable from './Editable';
  14. import Button from '@mui/material/Button';
  15. import {copy} from './utils';
  16. import {TabulatorFull as Tabulator} from "tabulator-tables"; //import Tabulator library
  17. import "tabulator-tables/dist/css/tabulator.min.css"; //import Tabulator stylesheet
  18. import './Tabulator.css';
  19. export default function Rcjhz({id, bh, tiaojiaCallback}) {
  20. const myTable = React.useRef(null);
  21. const myRef = React.useRef(null);
  22. const [detail, setDetail] = React.useState([]);
  23. var editCheck = function(cell){
  24. //cell - the cell component for the editable cell
  25. //get row data
  26. //console.log(cell);
  27. if(cell._cell.row.data['序号']) return false;
  28. return true;
  29. }
  30. function handleSelect(row){
  31. }
  32. React.useEffect(() => {
  33. myTable.current = new Tabulator(myRef.current, {
  34. index: "key",
  35. height: 600,
  36. data: detail, //link data to table
  37. reactiveData: false, //enable data reactivity
  38. dataTreeStartExpanded:true,
  39. dataTree: true,
  40. selectableRows:1, //make rows selectable
  41. editTriggerEvent:"dblclick", //trigger edit on double click
  42. dataTreeStartExpanded:function(row, level){
  43. //console.log(row);
  44. //console.log(level);
  45. return true; //expand rows where the "driver" data field is true;
  46. },
  47. columns: [ //Define Table Columns
  48. {title:"ID", field:"ID", width:80, headerSort:false,}, //never hide this column
  49. {title:"编码", field:"编码", width:120,headerSort:false,headerFilter:"input" },
  50. {title:"名称", field:"名称", width:150, headerSort:false, formatter:"textarea", headerFilter:"input"}, //hide this column first
  51. {title:"规格型号", field:"规格型号", width:70 , headerSort:false, formatter:"textarea"},
  52. {title:"单位", field:"单位", width:50, headerSort:false},
  53. {title:"数量", field:"数量", width:100, headerSort:true, sorter:"number", formatter:"money", formatterParams:{
  54. precision:4,
  55. } },
  56. {title:"单价", field:"单价", width:100, headerSort:true, sorter:"number", formatter:"money", editor: "input"},
  57. {title:"合价", field:"合价", width:100, headerSort:true, sorter:"number", formatter:"money"},
  58. {title:"产地", field:"产地", width:50, headerSort:false, },
  59. {title:"供应厂商", field:"供应厂商", width:80, headerSort:false, },
  60. {title:"人材机类别", field:"人材机类别", width:120, headerSort:true, sorter: 'string', headerFilter:"input"},
  61. {title:"主要材料标志", field:"主要材料标志", width:100, headerSort:false},
  62. {title:"主材标志", field:"主材标志", width:100, headerSort:false, },
  63. {title:"设备标志", field:"设备标志", width:100, headerSort:false, },
  64. {title:"甲供标志", field:"甲供标志", width:100, headerSort:false, },
  65. {title:"暂估价标志", field:"暂估价标志", width:100, headerSort:false, },
  66. ]
  67. });
  68. myTable.current.on("cellDblClick", function(e, cell){
  69. //e - the click event object
  70. //cell - cell component
  71. console.log(cell);
  72. });
  73. myTable.current.on("rowSelected", handleSelect);
  74. myTable.current.on("cellEdited", function(cell){
  75. //console.log("edited");
  76. //console.log();
  77. let newData = copy(cell._cell.row.data);
  78. let newDj = newData['单价'];
  79. let sl = newData['数量'];
  80. newData['合价'] = Number(newDj) * Number(sl);
  81. myTable.current.updateData([newData]);
  82. tiaojiaCallback(bh, newData['编码'], newData['名称'], newData['单位'], newDj);
  83. });
  84. myTable.current.on("tableBuilt", () => {
  85. Service.generateRencaijihuizong2(id, bh).then(x=>{
  86. myTable.current.replaceData(x);
  87. });
  88. });
  89. }, [id, bh]);
  90. return (
  91. <div ref={myRef}>
  92. </div>
  93. );
  94. }