project_controller.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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, parentID, nextSiblingID;
  20. if (target) {
  21. console.log(target.depth());
  22. parentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
  23. nextSiblingID = target.depth() === 0 ? project.Bills.tree.setting.rootId : target.source.getNextSiblingID();
  24. if (std) {
  25. let newCode = project.Bills.newFormatCode(std.code);
  26. newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
  27. } else {
  28. newSource = project.Bills.insertBills(parentID, nextSiblingID);
  29. }
  30. if (target.depth() === 0) {
  31. newNode = project.mainTree.insert(target.getID(), project.mainTree.rootID())
  32. } else {
  33. newNode = project.mainTree.insert(target.getParentID(), target.getNextSiblingID());
  34. }
  35. } else {
  36. alert('不可添加清单');
  37. }
  38. if (newNode) {
  39. newNode.source = newSource;
  40. newNode.sourceType = project.Bills.getSourceType();
  41. newNode.data = newSource.data;
  42. this.syncDisplayNewNode(sheetController, newNode);
  43. }
  44. },
  45. addRation: function (project, sheetController, rationType, std) {
  46. if (!project || !sheetController) { return; }
  47. let selected = project.mainTree.selected, newSource = null, newNode = null;
  48. if (selected === null) { return; }
  49. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  50. if (selected.source.children.length > 0) {
  51. alert('当前清单已有清单子项,不能套用定额。');
  52. } else if (false) {
  53. alert('当前清单已有公式计算,不能套用定额。');
  54. } else {
  55. if (std) {
  56. newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
  57. project.ration_glj.addRationGLJ(newSource,std);
  58. } else {
  59. newSource = project.Ration.insertRation(selected.source.getID(),null, rationType);
  60. }
  61. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  62. }
  63. }
  64. else if (selected.sourceType === project.Ration.getSourceType()) {
  65. if (std) {
  66. newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
  67. project.ration_glj.addRationGLJ(newSource,std);
  68. } else {
  69. newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source, rationType);
  70. }
  71. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  72. };
  73. if (newNode) {
  74. newNode.source = newSource;
  75. newNode.sourceType = project.Ration.getSourceType();
  76. newNode.data = newSource;
  77. this.syncDisplayNewNode(sheetController, newNode);
  78. }
  79. },
  80. replaceRation: function (project, sheetController, std) {
  81. if (!project || !sheetController) { return; }
  82. let selected = project.mainTree.selected, newSource = null, newNode = null;
  83. if (selected === null) { return; }
  84. if (selected.sourceType === project.Ration.getSourceType()) {
  85. project.Ration.replaceRation(selected.source, std);
  86. project.ration_glj.addRationGLJ(selected.source, std);
  87. sheetController.refreshTreeNode([selected], false);
  88. } else {
  89. alert('当前焦点行不是定额,无法替换。');
  90. }
  91. }
  92. /* addVolumePrice: function (project, sheetController) {
  93. if (!project || !sheetController) { return null; }
  94. var selected = project.mainTree.selected;
  95. var newSource = null, newNode = null;
  96. if(selected === null) {
  97. return;
  98. }
  99. if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
  100. newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
  101. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  102. } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
  103. newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
  104. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  105. }
  106. if (newNode) {
  107. newNode.source = newSource;
  108. newNode.sourceType = project.VolumePrice.getSourceType();
  109. newNode.data = newSource;
  110. this.syncDisplayNewNode(sheetController, newNode);
  111. }
  112. },*/
  113. /* calculateAll: function (project, sheetController, CalcType) {
  114. this.project.setCalcFlag(CalcType);
  115. let calc = new BillsCalcHelper(project);
  116. calc.calcAll();
  117. sheetController.showTreeData();
  118. project.Bills.updateAll();
  119. calc = null;
  120. }*/
  121. }