project_controller.js 12 KB

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