block_controller.js 29 KB

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