Zjcs2.js 12 KB

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