Zjcs2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import * as React from 'react';
  2. import Box from "@mui/material/Box";
  3. import {RichTreeView } from "@mui/x-tree-view/RichTreeView";
  4. import { Grid } from '@mui/material';
  5. import Tab from "@mui/material/Tab";
  6. import Tabs from '@mui/material/Tabs';
  7. import FormControl from '@mui/material/FormControl';
  8. import InputLabel from '@mui/material/InputLabel';
  9. import Select from '@mui/material/Select';
  10. import MenuItem from '@mui/material/MenuItem';
  11. import { v4 as uuidv4 } from 'uuid';
  12. import {copy} from './utils';
  13. import TabContext from "@mui/lab/TabContext";
  14. import TabList from "@mui/lab/TabList";
  15. import TabPanel from "@mui/lab/TabPanel";
  16. import Stack from "@mui/material/Stack";
  17. import Service from './Service';
  18. import {TabulatorFull as Tabulator} from "tabulator-tables"; //import Tabulator library
  19. import "tabulator-tables/dist/css/tabulator.min.css"; //import Tabulator stylesheet
  20. import './Tabulator.css';
  21. export default function Zjcs2({name, bh, zjcsCallback}) {
  22. const [detail, setDetail] = React.useState([
  23. {
  24. "序号" : null, "清单编码": null, "名称" : null, "计算基数" : null,
  25. "计算基础" : null, "费率" : null, "金额" : null, "项目类别" : null}
  26. ]);
  27. const [cankao, setCankao] = React.useState([
  28. ]);
  29. const myRef = React.useRef(null);
  30. const myTable = React.useRef(null);
  31. const cankaoRef = React.useRef(null);
  32. const cankaoTable = React.useRef(null);
  33. const hotRef = React.useRef(null);
  34. const allRef = React.useRef([]);
  35. const [value, setValue] = React.useState(10);
  36. const [valueTab, setValueTab] = React.useState("1");
  37. React.useEffect(
  38. () => {
  39. myTable.current = new Tabulator(myRef.current, {
  40. index: "key",
  41. height: 380,
  42. data: detail, //link data to table
  43. reactiveData: false, //enable data reactivity
  44. dataTreeStartExpanded:true,
  45. dataTree: true,
  46. selectableRows:1, //make rows selectable
  47. editTriggerEvent:"dblclick", //trigger edit on double click
  48. dataTreeStartExpanded:function(row, level){
  49. //console.log(row);
  50. //console.log(level);
  51. return true; //expand rows where the "driver" data field is true;
  52. },
  53. columns: [ //Define Table Columns
  54. {title:"序号", field:"序号", width:40, headerSort:false, frozen: true}, //never hide this column
  55. {title:"清单编码", field:"清单编码", width:120,headerSort:false, frozen: true, formatter:"textarea" },
  56. {title:"名称", field:"名称", width:150, headerSort:false, formatter:"textarea"}, //hide this column first
  57. {title:"计算基数", field:"计算基数", width:150 , headerSort:false, formatter:"money"},
  58. {title:"计算基础", field:"计算基础", width:250, headerSort:false, formatter:"textarea"},
  59. {title:"费率", field:"费率", width:60 , headerSort:false, formatter:"money", editor:"input", editable:editCheck},
  60. {title:"金额", field:"金额", width:150, headerSort:false, formatter:"money"},
  61. {title:"项目类别", field:"项目类别", width:80 , headerSort:false, formatter:"textarea"},
  62. ]
  63. });
  64. myTable.current.on("cellDblClick", function(e, cell){
  65. //e - the click event object
  66. //cell - cell component
  67. console.log(cell);
  68. });
  69. myTable.current.on("cellEdited", function(cell){
  70. //cell - cell component
  71. console.log(cell);
  72. let newData = copy(cell._cell.row.data);
  73. newData['金额'] = Number(newData['计算基数']) * Number(newData['费率']) / Number(100);
  74. myTable.current.updateData([newData]);
  75. zjcsCallback(name, bh, newData);
  76. });
  77. Service.generateZjcs(name, bh).then(x=>{
  78. let addedkey = x.map(y=>{
  79. y['key'] = uuidv4();
  80. if (y.hasOwnProperty('_children')) {
  81. y['_children'] = y['_children'].map(z=>{
  82. z['key'] = uuidv4();
  83. return z;
  84. });
  85. }
  86. return y;
  87. });
  88. myTable.current.replaceData(addedkey);
  89. });
  90. }, [bh]
  91. );
  92. React.useEffect(
  93. () => {
  94. cankaoTable.current = new Tabulator(cankaoRef.current, {
  95. index: "key",
  96. height: 200,
  97. data: cankao, //link data to table
  98. reactiveData: false, //enable data reactivity
  99. dataTree: false,
  100. selectableRows:1, //make rows selectable
  101. columns: [ //Define Table Columns
  102. {title:"工程类型", field:"工程类型", width:200, headerSort:false, headerFilter:"input", formatter:"textarea"}, //never hide this column
  103. {title:"名称", field:"名称", width:150, headerSort:false, formatter:"textarea"}, //hide this column first
  104. {title:"计算基础", field:"计算基础", width:250, headerSort:false, formatter:"textarea"},
  105. {title:"参考费率", field:"参考费率", width:100 , headerSort:false, formatter:"money"},
  106. {title:"地区", field:"地区", width:50, headerSort:false, formatter:"textarea"},
  107. {title:"备注", field:"备注", width:280 , headerSort:false, formatter:"textarea"},
  108. ]
  109. });
  110. Service.cankao().then(x=>{
  111. allRef.current = x;
  112. filterData(value);
  113. });
  114. }, []
  115. );
  116. const filterData = (value) => {
  117. if (value == 10) {
  118. let newData = allRef.current.filter(y=>y['名称'].includes('安全文明施工措施费'));
  119. cankaoTable.current.replaceData(newData);
  120. } else if (value == 20) {
  121. let newData = allRef.current.filter(y=>y['名称'].includes('扬尘污染防治增加费'));
  122. cankaoTable.current.replaceData(newData);
  123. } else if (value == 30) {
  124. let newData = allRef.current.filter(y=>y['名称'].includes('按质论价'));
  125. cankaoTable.current.replaceData(newData);
  126. } else if (value == 40) {
  127. let newData = allRef.current.filter(y=>y['名称'].includes('非夜间施工照明'));
  128. cankaoTable.current.replaceData(newData);
  129. } else if (value == 50) {
  130. let newData = allRef.current.filter(y=>y['名称'].includes('冬雨季施工'));
  131. cankaoTable.current.replaceData(newData);
  132. } else if (value == 60) {
  133. let newData = allRef.current.filter(y=>y['名称'].includes('已完工程及设备保护'));
  134. cankaoTable.current.replaceData(newData);
  135. } else if (value == 70) {
  136. let newData = allRef.current.filter(y=>y['名称'].includes('临时设施'));
  137. cankaoTable.current.replaceData(newData);
  138. } else if (value == 80) {
  139. let newData = allRef.current.filter(y=>y['名称'].includes('赶工措施'));
  140. cankaoTable.current.replaceData(newData);
  141. } else if (value == 90) {
  142. let newData = allRef.current.filter(y=>y['名称'].includes('住宅分户验收'));
  143. cankaoTable.current.replaceData(newData);
  144. } else if (value == 100) {
  145. let newData = allRef.current.filter(y=>y['名称'].includes('夜间施工'));
  146. cankaoTable.current.replaceData(newData);
  147. } else if (value == 110) {
  148. let newData = allRef.current.filter(y=>y['名称'].includes('建筑工人实名制费用'));
  149. cankaoTable.current.replaceData(newData);
  150. } else if (value == 120) {
  151. let newData = allRef.current.filter(y=>y['名称'].includes('苏安码管理增加费'));
  152. cankaoTable.current.replaceData(newData);
  153. } else if (value == 130) {
  154. let newData = allRef.current.filter(y=>y['名称'].includes('特殊施工降效'));
  155. cankaoTable.current.replaceData(newData);
  156. } else if (value == 140) {
  157. let newData = allRef.current.filter(y=>y['名称'].includes('交通组织维护'));
  158. cankaoTable.current.replaceData(newData);
  159. } else if (value == 150) {
  160. let newData = allRef.current.filter(y=>y['名称'].includes('协管费'));
  161. cankaoTable.current.replaceData(newData);
  162. } else if (value == 160) {
  163. let newData = allRef.current.filter(y=>y['名称'].includes('垂直运输'));
  164. cankaoTable.current.replaceData(newData);
  165. } else if (value == 170) {
  166. let newData = allRef.current.filter(y=>y['名称'].includes('二次搬运'));
  167. cankaoTable.current.replaceData(newData);
  168. } else if (value == 180) {
  169. let newData = allRef.current.filter(y=>y['名称'].includes('智慧工地费用'));
  170. cankaoTable.current.replaceData(newData);
  171. } else if (value == 190) {
  172. let newData = allRef.current.filter(y=>y['名称'].includes('外脚手架钢板网使用增加费'));
  173. cankaoTable.current.replaceData(newData);
  174. }
  175. };
  176. const handleChange = (event) => {
  177. setValue(event.target.value);
  178. filterData(event.target.value);
  179. };
  180. var editCheck = function(cell){
  181. //cell - the cell component for the editable cell
  182. //get row data
  183. let row = cell._cell.row;
  184. while(row.modules.dataTree.parent) {
  185. row = row.modules.dataTree.parent;
  186. }
  187. if (row.data['名称'] == '现场安全文明施工') return false;
  188. return true; // only allow the name cell to be edited if the age is over 18
  189. }
  190. return (
  191. <Stack spacing={1}>
  192. <div ref={myRef}>
  193. </div>
  194. <Box >
  195. <TabContext value={valueTab}>
  196. <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
  197. <TabList sx={{minHeight: '24px'}} aria-label="lab API tabs example">
  198. <Tab sx={{p: 0, minHeight: '24px'}} label="参考费率" value="1" />
  199. </TabList>
  200. </Box>
  201. <TabPanel sx={{p: 1}} value="1">
  202. <Stack direction="row" spacing={1}>
  203. <FormControl sx={{width: 200}}>
  204. <InputLabel id="demo-simple-select-label">措施分类</InputLabel>
  205. <Select
  206. labelId="demo-simple-select-label"
  207. id="demo-simple-select"
  208. value={value}
  209. label="措施分类"
  210. onChange={handleChange}
  211. >
  212. <MenuItem value={10}>安全文明施工措施费</MenuItem>
  213. <MenuItem value={20}>扬尘污染防治增加费</MenuItem>
  214. <MenuItem value={30}>按质论价</MenuItem>
  215. <MenuItem value={40}>非夜间施工照明</MenuItem>
  216. <MenuItem value={50}>冬雨季施工</MenuItem>
  217. <MenuItem value={60}>已完工程及设备保护</MenuItem>
  218. <MenuItem value={70}>临时设施</MenuItem>
  219. <MenuItem value={80}>赶工措施</MenuItem>
  220. <MenuItem value={90}>住宅分户验收</MenuItem>
  221. <MenuItem value={100}>夜间施工</MenuItem>
  222. <MenuItem value={110}>建筑工人实名制费用</MenuItem>
  223. <MenuItem value={120}>苏安码管理增加费</MenuItem>
  224. <MenuItem value={130}>特殊施工降效</MenuItem>
  225. <MenuItem value={140}>交通组织维护</MenuItem>
  226. <MenuItem value={150}>协管费</MenuItem>
  227. <MenuItem value={160}>垂直运输</MenuItem>
  228. <MenuItem value={170}>二次搬运</MenuItem>
  229. <MenuItem value={180}>智慧工地费用</MenuItem>
  230. <MenuItem value={190}>外脚手架钢板网使用增加费</MenuItem>
  231. </Select>
  232. </FormControl>
  233. <div ref={cankaoRef}>
  234. </div>
  235. </Stack>
  236. </TabPanel>
  237. </TabContext>
  238. </Box>
  239. </Stack>
  240. );
  241. }