block_controller.js 27 KB

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