editor.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {danxiangdinge_index} from './utils';
  2. function copy(input) {
  3. return JSON.parse(JSON.stringify(input));
  4. }
  5. export const shanchu = (hotRef, selectedRow, detailRef) => {
  6. let deleted = hotRef.current?.hotInstance?.getData()[selectedRow.current][2];
  7. //hotRef.current?.hotInstance?.alter('remove_row', selectedRow.current, 1);
  8. let qdbm = null;
  9. for (let i = selectedRow.current - 1; i > -1; i= i - 1) {
  10. let above = hotRef.current?.hotInstance?.getData()[i];
  11. if (above[1] != null) {
  12. qdbm = above[2];
  13. break;
  14. }
  15. }
  16. let newData = detailRef.current.map(x=>{
  17. if (x["清单编码"] == qdbm) {
  18. let y = copy(x);
  19. let origin = y["__children"];
  20. let trans = origin.filter(z=>z["清单编码"]!=deleted);
  21. y["__children"] = trans;
  22. return y;
  23. } else {
  24. return x;
  25. }
  26. });
  27. detailRef.current = newData;
  28. return newData;
  29. };
  30. export const push_op = (memory, mem_pointer, detailRef) => {
  31. if(memory.current.length == mem_pointer.current + 1) {
  32. memory.current.push(copy(detailRef.current));
  33. mem_pointer.current = mem_pointer.current + 1;
  34. } else{
  35. memory.current.splice(mem_pointer.current + 1);
  36. memory.current.push(copy(detailRef.current));
  37. mem_pointer.current = mem_pointer.current + 1;
  38. }
  39. console.log("after op the memory is");
  40. console.log(memory.current);
  41. console.log(mem_pointer.current);
  42. };
  43. export const quanbushanchu = (hotRef, selectedRow, detailRef) => {
  44. let qdbm = hotRef.current?.hotInstance?.getData()[selectedRow.current][2];
  45. let newData = detailRef.current.map(x=>{
  46. if (x["清单编码"] == qdbm) {
  47. let y = copy(x);
  48. y["__children"] = [];
  49. return y;
  50. } else {
  51. return x;
  52. }
  53. });
  54. detailRef.current = newData;
  55. return newData;
  56. };
  57. export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
  58. let bh = danxiangdinge_index(detailRef.current);
  59. let selected = hotRef.current?.hotInstance?.getData()[selectedRow.current];
  60. if (selected && selected[1] != null) {
  61. let danwei = selected[6];
  62. let newData = detailRef.current.map(
  63. x => {
  64. if (x['序号'] == selected[1]) {
  65. let y = copy(x);
  66. if (y.hasOwnProperty("__children")) {
  67. y["__children"].push(
  68. {
  69. '操作': '',
  70. '序号': null,
  71. '清单编码': bh,
  72. '名称': '',
  73. '项目特征': null,
  74. '计算规则': null,
  75. '单位': danwei,
  76. '数量': '1',
  77. '综合单价': '',
  78. '合价': '',
  79. '人工费': '0',
  80. '主材费': '0',
  81. '设备费': '0',
  82. '辅材费': '',
  83. '材料费': '',
  84. '机械费': '0',
  85. '管理费': '0',
  86. '利润': '0',
  87. '暂估价': null,
  88. '综合人工工日': null,
  89. '备注': null,
  90. }
  91. );
  92. } else {
  93. y["__children"] = [{
  94. '操作': '',
  95. '序号': null,
  96. '清单编码': bh,
  97. '名称': '',
  98. '项目特征': null,
  99. '计算规则': null,
  100. '单位': danwei,
  101. '数量': '1',
  102. '综合单价': '',
  103. '合价': '',
  104. '人工费': '0',
  105. '主材费': '0',
  106. '设备费': '0',
  107. '辅材费': '',
  108. '材料费': '',
  109. '机械费': '0',
  110. '管理费': '0',
  111. '利润': '0',
  112. '暂估价': null,
  113. '综合人工工日': null,
  114. '备注': null,
  115. }];
  116. }
  117. return y;
  118. } else {
  119. return x;
  120. }
  121. }
  122. );
  123. detailRef.current = newData;
  124. return [true, newData];
  125. } else {
  126. return [false, detailRef.current];
  127. }
  128. };