project_controller.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Created by Mai on 2017/6/1.
  3. */
  4. ProjectController = {
  5. /* sc: tree_sheet_controller */
  6. syncDisplayNewNode: function (sc, newNode) {
  7. TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
  8. var sels = sc.sheet.getSelections();
  9. sc.sheet.addRows(newNode.serialNo(), 1);
  10. TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
  11. sc.setTreeSelected(newNode);
  12. sc.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
  13. sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  14. });
  15. },
  16. addBills: function (project, sheetController, std) {
  17. if (!project || !sheetController) { return null; }
  18. let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
  19. let newSource = null, newNode = null;
  20. let parentID = target ? target.source.getParentID() : project.Bills.tree.setting.rootId;
  21. let nextSiblingID = target ? target.source.getNextSiblingID() : project.Bills.tree.setting.rootId;
  22. if (std) {
  23. let newCode = project.Bills.newFormatCode(std.code);
  24. newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
  25. } else {
  26. newSource = project.Bills.insertBills(parentID, nextSiblingID);
  27. }
  28. newNode = project.mainTree.insert(target.getParentID(), target.getNextSiblingID());
  29. if (newNode) {
  30. newNode.source = newSource;
  31. newNode.sourceType = project.Bills.getSourceType();
  32. newNode.data = newSource.data;
  33. this.syncDisplayNewNode(sheetController, newNode);
  34. }
  35. },
  36. addRation: function (project, sheetController, std) {
  37. if (!project || !sheetController) { return; }
  38. let selected = project.mainTree.selected, newSource = null, newNode = null;
  39. if (selected === null) { return; }
  40. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  41. if (selected.source.children.length > 0) {
  42. alert('当前清单已有清单子项,不能套用定额。');
  43. } else if (false) {
  44. alert('当前清单已有公式计算,不能套用定额。');
  45. } else {
  46. let firstChild = selected.firstChild();
  47. if (firstChild && firstChild.sourceType === project.VolumePrice.getSourceType()) {
  48. alert('当前位置已有量价,不能套用定额。');
  49. } else {
  50. if (std) {
  51. newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
  52. project.ration_glj.addRationGLJ(newSource,std);
  53. } else {
  54. newSource = project.Ration.insertRation(selected.source.getID());
  55. }
  56. }
  57. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  58. }
  59. } else if (selected.sourceType === project.Ration.getSourceType()) {
  60. if (std) {
  61. newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
  62. project.ration_glj.addRationGLJ(newSource,std);
  63. } else {
  64. newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source);
  65. }
  66. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  67. } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
  68. alert('当前位置已有量价,不能套用定额。');
  69. }
  70. if (newNode) {
  71. newNode.source = newSource;
  72. newNode.sourceType = project.Ration.getSourceType();
  73. newNode.data = newSource;
  74. this.syncDisplayNewNode(sheetController, newNode);
  75. }
  76. },
  77. replaceRation: function (project, sheetController, std) {
  78. if (!project || !sheetController) { return; }
  79. let selected = project.mainTree.selected, newSource = null, newNode = null;
  80. if (selected === null) { return; }
  81. if (selected.sourceType === project.Ration.getSourceType()) {
  82. project.Ration.replaceRation(selected.source, std);
  83. project.ration_glj.addRationGLJ(selected.source, std);
  84. sheetController.refreshTreeNode([selected], false);
  85. } else {
  86. alert('当前焦点行不是定额,无法替换。');
  87. }
  88. },
  89. addVolumePrice: function (project, sheetController) {
  90. if (!project || !sheetController) { return null; }
  91. var selected = project.mainTree.selected;
  92. var newSource = null, newNode = null;
  93. if(selected === null) {
  94. return;
  95. }
  96. if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
  97. newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
  98. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  99. } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
  100. newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
  101. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  102. }
  103. if (newNode) {
  104. newNode.source = newSource;
  105. newNode.sourceType = project.VolumePrice.getSourceType();
  106. newNode.data = newSource;
  107. this.syncDisplayNewNode(sheetController, newNode);
  108. }
  109. },
  110. calculateAll: function (project, sheetController, CalcType) {
  111. this.project.setCalcFlag(CalcType);
  112. let calc = new BillsCalcHelper(project);
  113. calc.calcAll();
  114. sheetController.showTreeData();
  115. project.Bills.updateAll();
  116. calc = null;
  117. }
  118. }