project_controller.js 11 KB

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