block_controller.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /**
  2. * Created by zhang on 2018/5/10.
  3. */
  4. let BlockController = {
  5. datas:[],
  6. copyBtnDisable:function (selected) {
  7. if(this.isDXFYorMainEq(selected)){
  8. return true;
  9. }
  10. if(selected.sourceType == ModuleNames.ration && selected.data.type == rationType.install){
  11. return true;
  12. }
  13. return false;
  14. },
  15. pasteBtnDisable:function (selected) {
  16. let blockData = this.getBlockData();
  17. let Bills = projectObj.project.Bills;
  18. if(this.isDXFYorMainEq(selected)){
  19. return true;
  20. }
  21. if(blockData == null){
  22. return true;
  23. }
  24. if(blockData.firstNodeType != blockType.RATION && blockData.isFBFX != Bills.isFBFX(selected)){//除了复制定额外,焦点行和复制的块不是来自同一个地方(分部分项工其它)
  25. return true;
  26. }
  27. if(selected.sourceType == Bills.getSourceType() && selected.data.type == billType.FX && blockData.firstNodeType == blockType.FB){//焦点行是分项,复制块的第一层是分部,则无效。
  28. return true;
  29. }
  30. if(blockData.firstNodeType == blockType.RATION && selected.sourceType == Bills.getSourceType()){ //复制的是定额/量价/工料机、焦点行是分部/清单父项则无效
  31. if( selected.data.type == billType.FB ){
  32. return true;
  33. }
  34. if(MainTreeCol.readOnly.billsParent(selected)){
  35. return true;
  36. }
  37. if(this.haveCalcBase(selected)){//有使用基数计算,disable
  38. return true;
  39. }
  40. }
  41. if(blockData.firstNodeType != blockType.RATION && selected.sourceType == ModuleNames.ration){
  42. return true;
  43. }
  44. return false;
  45. },
  46. haveCalcBase : function (node) {
  47. if(node.data.calcBase ==null||node.data.calcBase ==undefined|| node.data.calcBase == ""){
  48. return false;
  49. }
  50. return true;
  51. },
  52. isDXFYorMainEq:function (node) {//焦点行是大项费用或定额下的主材设备
  53. if(node.sourceType == ModuleNames.bills && node.data.type == billType.DXFY){//焦点行是大项费用则无效;
  54. return true;
  55. }
  56. if(node.sourceType == ModuleNames.ration_glj){// 焦点行是定额下的主材设备则无效;
  57. return true;
  58. }
  59. return false;
  60. },
  61. getBlockData:function () {
  62. let blockString =getLocalCache('project_block');
  63. if(blockString !=null){
  64. return JSON.parse(blockString);
  65. }
  66. return null;
  67. },
  68. copyBlock:function (selection) {
  69. let startTime = +new Date();
  70. let blockOjb = {
  71. compilationID:projectInfoObj.projectInfo.compilation,
  72. datas:[]
  73. };
  74. let firstNode = projectObj.project.mainTree.items[selection.row];
  75. let copyNodes = [firstNode];
  76. if(selection.rowCount > 1){
  77. for(let i = 1;i<selection.rowCount;i ++){
  78. let temNode = projectObj.project.mainTree.items[selection.row + i];
  79. if(this.copyBtnDisable(temNode) == false&&temNode.getParentID() != -1 && temNode.getParentID() == firstNode.getParentID() ){//多选时,与选中的第一个节点同一层次的才复制,即父节点一样的,其它的忽略,copyBtnDisable 判断要为false
  80. copyNodes.push(temNode);
  81. }
  82. }
  83. }
  84. if(firstNode.sourceType == projectObj.project.Bills.getSourceType()){
  85. blockOjb.firstNodeType = firstNode.data.type;
  86. }else if(firstNode.sourceType == projectObj.project.Ration.getSourceType()){
  87. blockOjb.firstNodeType = blockType.RATION;
  88. }
  89. blockOjb.isFBFX = projectObj.project.Bills.isFBFX(firstNode);
  90. let ration_glj_Map = _.groupBy(projectObj.project.ration_glj.datas, 'rationID');
  91. for(let cNode of copyNodes){
  92. blockOjb.datas.push(this.getNodeDatas(cNode,ration_glj_Map));
  93. }
  94. let getDataTime = +new Date();
  95. console.log(`复制所用时间——${getDataTime - startTime}`);
  96. blockOjb.copyTime = +new Date();//设置复制时间,可以用来做过期处理
  97. setLocalCache('project_block',JSON.stringify(blockOjb));
  98. let endTime = +new Date();
  99. console.log(`复制所用时间——${endTime - startTime}`);
  100. },
  101. getNodeDatas : function (node,ration_glj_Map) {
  102. let data = node.data;
  103. data.sourceType = node.sourceType;
  104. if(node.sourceType == projectObj.project.Bills.getSourceType()){
  105. data.quantity_details = projectObj.project.quantity_detail.getDetailByBillID(data.ID);
  106. }
  107. if(node.sourceType == projectObj.project.Ration.getSourceType()){
  108. if(node.data.type == rationType.install){ //如果是生成的安装增加费,则跳过
  109. return null;
  110. }
  111. let gljList = ration_glj_Map[data.ID]?ration_glj_Map[data.ID]:[];//gljOprObj.filterGljByRation(node.data, datas);
  112. gljList = gljOprObj.combineWithProjectGlj(gljList,false);
  113. data.ration_gljs = gljList;
  114. data.ration_coes = projectObj.project.ration_coe.getCoeByRationID(data.ID);
  115. data.ration_installations = projectObj.project.ration_installation.getInstallationByRationID(data.ID);
  116. data.quantity_details = projectObj.project.quantity_detail.getDetailByRationID(data.ID);
  117. }else if(node.children.length>0){
  118. let children = [];
  119. for(let c of node.children){
  120. let tem_data = this.getNodeDatas(c,ration_glj_Map);
  121. tem_data?children.push(tem_data):'';
  122. }
  123. data.children = children;
  124. }
  125. return data;
  126. },
  127. pasteBlock:function (selected) {
  128. let blockData = this.getBlockData();
  129. let position = this.initOptionDiv(selected,blockData);
  130. if(position == null){
  131. return;
  132. }
  133. this.confirmPaste(blockData,selected,position);
  134. //do paste
  135. },
  136. initOptionDiv:function (selected,blockData) {
  137. let Bills = projectObj.project.Bills;
  138. if( blockData.firstNodeType == blockType.RATION){//如果剪切板中是复制的定额块
  139. if(selected.sourceType == ModuleNames.ration && selected.data.type != rationType.install ){//焦点行是定额/量价/工料机,则粘贴为后项
  140. return "next";
  141. }
  142. if(isFXorBX(selected)||(selected.sourceType === Bills.getSourceType()&& selected.source.children.length == 0)){//焦点行是分项/叶子清单,且无基数计算,则粘贴到分项/叶子清单下
  143. if(!this.haveCalcBase(selected)){//无基数计算
  144. return "sub";
  145. }
  146. }
  147. }
  148. //设置选项的初始值
  149. setRadioProp('next_node',{checked:true,disabled:false});
  150. setRadioProp('pre_node',{checked:false,disabled:false});
  151. if(Bills.isFBFX(selected)){// (2.1)、焦点行属于“分部分项工程”:
  152. //复制块的第一层、焦点行的类型都是“分部”
  153. if(blockData.firstNodeType == blockType.FB && isFB(selected)){
  154. if(selected.children.length > 0 && isFXorBX(selected.children[0])){//焦点行分部下有分项补项,弹出“粘贴位置选择”,默认为当前行的后项,可选前项,子项灰显。
  155. setRadioProp('sub_node',{checked:false,disabled:true});
  156. }else {
  157. //默认为当前行的后项,可选前项、子项。
  158. setRadioProp('sub_node',{checked:false,disabled:false});
  159. }
  160. }
  161. //复制块的第一层、焦点行的类型都是“分项”或补项
  162. if(blockIsFXorBX(blockData.firstNodeType) && isFXorBX(selected)){
  163. //默认为当前行的后项,可选前项,子项灰显不可选。
  164. setRadioProp('sub_node',{checked:false,disabled:true});
  165. }
  166. //复制块的第一层是分项,焦点行是分部,且分部下无子项或者子项是分项
  167. if(blockIsFXorBX(blockData.firstNodeType)&& isFB(selected)){
  168. if(selected.children.length == 0 || isFXorBX(selected.children[0])){
  169. return 'sub';//不弹出选择窗口,直接粘贴为子项。
  170. }
  171. }
  172. }else {//焦点行不属于“分部分项工程”
  173. if(blockData.firstNodeType == blockType.BILL &&selected.sourceType == Bills.getSourceType()){//如果剪切板中是从“分部分项工程”以外复制的清单块
  174. if(selected.children.length==0 || selected.children[0].sourceType == Bills.getSourceType()){//焦点行没有子项,或者子项是清单,判断是否有基数计算
  175. if(this.haveCalcBase(selected)){//如果焦点行有基数计算,则子项灰显不可选。
  176. setRadioProp('sub_node',{checked:false,disabled:true});
  177. }else{//如果焦点行没有基数计算,则子项可选。
  178. setRadioProp('sub_node',{checked:false,disabled:false});
  179. }
  180. }else {
  181. setRadioProp('sub_node',{checked:false,disabled:true});
  182. }
  183. }
  184. }
  185. $("#pastePosition").modal({show:true});
  186. return null;
  187. function setRadioProp(id,options) {
  188. $("#"+id).prop("checked",options.checked);
  189. $("#"+id).prop("disabled",options.disabled);
  190. }
  191. function isFB(selected) {
  192. return selected.sourceType == Bills.getSourceType() && selected.data.type == billType.FB;
  193. }
  194. function isFXorBX(selected) {//是分项或者补项
  195. if(selected.sourceType == Bills.getSourceType()){
  196. return selected.data.type == billType.FX || selected.data.type == billType.BX;
  197. }
  198. return false;
  199. }
  200. function blockIsFXorBX(type) {
  201. return type == blockType.FX||type == blockType.BX;
  202. }
  203. },
  204. /**
  205. * @param blockData
  206. * @param selected
  207. * @param position next/pre/sub
  208. */
  209. confirmPaste:function (blockData,selected,position) {
  210. let me = this;
  211. let project = projectObj.project;
  212. let Bills = project.Bills;
  213. let parent = null,next = null,pre = null;
  214. let firstParentID = null, lastNextID = null;
  215. let updateData = [],billUpdate = null;
  216. let billsIDMap = {};//用来做新旧ID映射
  217. if(blockData.compilationID != projectInfoObj.projectInfo.compilation){//如果编办不一样,不能复制
  218. alert("编办不一致,不能粘贴!");
  219. return;
  220. }
  221. if(position == 'next'){ //插入为选中节点的后项,即选中节点为前项
  222. parent = selected.parent;
  223. next = selected.nextSibling;
  224. pre = selected;
  225. }
  226. if(position == 'pre'){//插入为选中节点的前项,即选中节点为后项
  227. parent = selected.parent;
  228. next = selected;
  229. pre = selected.preSibling;
  230. }
  231. if(position == 'sub'){//即选中节点为父项
  232. parent = selected;
  233. pre = selected.lastChild();
  234. }
  235. let parentID = parent?parent.getID():-1;
  236. let nextID = next?next.getID():-1;
  237. if(blockData.firstNodeType == blockType.RATION){ //复制的是定额,需根据新的父项信息和工程量明细计算工程量
  238. for(let d of blockData.datas){
  239. d.billsItemID = parentID;
  240. let billsQuantity = scMathUtil.roundForObj(parent.data.quantity,getDecimal("quantity",parent));
  241. this.calcRationQuantityAndContain(billsQuantity,d);
  242. //如果粘贴位置不属于分部分项工程,或者不是安装工程,则把安装增加费内容置空
  243. if(!Bills.isFBFX(parent)|| projectInfoObj.projectInfo.property.engineering!=engineeringType.BUILD_IN){
  244. d.ration_installations = [];
  245. }
  246. }
  247. //计算序列号
  248. this.calcRationSerialNo(parentID,blockData,updateData,pre,next);
  249. }else {
  250. firstParentID = parentID;
  251. lastNextID = nextID;
  252. /* blockData.data.ParentID = parentID;
  253. blockData.data.NextSiblingID = nextID;*/
  254. if(pre){
  255. billUpdate = {type:blockData.datas[0].sourceType,query:{ID:pre.getID()},doc:{NextSiblingID:blockData.datas[0].ID}};
  256. }
  257. }
  258. let dataMap = this.preparePasteData(blockData.datas,billsIDMap,firstParentID,lastNextID);
  259. if(billUpdate){
  260. billUpdate.doc.NextSiblingID = billsIDMap[billUpdate.doc.NextSiblingID];
  261. updateData.push(billUpdate);
  262. }
  263. dataMap.updateData = updateData;
  264. dataMap.projectID = projectObj.project.ID();
  265. console.log(dataMap);
  266. $.bootstrapLoading.start();
  267. CommonAjax.post('/bills/pasteBlock',dataMap,function (result) {
  268. $.bootstrapLoading.end();
  269. //更新前端缓存
  270. me.updateCache(result);
  271. //插入树节点
  272. let rationNodes = me.addToTree(parentID,nextID,result.bills,result.rations);
  273. //主材设备工料机插入主树
  274. project.ration_glj.addToMainTree(result.ration_gljs);
  275. //更新计算程序模板,并进行重新计算
  276. project.calcProgram.calcRationsAndSave(rationNodes);
  277. })
  278. },
  279. updateCache:function(result){
  280. let project = projectObj.project;
  281. let Bills = project.Bills,Ration = project.Ration;
  282. let mainTree = project.mainTree;
  283. Bills.addDatasToList(result.bills);
  284. Ration.addDatasToList(result.rations);
  285. project.quantity_detail.addDatasToList(result.quantity_details);
  286. project.ration_glj.addDatasToList(result.ration_gljs);
  287. project.ration_coe.addDatasToList(result.ration_coes);
  288. project.ration_installation.addDatasToList(result.ration_installations);
  289. for(let u of result.updateData){
  290. let unode = mainTree.findNode(u.query.ID);
  291. if(unode){
  292. for(let ukey in u.doc){
  293. unode.data[ukey] = u.doc[ukey];
  294. }
  295. }
  296. }
  297. //更新项目工料机模块信息-计算消耗量
  298. project.projectGLJ.datas = result.gljData;
  299. project.projectGLJ.calcQuantity();
  300. },
  301. addToTree:function (parentID,nextID,bills,rations) {
  302. let project = projectObj.project;
  303. let Bills = project.Bills,mainTree = project.mainTree;
  304. let parentMap_b = {},parentMap_r = {};
  305. let newNodes = [],firstNode = null,rationNodes=[];
  306. createParentMap(parentMap_b,bills,'bills');
  307. createParentMap(parentMap_r,rations,'ration');
  308. if(parentMap_b[parentID]){
  309. for(let i = 0;i < parentMap_b[parentID].length;i++){
  310. let temNode = loadTreeNode(parentID,nextID,parentMap_b[parentID][i],'bills');
  311. i==0?firstNode = temNode:'';
  312. }
  313. }else if(parentMap_r[parentID]){
  314. for(let i = 0;i<parentMap_r[parentID].length;i++){
  315. let temNode = loadTreeNode(parentID,nextID,parentMap_r[parentID][i],'ration');
  316. i==0?firstNode = temNode:'';
  317. }
  318. }
  319. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
  320. let sels = projectObj.mainController.sheet.getSelections();
  321. //设置选中并更新下方显示
  322. projectObj.mainController.setTreeSelected(firstNode);
  323. projectObj.mainController.sheet.setSelection(firstNode.serialNo(), sels[0].col, 1, 1);
  324. return rationNodes;
  325. function loadTreeNode(parentID,nextID,data,type) {
  326. let newNode = null;
  327. if(type == 'bills'){
  328. let newSource = Bills.tree.insertByData(data,parentID,nextID,true);
  329. newNode = mainTree.insert(parentID, nextID,data.ID);
  330. if (newNode) {
  331. newNode.source = newSource;
  332. newNode.sourceType = Bills.getSourceType();
  333. newNode.data = data;
  334. newNodes.push(newNode);
  335. let subType = 'bills';
  336. let children = parentMap_b[data.ID];
  337. if(!children){
  338. children = parentMap_r[data.ID];
  339. subType = 'ration';
  340. }
  341. if(children){
  342. for(let c of children){
  343. loadTreeNode(data.ID,-1,c,subType);
  344. }
  345. }
  346. }
  347. }else if(type == 'ration'){
  348. newNode = project.mainTree.insert(parentID, nextID, data.ID);
  349. newNode.source = data;
  350. newNode.sourceType = project.Ration.getSourceType();
  351. newNode.data = data;
  352. newNodes.push(newNode);
  353. rationNodes.push(newNode);
  354. }
  355. return newNode;
  356. }
  357. function createParentMap(parentMap,list,type) {
  358. let parentKey = type=='bills'?'ParentID':'billsItemID';
  359. for(let l of list){
  360. let parentID = l[parentKey];
  361. if(parentMap[parentID]){
  362. parentMap[parentID].push(l);
  363. }else {
  364. parentMap[parentID] = [l];
  365. }
  366. }
  367. }
  368. },
  369. preparePasteData : function (datas,billsIDMap,firstParentID,lastNextID) {
  370. let me = this;
  371. me.datas = _.cloneDeep(projectObj.project.Bills.datas);
  372. let bills = [],rations=[],ration_gljs = [],ration_coes = [],quantity_details = [],ration_installations = [];
  373. let firstBillIDs = [],lastBillID = null;//记录第一层清单的ID,和第一层的最后一个清单ID
  374. let firstIDMap = {};
  375. for(let i = 0 ;i< datas.length ;i++){
  376. if(datas[i].sourceType == 'bills'){
  377. firstBillIDs.push(datas[i].ID);
  378. if(i == datas.length -1){//最后一个清单节点
  379. lastBillID = datas[i].ID
  380. }
  381. }
  382. eachData(datas[i]);
  383. }
  384. for(let f of firstBillIDs){
  385. firstIDMap[billsIDMap[f]] = f //反向映射
  386. }
  387. for(let b of bills){//更新ID
  388. if(firstIDMap[b.ID]) {//如果是第一层清单节点对应的数据,更新父ID 为当前树中的父ID
  389. b.ParentID = firstParentID;
  390. }else {
  391. billsIDMap[b.ParentID]?b.ParentID = billsIDMap[b.ParentID]:'';
  392. }
  393. if(b.ID == billsIDMap[lastBillID]){//如果是第一层清单最后节点对应的数据,更新下一节点ID为插入位置的下一个节点ID
  394. b.NextSiblingID = lastNextID;
  395. }else {
  396. billsIDMap[b.NextSiblingID]?b.NextSiblingID = billsIDMap[b.NextSiblingID]:'';
  397. }
  398. }
  399. return {bills:bills,rations:rations,ration_gljs:ration_gljs,ration_coes:ration_coes,quantity_details:quantity_details,ration_installations:ration_installations};
  400. function eachData(data) {
  401. if(data.sourceType == 'bills'){
  402. let tem_b = createBillsData(data);
  403. bills.push(tem_b);
  404. for(let d of data.quantity_details){
  405. quantity_details.push(createQuantityDetails(d,tem_b,'bills'));
  406. }
  407. if(data.children && data.children.length>0){
  408. for(let c of data.children){
  409. eachData(c);
  410. }
  411. }
  412. }
  413. if( data.sourceType == 'ration'){
  414. let tem_r = createRationData(data);
  415. rations.push(tem_r);
  416. for(let d of data.quantity_details){
  417. quantity_details.push(createQuantityDetails(d,tem_r, 'ration'));
  418. }
  419. for(let g of data.ration_gljs){
  420. let tem_rg = createSubList(g,tem_r);
  421. tem_rg.billsItemID = tem_r.billsItemID;
  422. ration_gljs.push(tem_rg);
  423. }
  424. for(let o of data.ration_coes){
  425. ration_coes.push(createSubList(o,tem_r));
  426. }
  427. for(let ri of data.ration_installations){
  428. ration_installations.push(createSubList(ri,tem_r));
  429. }
  430. }
  431. }
  432. function createSubList(subData,rationData) {
  433. let tem_sub = _.cloneDeep(subData);
  434. delete tem_sub._id;
  435. tem_sub.ID = uuid.v1();
  436. tem_sub.projectID = projectObj.project.ID();
  437. tem_sub.rationID = rationData.ID;
  438. return tem_sub;
  439. }
  440. function createQuantityDetails(detailData,pdata,type) {
  441. let tem_detail = _.cloneDeep(detailData);
  442. delete tem_detail._id;
  443. tem_detail.ID = uuid.v1();
  444. tem_detail.projectID = projectObj.project.ID();
  445. if(type == 'bills'){
  446. tem_detail.billID = pdata.ID;
  447. }
  448. if(type == 'ration'){
  449. tem_detail.rationID = pdata.ID;
  450. }
  451. return tem_detail;
  452. }
  453. function createRationData(rationData) {
  454. let tem_ration = _.cloneDeep(rationData);
  455. //删除旧数据
  456. delete tem_ration._id;
  457. delete tem_ration.fees;
  458. delete tem_ration.feesIndex;
  459. delete tem_ration.ration_gljs;
  460. delete tem_ration.ration_coes;
  461. delete tem_ration.ration_installations;
  462. delete tem_ration.quantity_details;
  463. delete tem_ration.__v;
  464. delete tem_ration.sourceType;
  465. tem_ration.projectID = projectObj.project.ID();
  466. tem_ration.ID = uuid.v1();
  467. billsIDMap[tem_ration.billsItemID]?tem_ration.billsItemID = billsIDMap[tem_ration.billsItemID]:'';
  468. let firstLibID = rationLibObj.getFirstStdRationLibID();
  469. if(firstLibID){
  470. tem_ration.prefix = projectObj.project.Ration.getRationPrefix(firstLibID,tem_ration);
  471. }
  472. return tem_ration;
  473. }
  474. function createBillsData(billsData) { //ID、重新生成code
  475. let temData = _.cloneDeep(billsData);
  476. //删除旧数据
  477. delete temData._id;
  478. delete temData.fees;
  479. delete temData.feesIndex;
  480. delete temData.children;
  481. delete temData.quantity_details;
  482. delete temData.__v;
  483. delete temData.sourceType;
  484. temData.projectID = projectObj.project.ID();
  485. let newID = uuid.v1(); //新的清单ID
  486. billsIDMap[temData.ID] = newID;
  487. temData.ID = newID; //新的清单ID
  488. if(temData.billsLibId && temData.billsLibId!="" && temData.code.length == 12){//是从清单库来的
  489. let value = temData.code.substr(0,9);
  490. if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
  491. temData.code = projectObj.project.Bills.newFormatCode(value);
  492. }
  493. }
  494. me.datas.push(temData);//为了下一个清单的std code 一样
  495. return temData;
  496. }
  497. },
  498. calcRationSerialNo:function (billsItemID,blockData,updateData,pre,next) {
  499. let br = projectObj.project.Ration.getBillsSortRation(billsItemID);
  500. let firstSerialNo = 0;
  501. if(next == null){ //没有下一树节点,即为最后节点
  502. firstSerialNo = br.length > 0 ? br[br.length - 1].serialNo + 1 : 1;
  503. }else {//有下一节点
  504. let startIndex =0;
  505. if(pre){
  506. startIndex = br.indexOf(pre.data)+1;
  507. }
  508. firstSerialNo = br[startIndex].serialNo;
  509. for(let i = startIndex;i < br.length; i++){
  510. let br_serialNo = br[i].serialNo + blockData.datas.length; //i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  511. updateData.push({type:blockData.datas[0].sourceType,query:{ID:br[i].ID},doc:{serialNo:br_serialNo}});//更新兄弟节点序列号
  512. }
  513. }
  514. for(let i = 0 ; i < blockData.datas.length;i++){
  515. blockData.datas[i].serialNo = firstSerialNo;
  516. firstSerialNo += 1;
  517. }
  518. },
  519. calcRationQuantityAndContain : function (billsQuantity,ration) {//计算定额工程量和含量
  520. let EXPString = ration.quantityEXP+"";
  521. if(EXPString.indexOf("QDL") != -1){
  522. if(EXPString=="QDL"){//定额的工程量是直接通过清单量填进来的;
  523. let times = parseInt(ration.unit);
  524. if(isNaN(times)){
  525. times = 1;
  526. }
  527. ration.quantity = scMathUtil.roundForObj(billsQuantity / times,getDecimal("ration.quantity"));
  528. billsQuantity?ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,getDecimal("process")):ration.contain = 0;
  529. } else {//如果定额的工程量是通过计算出来的,则应该重新计算。
  530. let tem_contain = scMathUtil.roundForObj(ration.contain,getDecimal("process"));
  531. let tem_quantity = scMathUtil.roundForObj(billsQuantity*tem_contain,getDecimal("ration.quantity")); //this.autoTransformQuantity(tem_quantity,rationNode);
  532. ration.quantity = tem_quantity;
  533. }
  534. }else {//GCLMXHJ
  535. let tem_contain=0;
  536. if(billsQuantity&&billsQuantity!=0){
  537. let children_quantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
  538. // children_quantity = scMathUtil.roundForObj(this.reverseQuantity(children_quantity,rationNode),getDecimal("quantity",rationNode)); 原先是要反算的,现在改成不用反算了
  539. tem_contain =scMathUtil.roundForObj(children_quantity/billsQuantity,getDecimal("process"));
  540. }
  541. ration.contain = tem_contain;
  542. }
  543. },
  544. newFormatCode : function (stdCode, filterCode) {
  545. let matchs = this.sameStdCode(stdCode, filterCode);
  546. let format = function (Number) {
  547. let s = Number + '';
  548. while (s.length < 3) {
  549. s = '0' + s;
  550. }
  551. return s;
  552. };
  553. for (let i = 0; i <= matchs.length; i++) {
  554. let formatCode = stdCode + format(i+1);
  555. if (matchs.indexOf(formatCode) === -1) {
  556. return formatCode;
  557. }
  558. }
  559. },
  560. sameStdCode : function (stdCode, filterCode) {
  561. let reg = new RegExp('^' + stdCode), matchs= [];
  562. for (let data of this.datas) {
  563. if (data.code && data.code.length === 12 && reg.test(data.code) && data.code !== filterCode) {
  564. matchs.push(data.code);
  565. }
  566. }
  567. return matchs;
  568. },
  569. removeBlock:function () {
  570. removeLocalCache('project_block');
  571. }
  572. };