project_controller.js 12 KB

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