project_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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,callback) {//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. if(callback) callback();
  45. });
  46. },
  47. syncDisplayNewRationGljNode:function (sc,newNode) {
  48. TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
  49. sc.sheet.addRows(newNode.serialNo(), 1);
  50. TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
  51. // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  52. cbTools.refreshFormulaNodes();
  53. });
  54. },
  55. /* addBillsByData: async function (postData, insertFunc) {
  56. await ajaxPost('/bills/insertBills', { postData });
  57. // 插入
  58. const insertData = postData.filter(item => item.updateType === 'create');
  59. const treeData = insertData.map(item => item.updateData);
  60. // 插入清单节点
  61. if (!insertFunc) {
  62. insertFunc = projectObj.project.Bills.tree.insertByDatas;
  63. }
  64. projectObj.project.Bills.tree.insertByDatas(treeData);
  65. projectObj.project.Bills.datas = projectObj.project.Bills.datas.concat(treeData);
  66. // 插入主树节点
  67. const newNodes = projectObj.project.mainTree.insertByDatas(treeData);
  68. for (const node of newNodes) {
  69. node.source = projectObj.project.Bills.tree.nodes[projectObj.project.Bills.tree.prefix + node.getID()];
  70. node.data = node.source.data;
  71. node.sourceType = projectObj.project.Bills.getSourceType();
  72. }
  73. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes, true);
  74. return newNodes;
  75. }, */
  76. addBillsByData: async function (postData, isSameDepth = false) {
  77. await ajaxPost('/bills/insertBills', { postData });
  78. // 插入
  79. const insertData = postData.filter(item => item.updateType === 'create');
  80. const treeData = insertData.map(item => item.updateData);
  81. // 插入清单节点和主树节点
  82. projectObj.project.Bills.datas = projectObj.project.Bills.datas.concat(treeData);
  83. let newNodes;
  84. if (isSameDepth) {
  85. const pre = postData.find(item => item.updateType === 'update');
  86. const preID = pre && pre.updateData.ID || null;
  87. projectObj.project.Bills.tree.multiInsert(treeData, preID);
  88. newNodes = projectObj.project.mainTree.multiInsert(treeData, preID);
  89. } else {
  90. projectObj.project.Bills.tree.insertByDatas(treeData);
  91. newNodes = projectObj.project.mainTree.insertByDatas(treeData);
  92. }
  93. for (const node of newNodes) {
  94. node.source = projectObj.project.Bills.tree.nodes[projectObj.project.Bills.tree.prefix + node.getID()];
  95. node.data = node.source.data;
  96. node.sourceType = projectObj.project.Bills.getSourceType();
  97. }
  98. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes, true);
  99. return newNodes;
  100. },
  101. getBillsPostData: function (number) {
  102. const project = projectObj.project;
  103. const target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
  104. const baseParentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
  105. const baseNextID = target.depth() === 0 ? -1 : target.source.getNextSiblingID();
  106. const updateNode = target.depth() === 0 ? target.source.children[target.source.children.length - 1] : target;
  107. const insertData = [];
  108. for (let i = 0; i < number; i++) {
  109. const data = {
  110. type: billType.BILL,
  111. projectID: project.ID(),
  112. ID: uuid.v1(),
  113. ParentID: baseParentID,
  114. };
  115. const pre = insertData[i - 1];
  116. if (pre) {
  117. pre.NextSiblingID = data.ID;
  118. }
  119. if (i === number - 1) {
  120. data.NextSiblingID = baseNextID;
  121. }
  122. insertData.push(data);
  123. }
  124. const postData = insertData.map(item => ({
  125. updateType: 'create',
  126. updateData: item
  127. }));
  128. if (updateNode) {
  129. postData.push({ updateType: 'update', updateData: { ID: updateNode.getID(), NextSiblingID: insertData[0].ID } });
  130. }
  131. return postData;
  132. },
  133. addBills: function (project, sheetController, std) {
  134. if (!project || !sheetController) { return null; }
  135. let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
  136. let newSource = null, newNode = null, parentID, nextSiblingID, nodeParentID, nodeNextSiblingID;
  137. if (target) {
  138. if(target.depth() === 0){
  139. parentID = target.source.getID();
  140. nextSiblingID = project.Bills.tree.setting.rootId;
  141. nodeParentID = target.getID();
  142. nodeNextSiblingID = project.mainTree.rootID();
  143. } else{
  144. parentID = target.source.getParentID();
  145. nextSiblingID = target.source.getNextSiblingID();
  146. nodeParentID = target.getParentID();
  147. nodeNextSiblingID = target.getNextSiblingID();
  148. }
  149. parentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
  150. nextSiblingID = target.depth() === 0 ? project.Bills.tree.setting.rootId : target.source.getNextSiblingID();
  151. if (std) {
  152. let fixedNode = getRootFixedNode(target);
  153. if(!isFlag(fixedNode.data) || (fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.SUB_ENGINERRING && fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.MEASURE)){
  154. return false;
  155. }
  156. //焦点行属于分部分项
  157. if(fixedNode.data.flagsIndex.fixed.flag === fixedFlag.SUB_ENGINERRING){
  158. std.type = billType.FX;
  159. //焦点行是分部分项
  160. let subType = getSubType(target);
  161. if(target.sourceType === project.Bills.getSourceType() && target.data.type === billType.DXFY && subType === billType.FB){
  162. return false;
  163. } else if(target.sourceType === project.Bills.getSourceType() && target.data.type === billType.FB){//焦点行是分部
  164. if(!subType || subType === billType.FX){
  165. parentID = target.source.getID();
  166. nextSiblingID = project.Bills.tree.setting.rootId;
  167. nodeParentID = target.getID();
  168. nodeNextSiblingID = project.mainTree.rootID();
  169. } else{
  170. return false;
  171. }
  172. }
  173. } else {
  174. std.type = billType.BILL;
  175. }
  176. let newCode = project.Bills.newFormatCode(std.code);
  177. newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
  178. } else {
  179. newSource = project.Bills.insertBills(parentID, nextSiblingID);
  180. }
  181. newNode = project.mainTree.insert(nodeParentID, nodeNextSiblingID, newSource.data.ID);
  182. } else {
  183. alert('不可添加清单');
  184. }
  185. if (newNode) {
  186. newNode.source = newSource;
  187. newNode.sourceType = project.Bills.getSourceType();
  188. newNode.data = newSource.data;
  189. this.syncDisplayNewNode(sheetController, newNode);
  190. return newNode;
  191. }
  192. function getSubType(node){
  193. for(let sub of node.children){
  194. if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FB){
  195. return billType.FB;
  196. }
  197. else if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FX){
  198. return billType.FX;
  199. }
  200. }
  201. return null;
  202. }
  203. },
  204. addRootBill:function (project, sheetController) {//添加大项费用
  205. if (!project || !sheetController) { return null; }
  206. this.addSpecialBill(project, sheetController,null, project.mainTree.selected.nextSibling,true,billType.DXFY);
  207. },
  208. addFB:function(project, sheetController) {//添加分部
  209. if (!project || !sheetController) { return null; }
  210. let selected = project.mainTree.selected;
  211. if(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//选中的是分部分项,则插入做为最后一个子项
  212. return this.addSpecialBill(project, sheetController,selected, null,true,billType.FB);
  213. }
  214. if(selected.parent){
  215. return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FB);
  216. }
  217. },
  218. addFX:function(project, sheetController) {//添加分项
  219. if (!project || !sheetController) { return null; }
  220. let selected = project.mainTree.selected;
  221. console.log(selected);
  222. if(selected.data.type==billType.FB||(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING)){//选中的是分部或者是分部分项工程,则插入做为最后一个子项
  223. return this.addSpecialBill(project, sheetController,selected, null,true,billType.FX);
  224. }
  225. if(selected.parent){
  226. if(selected.data.type==billType.FX||selected.data.type==billType.BX){
  227. return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FX);
  228. }
  229. }
  230. },
  231. addSpecialBill(project,sheetController,parent,nextSibling,isUserAdd,type){
  232. let newNode = null;
  233. let b_nexID = nextSibling==null?-1:nextSibling.source.getID();//主树和清单树,对应的树节点ID不一样
  234. let m_nexID = nextSibling==null?-1:nextSibling.getID();
  235. let b_parent = parent==null?-1:parent.source.getID();
  236. let m_parent = parent==null?-1:parent.getID();
  237. let newSource = project.Bills.insertSpecialBill(b_parent, b_nexID,isUserAdd,type);
  238. newNode = project.mainTree.insert(m_parent,m_nexID, newSource.data.ID);
  239. if (newNode) {
  240. newNode.source = newSource;
  241. newNode.sourceType = project.Bills.getSourceType();
  242. newNode.data = newSource.data;
  243. this.syncDisplayNewNode(sheetController, newNode);
  244. return newNode;
  245. }
  246. },
  247. addRation: function (project, sheetController, rationType, std) {
  248. if (!project || !sheetController) { return; }
  249. let selected = project.mainTree.selected, newSource = null, newNode = null;
  250. if (selected === null) { return; }
  251. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  252. if (selected.source.children.length > 0) {
  253. alert('当前清单已有清单子项,不能套用定额。');
  254. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  255. alert('当前有基数计算,不能插入定额/量价/人材机。');
  256. } else {
  257. if(selected.data.type === billType.FB){
  258. return;
  259. }
  260. if (std) {
  261. newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
  262. project.ration_glj.addRationGLJ(newSource,std);
  263. } else {
  264. newSource = project.Ration.insertRation(selected.source.getID(),null, rationType);
  265. }
  266. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID(), newSource.ID);
  267. }
  268. } else if (selected.sourceType === project.Ration.getSourceType()) {
  269. if (std) {
  270. newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
  271. project.ration_glj.addRationGLJ(newSource,std);
  272. } else {
  273. newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source, rationType);
  274. }
  275. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID(), newSource.ID);
  276. };
  277. if (newNode) {
  278. newNode.source = newSource;
  279. newNode.sourceType = project.Ration.getSourceType();
  280. newNode.data = newSource;
  281. this.syncDisplayNewNode(sheetController, newNode);
  282. }
  283. },
  284. replaceRation: function (project, sheetController, std) {
  285. if (!project || !sheetController) { return; }
  286. let selected = project.mainTree.selected, newSource = null, newNode = null;
  287. if (selected === null) { return; }
  288. if ( selected.sourceType === project.Ration.getSourceType()) {
  289. project.Ration.replaceRation(selected.source, std);
  290. project.ration_glj.addRationGLJ(selected.source, std);
  291. sheetController.refreshTreeNode([selected], false);
  292. } else {
  293. alert('当前焦点行不是定额,无法替换。');
  294. }
  295. },
  296. addNewNodes:function (updateData){
  297. let controller = projectObj.mainController;
  298. let Bill = projectObj.project.Bills;
  299. let newAddNode = [];
  300. let newRationNodes = [];
  301. for(let nb of updateData.bills.add){
  302. let newSource = Bill.tree.insertByData(nb, nb.ParentID, -1, true);//按顺序插入的情况下,nextID为-1,树节点
  303. let newNode = projectObj.project.mainTree.insert(nb.ParentID, -1, newSource.data.ID);
  304. newNode.source = newSource;
  305. newNode.sourceType = Bill.getSourceType();
  306. newNode.data = newSource.data;
  307. controller.sheet.addRows(newNode.serialNo(), 1);
  308. // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  309. newAddNode.push(newNode);
  310. Bill.datas.push(nb);
  311. }
  312. for(let nr of updateData.ration.add){
  313. let newNode = projectObj.project.mainTree.insert(nr.billsItemID, -1, nr.ID);
  314. newNode.source = nr;
  315. newNode.sourceType = projectObj.project.Ration.getSourceType();
  316. newNode.data = nr;
  317. controller.sheet.addRows(newNode.serialNo(), 1);
  318. // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  319. newAddNode.push(newNode);
  320. newRationNodes.push(newNode);
  321. projectObj.project.Ration.datas.push(nr);
  322. }
  323. TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
  324. return newRationNodes;
  325. }
  326. /* addVolumePrice: function (project, sheetController) {
  327. if (!project || !sheetController) { return null; }
  328. var selected = project.mainTree.selected;
  329. var newSource = null, newNode = null;
  330. if(selected === null) {
  331. return;
  332. }
  333. if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
  334. newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
  335. newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
  336. } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
  337. newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
  338. newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
  339. }
  340. if (newNode) {
  341. newNode.source = newSource;
  342. newNode.sourceType = project.VolumePrice.getSourceType();
  343. newNode.data = newSource;
  344. this.syncDisplayNewNode(sheetController, newNode);
  345. }
  346. },*/
  347. /* calculateAll: function (project, sheetController, CalcType) {
  348. this.project.setCalcFlag(CalcType);
  349. let calc = new BillsCalcHelper(project);
  350. calc.calcAll();
  351. sheetController.showTreeData();
  352. project.Bills.updateAll();
  353. calc = null;
  354. }*/
  355. }