project_controller.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. syncDisplayNewRationGljNode:function (sc,newNode) {
  17. TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
  18. sc.sheet.addRows(newNode.serialNo(), 1);
  19. TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
  20. sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  21. });
  22. },
  23. addBills: function (project, sheetController, std) {
  24. if (!project || !sheetController) { return null; }
  25. let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
  26. let newSource = null, newNode = null, parentID, nextSiblingID;
  27. if (target) {
  28. console.log(target.depth());
  29. parentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
  30. nextSiblingID = target.depth() === 0 ? project.Bills.tree.setting.rootId : target.source.getNextSiblingID();
  31. if (std) {
  32. let newCode = project.Bills.newFormatCode(std.code);
  33. newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
  34. } else {
  35. newSource = project.Bills.insertBills(parentID, nextSiblingID);
  36. }
  37. if (target.depth() === 0) {
  38. newNode = project.mainTree.insert(target.getID(), project.mainTree.rootID())
  39. } else {
  40. newNode = project.mainTree.insert(target.getParentID(), target.getNextSiblingID());
  41. }
  42. } else {
  43. alert('不可添加清单');
  44. }
  45. if (newNode) {
  46. newNode.source = newSource;
  47. newNode.sourceType = project.Bills.getSourceType();
  48. newNode.data = newSource.data;
  49. this.syncDisplayNewNode(sheetController, newNode);
  50. }
  51. },
  52. addRootBill:function (project, sheetController) {//添加大项费用
  53. if (!project || !sheetController) { return null; }
  54. this.addSpecialBill(project, sheetController,null, null,true,billType.DXFY);
  55. },
  56. addFB:function(project, sheetController) {//添加分部
  57. if (!project || !sheetController) { return null; }
  58. let selected = project.mainTree.selected;
  59. if(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//选中的是分部分项,则插入做为最后一个子项
  60. this.addSpecialBill(project, sheetController,selected, null,true,billType.FB);
  61. }
  62. if(selected.parent){
  63. this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FB);
  64. }
  65. },
  66. addFX:function(project, sheetController) {//添加分项
  67. if (!project || !sheetController) { return null; }
  68. let selected = project.mainTree.selected;
  69. if(selected.data.type==billType.FB||(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING)){//选中的是分部或者是分部分项工程,则插入做为最后一个子项
  70. this.addSpecialBill(project, sheetController,selected, null,true,billType.FX);
  71. }
  72. if(selected.parent){
  73. if(selected.data.type==billType.FX){
  74. this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FX);
  75. }
  76. }
  77. },
  78. addSpecialBill(project,sheetController,parent,nextSibling,isUserAdd,type){
  79. let newSource = null, newNode = null;
  80. let b_nexID = nextSibling==null?-1:nextSibling.source.getID();//主树和清单树,对应的树节点ID不一样
  81. let m_nexID = nextSibling==null?-1:nextSibling.getID();
  82. let b_parent = parent==null?-1:parent.source.getID();
  83. let m_parent = parent==null?-1:parent.getID();
  84. newSource = project.Bills.insertSpecialBill(b_parent, b_nexID,isUserAdd,type);
  85. newNode = project.mainTree.insert(m_parent,m_nexID);
  86. if (newNode) {
  87. newNode.source = newSource;
  88. newNode.sourceType = project.Bills.getSourceType();
  89. newNode.data = newSource.data;
  90. this.syncDisplayNewNode(sheetController, newNode);
  91. }
  92. },
  93. addRation: function (project, sheetController, rationType, std) {
  94. if (!project || !sheetController) { return; }
  95. let selected = project.mainTree.selected, newSource = null, newNode = null;
  96. if (selected === null) { return; }
  97. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  98. if (selected.source.children.length > 0) {
  99. alert('当前清单已有清单子项,不能套用定额。');
  100. } else if (false) {
  101. alert('当前清单已有公式计算,不能套用定额。');
  102. } else {
  103. if (std) {
  104. newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
  105. project.ration_glj.addRationGLJ(newSource,std);
  106. } else {
  107. newSource = project.Ration.insertRation(selected.source.getID(),null, rationType);
  108. }
  109. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  110. }
  111. } else if (selected.sourceType === project.Ration.getSourceType()) {
  112. if (std) {
  113. newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
  114. project.ration_glj.addRationGLJ(newSource,std);
  115. } else {
  116. newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source, rationType);
  117. }
  118. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  119. };
  120. if (newNode) {
  121. newNode.source = newSource;
  122. newNode.sourceType = project.Ration.getSourceType();
  123. newNode.data = newSource;
  124. this.syncDisplayNewNode(sheetController, newNode);
  125. }
  126. },
  127. replaceRation: function (project, sheetController, std) {
  128. if (!project || !sheetController) { return; }
  129. let selected = project.mainTree.selected, newSource = null, newNode = null;
  130. if (selected === null) { return; }
  131. if (selected.sourceType === project.Ration.getSourceType()) {
  132. project.Ration.replaceRation(selected.source, std);
  133. project.ration_glj.addRationGLJ(selected.source, std);
  134. sheetController.refreshTreeNode([selected], false);
  135. } else {
  136. alert('当前焦点行不是定额,无法替换。');
  137. }
  138. }
  139. /* addVolumePrice: function (project, sheetController) {
  140. if (!project || !sheetController) { return null; }
  141. var selected = project.mainTree.selected;
  142. var newSource = null, newNode = null;
  143. if(selected === null) {
  144. return;
  145. }
  146. if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
  147. newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
  148. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  149. } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
  150. newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
  151. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  152. }
  153. if (newNode) {
  154. newNode.source = newSource;
  155. newNode.sourceType = project.VolumePrice.getSourceType();
  156. newNode.data = newSource;
  157. this.syncDisplayNewNode(sheetController, newNode);
  158. }
  159. },*/
  160. /* calculateAll: function (project, sheetController, CalcType) {
  161. this.project.setCalcFlag(CalcType);
  162. let calc = new BillsCalcHelper(project);
  163. calc.calcAll();
  164. sheetController.showTreeData();
  165. project.Bills.updateAll();
  166. calc = null;
  167. }*/
  168. }