project_controller.js 12 KB

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