Qingdan2.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. import * as React from 'react';
  2. import Box from "@mui/material/Box";
  3. import 'handsontable/dist/handsontable.full.min.css';
  4. //import 'handsontable/styles/ht-theme-main.min.css';
  5. import { HandsonTable } from 'handsontable/base';
  6. import { Table, ConfigProvider, Button as AButton } from "antd";
  7. import {HotTable} from "@handsontable/react-wrapper";
  8. import { registerAllModules } from 'handsontable/registry';
  9. import {RichTreeView } from "@mui/x-tree-view/RichTreeView";
  10. import { Grid } from '@mui/material';
  11. import Tab from "@mui/material/Tab";
  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 { registerPlugin, NestedRows } from 'handsontable/plugins';
  17. //registerPlugin(NestedRows);
  18. import Service from './Service';
  19. import { textRenderer, registerRenderer } from 'handsontable/renderers';
  20. import Button from '@mui/material/Button';
  21. import ButtonGroup from '@mui/material/ButtonGroup';
  22. import {extractFuzhu} from './utils';
  23. import {shanchu, undo, redo, danxiangdinge, updateDercj, changguidinge, handleBeizhu, huan, updateShuliang} from './editor';
  24. import Backdrop from '@mui/material/Backdrop';
  25. import CircularProgress from '@mui/material/CircularProgress';
  26. import { DataGrid } from '@mui/x-data-grid';
  27. import { useHotEditor } from "@handsontable/react-wrapper";
  28. import Dialog from '@mui/material/Dialog';
  29. import DialogTitle from '@mui/material/DialogTitle';
  30. import DialogContent from '@mui/material/DialogContent';
  31. import IconButton from '@mui/material/IconButton';
  32. import Typography from '@mui/material/Typography';
  33. import Editable from './Editable';
  34. import {
  35. SettingFilled,
  36. } from '@ant-design/icons';
  37. import zhCN from 'antd/locale/zh_CN';
  38. import {TabulatorFull as Tabulator} from "tabulator-tables"; //import Tabulator library
  39. import "tabulator-tables/dist/css/tabulator.min.css"; //import Tabulator stylesheet
  40. import './Tabulator.css';
  41. registerAllModules();
  42. /**
  43. *
  44. 本条规定了工程量清单编码的表示方式:十二位阿拉伯数字及其设置规定。
  45. 各位数字的含义是:一、二位为专业工程代码(01—房屋建筑与装饰工程;02—仿古建筑工程;
  46. 03—通用安装工程;04—市政工程;05—园林绿化工程;06—矿山工程;07—构筑物工程;08—城市
  47. 轨道交通工程;09—爆破工程。以后进入国标的专业工程代码以此类推);三、四位为附录分类顺序码;
  48. 五、六位为分部工程顺序码;七、八、九位为分项工程项目名称顺序码;十至十二位为清单项目名称
  49. 顺序码。
  50. */
  51. export default function Qingdan2({name, bh, bt, rgde, jxde, clde, beizhu/*后台传回来的附注信息,要整理后才能成为展示用的行*/ , beizhuFK, clickCallback, loadingCallback, dingeclick, tihuanCallback, tihuanClick, suanshiCallback}) {
  52. registerRenderer('customStylesRenderer', (hotInstance, TD, row, column, prop, value, ...rest) => {
  53. let newValue = value;
  54. if (( column == 11 || column == 5) && row > 0) {
  55. newValue = Number(value).toFixed(2).toString();
  56. }
  57. if (column == 10 && row > 0) {
  58. newValue = Number(value).toFixed(4).toString();
  59. }
  60. textRenderer(hotInstance, TD, row, column, prop, newValue, ...rest);
  61. for (let i = 0; i < highlight.current.length; i++) {
  62. let entry = highlight.current[i];
  63. if (entry.row == row && entry.col == column) {
  64. TD.style.fontWeight = 'bold';
  65. TD.style.color = 'green';
  66. TD.style.background = '#d7f1e1';
  67. }
  68. }
  69. });
  70. const myTable = React.useRef(null);
  71. const myRef = React.useRef(null);
  72. const [valueTab, setValueTab] = React.useState("1");
  73. const handleChange = (event, newValue) => {
  74. setValueTab(newValue);
  75. };
  76. const [rcjhl, setRcjhl] = React.useState([]);
  77. const [rcjhl2, setRcjhl2] = React.useState([]);
  78. const [fuzhu, setFuzhu] = React.useState([]);//展示用的附注行
  79. const [tuijian, setTuijian] = React.useState([]);
  80. const [fuzhuEnable, setFuzhuEnable] = React.useState(false);
  81. const hotRcjRef = React.useRef(null);
  82. const hotTuijianRef = React.useRef(null);
  83. const highlight = React.useRef([]);
  84. const debmRef = React.useRef(null);
  85. const lastClickRef = React.useRef(null);
  86. const [detail, setDetail] = React.useState([
  87. ]);
  88. const selectedRowKeysTable = React.useRef([]);
  89. const selectedRowKeysTableParent = React.useRef(null);
  90. const beizhuFKRef = React.useRef(null);
  91. const rgdeRef = React.useRef(null);
  92. const jxdeRef = React.useRef(null);
  93. const cldeRef = React.useRef(null);
  94. const isQdrcj = React.useRef(false);
  95. const [selectedRowKeys, setSelectedRowKeys] = React.useState([]);
  96. const onSelectChange = (newSelectedRowKeys) => {
  97. console.log('selectedRowKeys changed: ', newSelectedRowKeys);
  98. setSelectedRowKeys(newSelectedRowKeys);
  99. const [newData, newHl] = handleBeizhu(beizhuFKRef.current, selectedRowKeysTable.current[0], newSelectedRowKeys, fuzhu);
  100. if (newData) {
  101. myTable.current.updateData(newData.filter(x=>x['key'] == selectedRowKeysTableParent.current));
  102. setRcjhl(newHl);
  103. }
  104. };
  105. /**fuzhu select */
  106. const rowSelection = {
  107. selectedRowKeys,
  108. onChange: onSelectChange,
  109. getCheckboxProps: (record) => {
  110. return {
  111. disabled: !fuzhuEnable
  112. };
  113. }
  114. };
  115. var editCheck = function(cell){
  116. //cell - the cell component for the editable cell
  117. //get row data
  118. //console.log(cell);
  119. if(cell._cell.row.data['序号']) return false;
  120. return true;
  121. }
  122. function handleSelect(row){
  123. selectedRowKeysTable.current = [row._row['data']['key']];
  124. if (row._row.data['序号'] != null && row._row.data['序号'].length >0) {
  125. selectedRowKeysTableParent.current = row._row['data']['key'];
  126. setFuzhu([]);
  127. Service.generateQingdanrcj(name, bh,bt,row._row.data['清单编码']).then(x=>{
  128. setRcjhl(x);
  129. //hotRcjRef.current?.hotInstance?.loadData(x);
  130. isQdrcj.current = true;
  131. highlight.current = [];
  132. });
  133. Service.generateQingdanTuijian(name, bh,bt,row._row.data['清单编码']).then(x=>{
  134. setTuijian(x);
  135. });
  136. }else{
  137. setTuijian([]);
  138. let row_parent = row._row;
  139. while(row_parent.modules.dataTree.parent) {
  140. row_parent = row_parent.modules.dataTree.parent;
  141. }
  142. //console.log(name, bh,bt,qdbm, selected[1]);
  143. debmRef.current = row._row['data']['清单编码'];
  144. selectedRowKeysTableParent.current = row_parent['data']['key'];
  145. let qdbm = row_parent['data']['清单编码'];
  146. let debm = row._row['data']['清单编码'];
  147. console.log('debm=');
  148. console.log(debm);
  149. let danwei = row._row['data']['单位'];
  150. clickCallback(qdbm, debm);
  151. Service.generateDingercj(name, bh,bt,qdbm, debm, danwei).then(x=>{
  152. console.log(x);
  153. setRcjhl(x[0]);
  154. setFuzhuEnable(x[1]);
  155. //hotRcjRef.current?.hotInstance?.loadData(x);
  156. isQdrcj.current = false;
  157. let toHighlight = [];
  158. for(let i = 1; i < x[0].length; i++) {
  159. let entry = x[0][i];
  160. let bianhao = entry[1];
  161. let rcjlb = entry[8];
  162. let hit = false;
  163. if (Number(rcjlb) == 1 && rgdeRef.current ) {
  164. for (let j = 0;j < rgdeRef.current.length; j++) {
  165. if (rgdeRef.current[j]["CLBH"] == bianhao) {
  166. if(rgdeRef.current[j]["CLMC"] == entry[2])hit = true;
  167. let danjia = Number(entry[5]);
  168. if (danjia != rgdeRef.current[j]["YSJG"]) {
  169. //console.log(`[${i},5]danjia bu yizhi`);
  170. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  171. }
  172. let hanliang = Number(entry[10]);
  173. if (hanliang != rgdeRef.current[j]["gr"]) {
  174. //console.log(`[${i}, 10]hanliang bu yizhi`);
  175. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  176. }
  177. }
  178. }
  179. }
  180. if (Number(rcjlb) == 3 && jxdeRef.current ) {
  181. for (let j = 0; j < jxdeRef.current.length; j++) {
  182. if (jxdeRef.current[j]["jxbh"] == bianhao) {
  183. if(jxdeRef.current[j]["jxmc"] == entry[2])hit = true;
  184. let danjia = Number(entry[5]);
  185. if (danjia != jxdeRef.current[j]["tbdj"]) {
  186. //console.log(`[${i},5]danjia bu yizhi`);
  187. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  188. }
  189. let hanliang = Number(entry[10]);
  190. if (hanliang != jxdeRef.current[j]["sl"]) {
  191. //console.log(`[${i}, 10]hanliang bu yizhi`);
  192. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  193. }
  194. }
  195. }
  196. }
  197. if (Number(rcjlb) == 2 && cldeRef.current ) {
  198. for (let j = 0; j < cldeRef.current.length; j++) {
  199. if (cldeRef.current[j]["CLBH"] == bianhao) {
  200. if(cldeRef.current[j]["CLMC"] == entry[2])hit = true;
  201. let danjia = Number(entry[5]);
  202. if (danjia != cldeRef.current[j]["YSJG"]) {
  203. //console.log(`[${i},5]danjia bu yizhi`);
  204. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  205. }
  206. let hanliang = Number(entry[10]);
  207. if (hanliang != cldeRef.current[j]["SL"]) {
  208. //console.log(`[${i}, 10]hanliang bu yizhi`);
  209. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  210. }
  211. }
  212. }
  213. }
  214. if (!hit) {
  215. toHighlight.push({row: i, col: 1, renderer: "customStylesRenderer"});
  216. }
  217. }
  218. highlight.current = toHighlight;
  219. });
  220. }
  221. }
  222. const afterChange = (changes, source) => {
  223. if (changes == null || changes.every(x=>x[2] == x[3])) {
  224. } else {
  225. let data = hotRcjRef.current?.hotInstance?.getData();
  226. for(let i = 1; i < data.length; i++) {
  227. data[i][11] = Number(data[i][10]) * Number(data[i][5]);
  228. }
  229. setRcjhl(data);
  230. let newData = updateDercj(selectedRowKeysTable.current[0], data);
  231. myTable.current.updateData(newData.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function() {
  232. let getRow = myTable.current.getRows(); //get array of currently selected row components.
  233. let component = null;
  234. for(let i = 0; i < getRow.length; i++) {
  235. let entry = getRow[i]._row.modules.dataTree.children;
  236. for(let j = 0; j < entry.length; j++) {
  237. let child = entry[j];
  238. if(child.data['key'] == selectedRowKeysTable.current[0]) {
  239. //console.log(child);
  240. component = child.component;
  241. break;
  242. }
  243. }
  244. }
  245. handleSelect(component);
  246. //handleSelect(getRow[0]);
  247. });
  248. }
  249. };
  250. const afterOnCellMouseDown = (event, coord, TD) => {
  251. if (lastClickRef.current == null) {
  252. lastClickRef.current = Date.now();
  253. } else {
  254. let origin = lastClickRef.current;
  255. lastClickRef.current = Date.now();
  256. let delta = lastClickRef.current - origin;
  257. if (delta < 300 && coord.col == 1 && coord.row > 0 && !isQdrcj.current){//300 ms -> 换
  258. tihuanCallback(coord.row, coord.col);
  259. }
  260. }
  261. };
  262. React.useEffect(() => {
  263. myTable.current = new Tabulator(myRef.current, {
  264. index: "key",
  265. height: 380,
  266. data: detail, //link data to table
  267. reactiveData: false, //enable data reactivity
  268. dataTreeStartExpanded:true,
  269. dataTree: true,
  270. selectableRows:1, //make rows selectable
  271. editTriggerEvent:"dblclick", //trigger edit on double click
  272. dataTreeStartExpanded:function(row, level){
  273. //console.log(row);
  274. //console.log(level);
  275. return true; //expand rows where the "driver" data field is true;
  276. },
  277. columns: [ //Define Table Columns
  278. {title:"序号", field:"序号", width:80, headerSort:false, frozen: true}, //never hide this column
  279. {title:"清单编码", field:"清单编码", width:120,headerSort:false, frozen: true ,formatter:"textarea" },
  280. {title:"名称", field:"名称", width:150, headerSort:false, formatter:"textarea"}, //hide this column first
  281. {title:"项目特征", field:"项目特征", width:150 , headerSort:false, formatter:"textarea"},
  282. {title:"计算规则", field:"计算规则", width:150, headerSort:false, formatter:"textarea"},
  283. {title:"单位", field:"单位", width:100, headerSort:false},
  284. {title:"数量", field:"数量", width:100, headerSort:false, editor: "input", editable: editCheck },
  285. {title:"综合单价", field:"综合单价", width:100, headerSort:false, formatter:"money"},
  286. {title:"合价", field:"合价", width:100, headerSort:false, formatter:"money"},
  287. {title:"人工费", field:"人工费", width:100, headerSort:false, formatter:"money"},
  288. {title:"主材费", field:"主材费", width:100, headerSort:false, formatter:"money"},
  289. {title:"设备费", field:"设备费", width:100, headerSort:false, formatter:"money"},
  290. {title:"辅材费", field:"辅材费", width:100, headerSort:false, formatter:"money"},
  291. {title:"材料费", field:"材料费", width:100, headerSort:false, formatter:"money"},
  292. {title:"机械费", field:"机械费", width:100, headerSort:false, formatter:"money"},
  293. {title:"管理费", field:"管理费", width:100, headerSort:false, formatter:"money"},
  294. {title:"利润", field:"利润", width:100, headerSort:false, formatter:"money"},
  295. {title:"暂估价", field:"暂估价", width:100, headerSort:false, formatter:"money"},
  296. {title:"综合人工工日", field:"综合人工工日", width:100, headerSort:false},
  297. ]
  298. });
  299. myTable.current.on("cellDblClick", function(e, cell){
  300. //e - the click event object
  301. //cell - cell component
  302. console.log(cell);
  303. });
  304. myTable.current.on("rowSelected", handleSelect);
  305. myTable.current.on("cellEdited", function(cell){
  306. //console.log("edited");
  307. //console.log();
  308. let key = cell._cell.row.data['key'];
  309. myTable.current.deselectRow();
  310. let [success, data] = updateShuliang(cell._cell.row.data['数量'], selectedRowKeysTable.current[0]);
  311. if (success) {
  312. myTable.current.updateData(data.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function() {
  313. let getRow = myTable.current.getRows(); //get array of currently selected row components.
  314. let component = null;
  315. for(let i = 0; i < getRow.length; i++) {
  316. let entry = getRow[i]._row.modules.dataTree.children;
  317. for(let j = 0; j < entry.length; j++) {
  318. let child = entry[j];
  319. if(child.data['key'] == key) {
  320. //console.log(child);
  321. component = child.component;
  322. break;
  323. }
  324. }
  325. }
  326. component.select();
  327. handleSelect(component);
  328. //handleSelect(getRow[0]);
  329. });
  330. }
  331. });
  332. myTable.current.on("tableBuilt", () => {
  333. Service.generateQingdanmingxi(name, bh, bt).then(x=>{
  334. myTable.current.replaceData(x);
  335. });
  336. });
  337. }, [bh, bt]);
  338. React.useEffect(
  339. () => {
  340. //console.log("rgde changed");
  341. //console.log(rgde);
  342. rgdeRef.current = rgde;
  343. jxdeRef.current = jxde;
  344. cldeRef.current = clde;
  345. if (isQdrcj.current) {
  346. highlight.current = [];
  347. } else {
  348. let toHighlight = [];
  349. for(let i = 1; i < rcjhl.length; i++) {
  350. let entry = rcjhl[i];
  351. let bianhao = entry[1];
  352. let rcjlb = entry[8];
  353. let hit = false;
  354. if (Number(rcjlb) == Number(1) && rgde) {
  355. for (let j = 0; j < rgde.length; j++) {
  356. if (rgde[j]["CLBH"] == bianhao) {
  357. if(rgde[j]["CLMC"] == entry[2])hit = true;
  358. let danjia = Number(entry[5]);
  359. if (danjia != rgde[j]["YSJG"]) {
  360. //console.log(`[${i},5]danjia bu yizhi`);
  361. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  362. }
  363. let hanliang = Number(entry[10]);
  364. if (hanliang != rgde[j]["gr"]) {
  365. //console.log(`[${i}, 10]hanliang bu yizhi`);
  366. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  367. }
  368. }
  369. }
  370. }
  371. if (Number(rcjlb) == Number(3) && jxde ) {
  372. for (let j = 0; j < jxde.length; j++) {
  373. if (jxde[j]["jxbh"] == bianhao) {
  374. if(jxde[j]["jxmc"] == entry[2])hit = true;
  375. let danjia = Number(entry[5]);
  376. if (danjia != jxde[j]["tbdj"]) {
  377. //console.log(`[${i},5]danjia bu yizhi`);
  378. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  379. }
  380. let hanliang = Number(entry[10]);
  381. if (hanliang != jxde[j]["sl"]) {
  382. //console.log(`[${i}, 10]hanliang bu yizhi`);
  383. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  384. }
  385. }
  386. }
  387. }
  388. if (Number(rcjlb) == Number(2) && clde ) {
  389. for (let j = 0; j < clde.length; j++) {
  390. if (clde[j]["CLBH"] == bianhao) {
  391. if(clde[j]["CLMC"] == entry[2])hit = true;
  392. let danjia = Number(entry[5]);
  393. if (danjia != clde[j]["YSJG"]) {
  394. //console.log(`[${i},5]danjia bu yizhi`);
  395. toHighlight.push({row: i, col: 5, renderer: "customStylesRenderer"});
  396. }
  397. let hanliang = Number(entry[10]);
  398. if (hanliang != clde[j]["SL"]) {
  399. //console.log(`[${i}, 10]hanliang bu yizhi`);
  400. toHighlight.push({row: i, col: 10, renderer: "customStylesRenderer"});
  401. }
  402. }
  403. }
  404. }
  405. if (!hit) {
  406. toHighlight.push({row: i, col: 1, renderer: "customStylesRenderer"});
  407. }
  408. }
  409. //console.log(toHighlight);
  410. highlight.current = toHighlight;
  411. }
  412. let bzrcjhl = [["人材机编码", "名称", "单位", "单价", "合价", "含量"]]
  413. if (rgde)
  414. for (let i = 0; i < rgde.length; i++) {
  415. bzrcjhl.push([rgde[i]["CLBH"], rgde[i]["CLMC"], rgde[i]["JLDW"], rgde[i]["YSJG"], rgde[i]["gf"], rgde[i]["gr"]]);
  416. }
  417. if (clde)
  418. for (let i = 0; i < clde.length; i++) {
  419. bzrcjhl.push([clde[i]["CLBH"], clde[i]["CLMC"], clde[i]["JLDW"], clde[i]["YSJG"], clde[i]["HJ"], clde[i]["SL"]]);
  420. }
  421. if (jxde)
  422. for (let i = 0; i < jxde.length; i++) {
  423. bzrcjhl.push([jxde[i]["jxbh"], jxde[i]["jxmc"], jxde[i]["DW"], jxde[i]["tbdj"], jxde[i]["hj"], jxde[i]["sl"]]);
  424. }
  425. setRcjhl2(bzrcjhl);
  426. }, [rgde, jxde, clde]
  427. );
  428. React.useEffect(
  429. () => {
  430. console.log(beizhu);
  431. let result = [];
  432. if (beizhu != null) {
  433. let keys = Object.keys(beizhu["BZBH"]);
  434. for(let i = 0; i < keys.length; i++) {
  435. let key = keys[i];
  436. result.push({'key': i+1, '序号': i+1, '编号': beizhu["BZBH"][key], '说明': beizhu["SM"][key]});//序号很重要
  437. }
  438. setFuzhu(result);
  439. let newSelect = extractFuzhu(debmRef.current);
  440. setSelectedRowKeys(newSelect);
  441. //setSelectedRowKeys([1]);
  442. }
  443. }, [beizhu]
  444. );
  445. React.useEffect(
  446. () => {
  447. beizhuFKRef.current = beizhuFK;
  448. }, [beizhuFK]
  449. );
  450. React.useEffect(
  451. () => {
  452. myTable.current.deselectRow();
  453. //console.log(dingeclick);
  454. if (selectedRowKeysTable.current.length > 0 ) {
  455. const [success, data, key] = changguidinge(JSON.parse(dingeclick), selectedRowKeysTable.current[0]);
  456. if (success) {
  457. myTable.current.updateData(data.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function(){
  458. let getRow = myTable.current.getRows(); //get array of currently selected row components.
  459. let component = null;
  460. for(let i = 0; i < getRow.length; i++) {
  461. let entry = getRow[i]._row.modules.dataTree.children;
  462. for(let j = 0; j < entry.length; j++) {
  463. let child = entry[j];
  464. if(child.data['key'] == key) {
  465. //console.log(child);
  466. component = child.component;
  467. break;
  468. }
  469. }
  470. }
  471. component.select();
  472. handleSelect(component);
  473. });
  474. }
  475. }
  476. }, [dingeclick]//常规添加定额
  477. );
  478. React.useEffect(
  479. () => {
  480. //console.log(dingeclick);
  481. if (selectedRowKeysTable.current.length > 0 ) {
  482. const data = huan(JSON.parse(tihuanClick), selectedRowKeysTable.current[0]);
  483. myTable.current.updateData(data.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function(){
  484. let getRow = myTable.current.getRows(); //get array of currently selected row components.
  485. let component = null;
  486. for(let i = 0; i < getRow.length; i++) {
  487. let entry = getRow[i]._row.modules.dataTree.children;
  488. for(let j = 0; j < entry.length; j++) {
  489. let child = entry[j];
  490. if(child.data['key'] == selectedRowKeysTable.current[0]) {
  491. //console.log(child);
  492. component = child.component;
  493. break;
  494. }
  495. }
  496. }
  497. handleSelect(component);
  498. });
  499. }
  500. }, [tihuanClick]//替换定额人材机
  501. );
  502. return (
  503. <Stack spacing={2}>
  504. <Box>
  505. <Stack direction='row' spacing={2}>
  506. <Button variant="outlined" size="small" onClick={() => {
  507. if (selectedRowKeysTable.current.length > 0) {
  508. let getRow = myTable.current.getRows(); //get array of currently selected row components.
  509. let hit = false;
  510. for(let i = 0; i < getRow.length; i++) {
  511. if (getRow[i]._row.data['key'] == selectedRowKeysTable.current[0]) {
  512. hit = true;
  513. }
  514. }
  515. if (hit) {
  516. suanshiCallback();
  517. }
  518. }
  519. }}
  520. >定额(算式)</Button>
  521. <Button variant="outlined" size="small" onClick={() => {
  522. if (selectedRowKeysTable.current.length > 0) {
  523. const [success, data] = danxiangdinge(selectedRowKeysTable.current[0]);
  524. if(success) {
  525. myTable.current.updateData(data.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function(){
  526. selectedRowKeysTable.current = [];
  527. selectedRowKeysTableParent.current = null;
  528. setRcjhl([]);
  529. setFuzhu([]);
  530. isQdrcj.current = true;
  531. highlight.current = [];
  532. });
  533. }
  534. }
  535. }}
  536. >单项定额</Button>
  537. <Button variant="outlined" size="small" onClick={() => {
  538. if (selectedRowKeysTable.current.length > 0) {
  539. let newData = shanchu(selectedRowKeysTable.current[0]);
  540. myTable.current.updateData(newData.filter(x=>x['key'] == selectedRowKeysTableParent.current)).then(function(){
  541. if (newData.filter(x=>x['key'] == selectedRowKeysTable.current[0]).length == 0) {
  542. selectedRowKeysTable.current = [];
  543. selectedRowKeysTableParent.current = [];
  544. setRcjhl([]);
  545. setFuzhu([]);
  546. isQdrcj.current = true;
  547. highlight.current = [];
  548. }
  549. });
  550. }
  551. }}
  552. >删除</Button>
  553. <Button variant="outlined" size="small" onClick={() => {
  554. let newData = undo();
  555. myTable.current.updateData(newData).then(function(){
  556. selectedRowKeysTable.current = [];
  557. selectedRowKeysTableParent.current = null;
  558. setRcjhl([]);
  559. setFuzhu([]);
  560. isQdrcj.current = true;
  561. highlight.current = [];
  562. });
  563. }}
  564. >撤销</Button>
  565. <Button variant="outlined" size="small" onClick={() => {
  566. let newData = redo();
  567. myTable.current.updateData(newData).then(function(){
  568. selectedRowKeysTable.current = [];
  569. selectedRowKeysTableParent.current = null;
  570. setRcjhl([]);
  571. setFuzhu([]);
  572. isQdrcj.current = true;
  573. highlight.current = [];
  574. });
  575. }}
  576. >重做</Button>
  577. <Button variant="outlined" size="small" onClick={() => {
  578. console.log("save to cloud");
  579. loadingCallback();
  580. }}
  581. >保存</Button>
  582. </Stack>
  583. <div ref={myRef}>
  584. </div>
  585. </Box>
  586. <Box >
  587. <TabContext value={valueTab}>
  588. <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
  589. <TabList sx={{minHeight: '24px'}} onChange={handleChange} aria-label="lab API tabs example">
  590. <Tab sx={{p: 0, minHeight: '24px'}} label="人材机含量" value="1" />
  591. <Tab sx={{p: 0, minHeight: '24px'}} label="标准定额人材机含量" value="2" />
  592. <Tab sx={{p: 0, minHeight: '24px'}} label="定额附注" value="3" />
  593. <Tab sx={{p: 0, minHeight: '24px'}} label="组价推荐" value="4" />
  594. </TabList>
  595. </Box>
  596. <TabPanel sx={{p: 1}} value="1">
  597. <HotTable
  598. nestedRows={false}
  599. data={rcjhl
  600. }
  601. //cell={highlight}
  602. manualColumnResize={true}
  603. rowHeaders={true}
  604. colHeaders={true}
  605. height="190"
  606. cells={(row, col) => {
  607. if (isQdrcj.current) return {readOnly: true, renderer: "customStylesRenderer"};
  608. if (col == 8) {
  609. return { readOnly: true, renderer: "customStylesRenderer" };
  610. }
  611. if (row === 0) {
  612. return { readOnly: true, renderer: "customStylesRenderer" };
  613. }
  614. if (col <= 1 || col === 11) {
  615. return { readOnly: true, renderer: "customStylesRenderer" };
  616. }
  617. return {renderer: "customStylesRenderer" };
  618. }}
  619. fixedRowsTop={1}
  620. selectionMode="single"
  621. autoWrapRow={false}
  622. autoWrapCol={false}
  623. ref = {hotRcjRef}
  624. afterChange={afterChange}
  625. afterOnCellMouseDown={afterOnCellMouseDown}
  626. licenseKey="non-commercial-and-evaluation" // for non-commercial use only
  627. >
  628. </HotTable>
  629. </TabPanel>
  630. <TabPanel sx={{p: 1}} value="2">
  631. <HotTable
  632. nestedRows={false}
  633. data={rcjhl2
  634. }
  635. manualColumnResize={true}
  636. rowHeaders={true}
  637. colHeaders={true}
  638. height="190"
  639. readOnly={true}
  640. fixedRowsTop={1}
  641. selectionMode="single"
  642. autoWrapRow={false}
  643. autoWrapCol={false}
  644. licenseKey="non-commercial-and-evaluation" // for non-commercial use only
  645. />
  646. </TabPanel>
  647. <TabPanel sx={{p: 1}} value="3">
  648. <Box sx={{maxHeight: `190px`}}>
  649. <ConfigProvider
  650. locale={zhCN}
  651. theme={{
  652. components: {
  653. Table: {
  654. /* here is your component tokens */
  655. cellPaddingBlock : 8
  656. },
  657. },
  658. }}
  659. >
  660. <Table
  661. scroll={{ x: 'max-content' , y : 190}}
  662. pagination={false}
  663. rowSelection={rowSelection}
  664. columns={
  665. [
  666. { title: '序号', dataIndex: '序号', width : 80},
  667. {
  668. title: '编号',
  669. dataIndex: '编号',
  670. },
  671. {
  672. title: '说明',
  673. dataIndex: '说明',
  674. width: 550
  675. },
  676. ]
  677. }
  678. dataSource={fuzhu} />
  679. </ConfigProvider>
  680. </Box>
  681. </TabPanel>
  682. <TabPanel sx={{p: 1}} value="4">
  683. <HotTable
  684. nestedRows={false}
  685. data={tuijian
  686. }
  687. ref = {hotTuijianRef}
  688. manualColumnResize={true}
  689. rowHeaders={true}
  690. colHeaders={true}
  691. height="190"
  692. readOnly={true}
  693. fixedRowsTop={1}
  694. selectionMode="single"
  695. autoWrapRow={false}
  696. autoWrapCol={false}
  697. licenseKey="non-commercial-and-evaluation" // for non-commercial use only
  698. />
  699. </TabPanel>
  700. </TabContext>
  701. </Box>
  702. </Stack>
  703. );
  704. }