project_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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,withOutSelect=false) {//withOutSelect 不需要自动选中,外面自已处理
  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. let lastNode = null;
  32. for(let newNode of newNodes){
  33. sc.sheet.addRows(newNode.serialNo(), 1);
  34. TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
  35. lastNode = newNode
  36. // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  37. }
  38. if(withOutSelect==false&& lastNode){
  39. sc.setTreeSelected(lastNode);
  40. sc.sheet.setSelection(lastNode.serialNo(), sels[0].col, 1, 1);
  41. }
  42. cbTools.refreshFormulaNodes();
  43. });
  44. },
  45. syncDisplayNewRationGljNode:function (sc,newNode) {
  46. TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
  47. sc.sheet.addRows(newNode.serialNo(), 1);
  48. TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
  49. // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  50. cbTools.refreshFormulaNodes();
  51. });
  52. },
  53. addBills: function (project, sheetController, std) {
  54. if (!project || !sheetController) { return null; }
  55. let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
  56. let newSource = null, newNode = null, parentID, nextSiblingID, nodeParentID, nodeNextSiblingID;
  57. if (target) {
  58. if(target.depth() === 0){
  59. parentID = target.source.getID();
  60. nextSiblingID = project.Bills.tree.setting.rootId;
  61. nodeParentID = target.getID();
  62. nodeNextSiblingID = project.mainTree.rootID();
  63. } else{
  64. parentID = target.source.getParentID();
  65. nextSiblingID = target.source.getNextSiblingID();
  66. nodeParentID = target.getParentID();
  67. nodeNextSiblingID = target.getNextSiblingID();
  68. }
  69. parentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
  70. nextSiblingID = target.depth() === 0 ? project.Bills.tree.setting.rootId : target.source.getNextSiblingID();
  71. if (std) {
  72. let fixedNode = getRootFixedNode(target);
  73. if(!isFlag(fixedNode.data) || (fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.SUB_ENGINERRING && fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.MEASURE)){
  74. return false;
  75. }
  76. //焦点行属于分部分项
  77. if(fixedNode.data.flagsIndex.fixed.flag === fixedFlag.SUB_ENGINERRING){
  78. std.type = billType.FX;
  79. //焦点行是分部分项
  80. let subType = getSubType(target);
  81. if(target.sourceType === project.Bills.getSourceType() && target.data.type === billType.DXFY && subType === billType.FB){
  82. return false;
  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. } else{
  90. return false;
  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. return newNode;
  111. }
  112. function getSubType(node){
  113. for(let sub of node.children){
  114. if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FB){
  115. return billType.FB;
  116. }
  117. else if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FX){
  118. return billType.FX;
  119. }
  120. }
  121. return null;
  122. }
  123. },
  124. addRootBill:function (project, sheetController) {//添加大项费用
  125. if (!project || !sheetController) { return null; }
  126. this.addSpecialBill(project, sheetController,null, project.mainTree.selected.nextSibling,true,billType.DXFY);
  127. },
  128. addFB:function(project, sheetController) {//添加分部
  129. if (!project || !sheetController) { return null; }
  130. let selected = project.mainTree.selected;
  131. if(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//选中的是分部分项,则插入做为最后一个子项
  132. return this.addSpecialBill(project, sheetController,selected, null,true,billType.FB);
  133. }
  134. if(selected.parent){
  135. return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FB);
  136. }
  137. },
  138. addFX:function(project, sheetController) {//添加分项
  139. if (!project || !sheetController) { return null; }
  140. let selected = project.mainTree.selected;
  141. console.log(selected);
  142. if(selected.data.type==billType.FB||(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING)){//选中的是分部或者是分部分项工程,则插入做为最后一个子项
  143. return 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. return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FX);
  148. }
  149. }
  150. },
  151. addSpecialBill(project,sheetController,parent,nextSibling,isUserAdd,type){
  152. let 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. let 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. return newNode;
  165. }
  166. },
  167. addRation: function (project, sheetController, rationType, std) {
  168. if (!project || !sheetController) { return; }
  169. let selected = project.mainTree.selected, newSource = null, newNode = null;
  170. if (selected === null) { return; }
  171. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  172. if (selected.source.children.length > 0) {
  173. alert('当前清单已有清单子项,不能套用定额。');
  174. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  175. alert('当前有基数计算,不能插入定额/量价/人材机。');
  176. } else {
  177. if(selected.data.type === billType.FB){
  178. return;
  179. }
  180. if (std) {
  181. newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
  182. project.ration_glj.addRationGLJ(newSource,std);
  183. } else {
  184. newSource = project.Ration.insertRation(selected.source.getID(),null, rationType);
  185. }
  186. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID(), newSource.ID);
  187. }
  188. } else if (selected.sourceType === project.Ration.getSourceType()) {
  189. if (std) {
  190. newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
  191. project.ration_glj.addRationGLJ(newSource,std);
  192. } else {
  193. newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source, rationType);
  194. }
  195. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID(), newSource.ID);
  196. };
  197. if (newNode) {
  198. newNode.source = newSource;
  199. newNode.sourceType = project.Ration.getSourceType();
  200. newNode.data = newSource;
  201. this.syncDisplayNewNode(sheetController, newNode);
  202. }
  203. },
  204. replaceRation: function (project, sheetController, std) {
  205. if (!project || !sheetController) { return; }
  206. let selected = project.mainTree.selected, newSource = null, newNode = null;
  207. if (selected === null) { return; }
  208. if ( selected.sourceType === project.Ration.getSourceType()) {
  209. project.Ration.replaceRation(selected.source, std);
  210. project.ration_glj.addRationGLJ(selected.source, std);
  211. sheetController.refreshTreeNode([selected], false);
  212. } else {
  213. alert('当前焦点行不是定额,无法替换。');
  214. }
  215. },
  216. addNewNodes:function (updateData){
  217. let controller = projectObj.mainController;
  218. let Bill = projectObj.project.Bills;
  219. let newAddNode = [];
  220. let newRationNodes = [];
  221. for(let nb of updateData.bills.add){
  222. let newSource = Bill.tree.insertByData(nb, nb.ParentID, -1, true);//按顺序插入的情况下,nextID为-1,树节点
  223. let newNode = projectObj.project.mainTree.insert(nb.ParentID, -1, newSource.data.ID);
  224. newNode.source = newSource;
  225. newNode.sourceType = Bill.getSourceType();
  226. newNode.data = newSource.data;
  227. controller.sheet.addRows(newNode.serialNo(), 1);
  228. // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  229. newAddNode.push(newNode);
  230. Bill.datas.push(nb);
  231. }
  232. for(let nr of updateData.ration.add){
  233. let newNode = projectObj.project.mainTree.insert(nr.billsItemID, -1, nr.ID);
  234. newNode.source = nr;
  235. newNode.sourceType = projectObj.project.Ration.getSourceType();
  236. newNode.data = nr;
  237. controller.sheet.addRows(newNode.serialNo(), 1);
  238. // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  239. newAddNode.push(newNode);
  240. newRationNodes.push(newNode);
  241. projectObj.project.Ration.datas.push(nr);
  242. }
  243. TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
  244. return newRationNodes;
  245. }
  246. /* addVolumePrice: function (project, sheetController) {
  247. if (!project || !sheetController) { return null; }
  248. var selected = project.mainTree.selected;
  249. var newSource = null, newNode = null;
  250. if(selected === null) {
  251. return;
  252. }
  253. if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
  254. newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
  255. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  256. } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
  257. newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
  258. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  259. }
  260. if (newNode) {
  261. newNode.source = newSource;
  262. newNode.sourceType = project.VolumePrice.getSourceType();
  263. newNode.data = newSource;
  264. this.syncDisplayNewNode(sheetController, newNode);
  265. }
  266. },*/
  267. /* calculateAll: function (project, sheetController, CalcType) {
  268. this.project.setCalcFlag(CalcType);
  269. let calc = new BillsCalcHelper(project);
  270. calc.calcAll();
  271. sheetController.showTreeData();
  272. project.Bills.updateAll();
  273. calc = null;
  274. }*/
  275. }