project_controller.js 14 KB

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