project_controller.js 11 KB

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