quantity_detail.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var quantity_detail = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var quantity_detail = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var sourceType = ModuleNames.quantity_detail;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.quantity_detail, this);
  18. this.temList=[];
  19. };
  20. // prototype用于定义public方法
  21. quantity_detail.prototype.loadData = function (datas) {
  22. this.datas = datas;
  23. };
  24. // 提交数据后返回数据处理
  25. quantity_detail.prototype.doAfterUpdate = function(err, data){
  26. if(!err){
  27. if(data.updateTpye=='ut_update'){
  28. this.refreshAfterUpdate(data);
  29. }else if(data.updateTpye=='ut_delete'){
  30. this.refreshAfterDelete(data);
  31. } else {
  32. this.refreshAfterSave(data);
  33. }
  34. }else {
  35. alert(err.message);
  36. this.refreshSheetData();
  37. }
  38. };
  39. quantity_detail.prototype.refreshAfterSave=function(data){
  40. var me = this;
  41. if(data.hasOwnProperty('resort')){
  42. this.resortData(data.doc,1);
  43. _.forEach(data.update_task,function (item) {
  44. me.refreshEachItme(item.query,item.doc);
  45. })
  46. this.datas.push(data.doc);
  47. }else {
  48. this.datas.push(data);
  49. }
  50. this.refreshSheetData();
  51. };
  52. quantity_detail.prototype.resortData=function(data,req){
  53. for(var i =0;i<gljOprObj.detailData.length;i++){
  54. var item = gljOprObj.detailData[i];
  55. if(item.seq>=data.seq){
  56. item.seq=item.seq+req;
  57. }
  58. }
  59. };
  60. quantity_detail.prototype.refreshAfterUpdate=function(data){
  61. var me = this;
  62. var filter_object;
  63. if(data.hasOwnProperty('refreshList')){
  64. _.forEach(data.refreshList,function (item) {
  65. filter_object= me.refreshEachItme(item.query,item.doc);
  66. })
  67. }else {
  68. filter_object = me.refreshEachItme(data.query,data.doc);
  69. }
  70. var showList = _.filter(this.datas,filter_object);
  71. gljOprObj.detailData=showList;
  72. gljOprObj.detailData=_.sortBy(gljOprObj.detailData,'seq');
  73. this.refreshSheetData();
  74. };
  75. quantity_detail.prototype.refreshEachItme = function(query,doc){
  76. var detail_list = this.datas;
  77. var detail_index= _.findIndex(detail_list,function(detail){
  78. return detail.ID==query.ID;
  79. })
  80. _.forEach(doc, function(n, key) {
  81. detail_list[detail_index][key] = n;
  82. });
  83. var filter_object;
  84. if(detail_list[detail_index].hasOwnProperty('rationID')){
  85. filter_object={'rationID':detail_list[detail_index].rationID};
  86. }else {
  87. filter_object={'billID':detail_list[detail_index].billID};
  88. }
  89. return filter_object;
  90. };
  91. quantity_detail.prototype.refreshAfterDelete=function(data){
  92. var me = this;
  93. if(data.doc.seq != gljOprObj.detailData.length - 1){
  94. this.resortData(data.doc,-1);
  95. }
  96. _.forEach(data.update_task,function (item) {
  97. me.refreshEachItme(item.query,item.doc);
  98. });
  99. _.remove(this.datas,{ID:data.doc.ID});
  100. this.refreshSheetData();
  101. };
  102. quantity_detail.prototype.refreshSheetData=function () {
  103. gljOprObj.showQuantityDetailData();
  104. };
  105. quantity_detail.prototype.saveQuantityDetail=function (args,dataCode,selected) {
  106. var me = this;
  107. var doc={};
  108. var selected = selected?selected:projectObj.project.mainTree.selected;
  109. if(selected.sourceType==ModuleNames.ration){
  110. doc.rationID=selected.data.ID;
  111. }
  112. if(selected.sourceType==ModuleNames.bills){
  113. doc.billID=selected.data.ID;
  114. }
  115. doc.projectID = selected.data.projectID;
  116. doc[dataCode]=args.editingText;
  117. doc.seq=args.row;
  118. if(dataCode=='regex'){
  119. if(!this.regexChecking(args.editingText)||!this.referenceChecking(args.editingText,args.row,doc)){
  120. gljOprObj.showQuantityDetailData();
  121. return;
  122. }
  123. doc.refreshQuantity=true;
  124. if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
  125. var c = confirm("确定要使用工程量明细替换原工程量吗?");
  126. if(!c){
  127. doc.refreshQuantity=false;
  128. }
  129. }
  130. }
  131. var url="";
  132. $.bootstrapLoading.start();
  133. if(args.hasOwnProperty("insertRecode")){//右键插入或者是通过直接编辑保存
  134. url = "/quantity_detail/insertRecode";
  135. }else{
  136. url = "/quantity_detail/save";
  137. }
  138. var callback = function (data) {
  139. if(doc.refreshQuantity==false){//清空数据
  140. me.cleanQuantityDetail();
  141. }else {
  142. data.newRecord?me.refreshAfterSave(data.newRecord):me.refreshAfterSave(data);
  143. if(data.node){
  144. me.refreshRationOrBillNodes(data.node);
  145. }
  146. //gljOprObj.detailSheet.setActiveCell(0,0);
  147. //gljOprObj.detailSheet.clearSelection();
  148. }
  149. $.bootstrapLoading.end();
  150. }
  151. CommonAjax.post(url,doc,callback,function () {
  152. $.bootstrapLoading.end();
  153. });
  154. };
  155. quantity_detail.prototype.refreshRationOrBillNodes=function(node){//工程量明细更新后触发定额或清单工程量改变,进行相应的更新
  156. var nodes = gljOprObj.refreshTreeNode(node);
  157. if(nodes.length>0){//触发计算
  158. let newNode = nodes[0];
  159. if(newNode.sourceType === project.Bills.getSourceType()){
  160. console.log(newNode.data.quantity);
  161. this.updateBillQuantity(newNode.data.quantity,newNode,newNode.data.quantityEXP);
  162. }else {//更新定额所使用的值要用还没转换前的
  163. this.updateRationQuantity(node.data.r_quantity,newNode,newNode.data.quantityEXP);//to do 加上工程量表达式和含量更新
  164. }
  165. }
  166. };
  167. quantity_detail.prototype.insertQuantityDetail = function (row) {
  168. var args = {
  169. row:row,
  170. editingText:1
  171. }
  172. if(row < gljOprObj.detailData.length){
  173. args.insertRecode = true;
  174. }
  175. this.saveQuantityDetail(args,'isSummation');
  176. };
  177. quantity_detail.prototype.deleteQuantityDetail = function (row) {
  178. var me = this;
  179. var deleteable = this.checkReference(row);
  180. if(deleteable){
  181. var recode = gljOprObj.detailData[row];
  182. $.bootstrapLoading.start();
  183. var callback=function (result) {
  184. me.refreshAfterDelete(result.data);
  185. if(result.node){//触发计算
  186. me.refreshRationOrBillNodes(result.node);
  187. }
  188. $.bootstrapLoading.end();
  189. }
  190. CommonAjax.post("/quantity_detail/deleteRecode",recode,callback,function () {
  191. $.bootstrapLoading.end();
  192. });
  193. }else {
  194. alert("当前行已被引用,不可删除。");
  195. }
  196. };
  197. quantity_detail.prototype.checkReference = function (row) {
  198. var deleteable = true;
  199. for(var i =0;i<gljOprObj.detailData.length;i++){
  200. var item = gljOprObj.detailData[i];
  201. if(_.includes(item.referenceIndexs,row+1)){
  202. deleteable = false;
  203. break;
  204. }
  205. }
  206. return deleteable;
  207. };
  208. quantity_detail.prototype.moveDown = function (row) {
  209. this.swapRow(row);
  210. };
  211. quantity_detail.prototype.moveUp = function (row) {
  212. this.swapRow(row-1);
  213. };
  214. quantity_detail.prototype.swapRow = function (preRow) {
  215. var me = this;
  216. var update_task = [];
  217. var a_row = gljOprObj.detailData[preRow];//
  218. var b_row = gljOprObj.detailData[preRow +1];//
  219. var temA = a_row.seq;
  220. var temB = b_row.seq;
  221. a_row.seq = temB;
  222. update_task.push({query:{ID:a_row.ID,projectID:a_row.projectID},doc:{seq:a_row.seq}});
  223. b_row.seq = temA;
  224. update_task.push({query:{ID:b_row.ID,projectID:b_row.projectID},doc:{seq:b_row.seq}});
  225. gljOprObj.detailData.forEach(function (item) {
  226. if(_.includes(item.referenceIndexs,temA+1)||_.includes(item.referenceIndexs,temB+1)){
  227. var regex = item.regex;
  228. for (var i=0;i<item.referenceIndexs.length;i++){
  229. if(item.referenceIndexs[i]==temA+1){
  230. regex = me.replaceAll('C'+item.referenceIndexs[i],'B'+(temB+1),regex);
  231. regex = me.replaceAll('c'+item.referenceIndexs[i],'b'+(temB+1),regex);
  232. item.referenceIndexs[i]=temB+1;
  233. }else if(item.referenceIndexs[i]==temB+1){
  234. regex = me.replaceAll('C'+item.referenceIndexs[i],'B'+(temA+1),regex);
  235. regex = me.replaceAll('c'+item.referenceIndexs[i],'b'+(temA+1),regex);
  236. item.referenceIndexs[i]=temA+1;
  237. }
  238. }
  239. regex = me.replaceAll('B','C',regex);
  240. regex = me.replaceAll('b','c',regex);
  241. update_task.push({query:{ID:item.ID,projectID:item.projectID},doc:{regex:regex,referenceIndexs:item.referenceIndexs}});
  242. }
  243. })
  244. me.commonUpdate("/quantity_detail/swapRow",update_task);
  245. };
  246. quantity_detail.prototype.replaceAll=function(FindText, RepText,str) {
  247. let regExp = new RegExp(FindText, "g");
  248. return str.replace(regExp, RepText);
  249. };
  250. quantity_detail.prototype.updateQuantityDetail=function (args,dataCode,recode,selected) {
  251. var doc ={};
  252. var query={
  253. ID:recode.ID,
  254. projectID:recode.projectID
  255. };
  256. var selected = selected?selected:projectObj.project.mainTree.selected;
  257. doc[dataCode]=args.editingText;
  258. if (dataCode == 'regex') {
  259. if(recode.hasOwnProperty('rationID')){
  260. query.rationID=recode.rationID;
  261. }else {
  262. query.billID = recode.billID
  263. }
  264. query.refreshQuantity=true;
  265. if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
  266. var c = confirm("确定要使用工程量明细替换原工程量吗?");
  267. if(!c){
  268. //query.refreshQuantity=false;
  269. this.cleanQuantityDetail(selected,true);
  270. return;
  271. }
  272. }
  273. query.index = args.row;
  274. this.updateQuantityRegex(query,doc,args)
  275. }else {
  276. this.normalUpdate(query,doc);
  277. }
  278. };
  279. quantity_detail.prototype.updateQuantityRegex=function(query,doc,args){
  280. var needupdate = false;
  281. if(args.editingText==null){
  282. needupdate =true;
  283. }else {
  284. args.editingText = _.trim(args.editingText,/\r\n/);
  285. if(this.regexChecking(args.editingText)&&this.referenceChecking(args.editingText,args.row,doc)){
  286. needupdate = true;
  287. }
  288. }
  289. if(needupdate){
  290. this.commonUpdate("/quantity_detail/updateRegex",{query:query,doc:doc});
  291. }else {
  292. var sheet = subSpread.getActiveSheet();
  293. sheet.getCell(args.row,args.col).value(gljOprObj.detailData[args.row].regex);
  294. }
  295. };
  296. quantity_detail.prototype.isSummationUpdate=function (args,detailList,newval) {
  297. var query={
  298. ID:detailList[args.row].ID,
  299. projectID:detailList[args.row].projectID
  300. };
  301. var selected = projectObj.project.mainTree.selected;
  302. query.refreshQuantity=true;
  303. if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
  304. var c = confirm("确定要使用工程量明细替换原工程量吗?");
  305. if(!c){
  306. query.refreshQuantity=false;
  307. }
  308. }
  309. if(detailList[args.row].hasOwnProperty('rationID')){
  310. query.rationID=detailList[args.row].rationID;
  311. }else {
  312. query.billID = detailList[args.row].billID
  313. }
  314. var doc={
  315. isSummation:newval
  316. };
  317. this.normalUpdate(query,doc);
  318. };
  319. quantity_detail.prototype.commonUpdate = function (url,postData) {
  320. var me = this;
  321. $.bootstrapLoading.start();
  322. var callback = function (data) {
  323. me.refreshAfterUpdate(data);
  324. if(data.node){
  325. me.refreshRationOrBillNodes(data.node);
  326. }
  327. $.bootstrapLoading.end();
  328. }
  329. CommonAjax.post(url,postData,callback,function () {
  330. $.bootstrapLoading.end();
  331. });
  332. };
  333. quantity_detail.prototype.normalUpdate=function(query,doc){
  334. var url = "/quantity_detail/update";
  335. this.commonUpdate(url,{query:query,doc:doc});
  336. };
  337. quantity_detail.prototype.regexChecking=function(text){
  338. var regex=/^[0-9Cc\+\-\*\^/\(\)\.]*$/g;
  339. if(!regex.test(text)){
  340. alert("输入了非法字符,请重新输入!")
  341. return false;
  342. }else {
  343. return true;
  344. }
  345. };
  346. quantity_detail.prototype.referenceChecking=function (text,row,doc) {
  347. text = text.toUpperCase();
  348. //text= this.replaceSqr(text);
  349. var me = this;
  350. var refReg = /C\d+/g;
  351. var self ='C'+(row+1);
  352. var refList = text.match(refReg);
  353. var invalidate = _.includes(refList,self);
  354. var referenceIndexs = [];
  355. var indexOut = false;
  356. _.forEach(refList,function (item) {
  357. var ref_index = parseInt(item.substring(1));
  358. if(ref_index>gljOprObj.detailData.length){
  359. indexOut=true;
  360. return;
  361. }else {
  362. referenceIndexs.push(ref_index);
  363. }
  364. });
  365. if(indexOut){
  366. alert("引用有误,请重新输入!");
  367. return false;
  368. }
  369. referenceIndexs=_.uniq(referenceIndexs);
  370. doc.referenceIndexs = referenceIndexs;
  371. this.temList = referenceIndexs;
  372. invalidate=this.getAllReferenceList((row+1),referenceIndexs);
  373. if(invalidate){
  374. alert("计算式中产生了循环引用,请重新输入!");
  375. return false;
  376. }
  377. return true;
  378. };
  379. quantity_detail.prototype.getAllReferenceList=function(original,refList){
  380. var me =this;
  381. var invalidate=false;
  382. _.forEach(refList,function (item) {
  383. if(me.getReferenceList(item,original)){
  384. invalidate=true;
  385. }
  386. })
  387. return invalidate;
  388. };
  389. quantity_detail.prototype.getReferenceList=function(item,original) {
  390. var invalidate =false;
  391. if(gljOprObj.detailData.length>=item){
  392. var recode = gljOprObj.detailData[item - 1];
  393. if (recode.referenceIndexs.length > 0) {
  394. if(_.includes(recode.referenceIndexs,original)){
  395. invalidate = true;
  396. return invalidate;
  397. }
  398. this.temList = this.temList.concat(recode.referenceIndexs);
  399. _.forEach(recode.referenceIndex, function (item) {
  400. if(this.getReferenceList(item,original)){
  401. invalidate = true;
  402. }
  403. })
  404. }
  405. }
  406. return invalidate;
  407. }
  408. quantity_detail.prototype.replaceSqr = function(text) {
  409. var squarRegex = /\([^\^]+\)\^\d+/g;
  410. var sqararr = text.match(squarRegex);
  411. var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
  412. var sqararr2=text.match(squarRegex2);
  413. if(sqararr){
  414. text=converSqrByArr(sqararr,text);
  415. }
  416. if(sqararr2){
  417. text=converSqrByArr(sqararr2,text);
  418. }
  419. return text;
  420. };
  421. quantity_detail.prototype.converSqrByArr = function (sqararr,text) {
  422. var temp = text;
  423. sqararr.forEach(function (item) {
  424. var arr = item.split('\^');
  425. var y = parseInt(arr[1]);
  426. var x_arr = [];
  427. for (var i = 0; i < y; i++) {
  428. x_arr.push(arr[0]);
  429. }
  430. var temStr = x_arr.join('*');
  431. temp = temp.replace(item, temStr);
  432. });
  433. return temp;
  434. };
  435. quantity_detail.prototype.getDetailByRationID = function (rationID) {
  436. return _.filter(this.datas,{'rationID':rationID});
  437. };
  438. quantity_detail.prototype.getDetailByBillID = function (billID) {
  439. return _.filter(this.datas,{'billID':billID});
  440. };
  441. quantity_detail.prototype.deleteByRation = function(ration){
  442. var detail_list = this.datas;
  443. _.remove(detail_list,{'rationID':ration.ID});
  444. };
  445. quantity_detail.prototype.deleteByBills=function(deleteData){
  446. var detail_list = this.datas;
  447. var billIDList = [];
  448. for(var i=0;i<deleteData.length;i++){
  449. if(deleteData[i].type=='delete'){
  450. billIDList.push(deleteData[i].data.ID);
  451. }
  452. }
  453. var newList =_.filter(detail_list,(d)=>{
  454. return !_.includes(billIDList,d.billID);
  455. });
  456. if(newList!=undefined){
  457. this.datas = newList;
  458. }
  459. };
  460. quantity_detail.prototype.cleanQuantityDetail = function (node,needSave) {
  461. node =node?node:projectObj.project.mainTree.selected;
  462. var query={projectID:node.data.projectID};
  463. if(node.sourceType === project.Bills.getSourceType()){
  464. query.billID = node.data.ID;
  465. this.deleteByBills([{type:'delete',data:node.data}]);
  466. }else if(node.sourceType === project.Ration.getSourceType()){
  467. this.deleteByRation(node.data);
  468. query.rationID = node.data.ID;
  469. }
  470. if(needSave===true){
  471. query.refreshQuantity=false;
  472. CommonAjax.post("/quantity_detail/save",query);
  473. }
  474. gljOprObj.detailData=[];
  475. sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,[]);
  476. };
  477. quantity_detail.prototype.quantityEditChecking = function(value,node,fieldName){
  478. var validate = true;
  479. if(fieldName=='quantity'){
  480. if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
  481. var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?')
  482. if(c){
  483. validate = true;
  484. }else {
  485. validate = false;
  486. }
  487. }
  488. }
  489. return validate;
  490. };
  491. quantity_detail.prototype.autoTransformQuantity = function(value,node){//根据单位转换定额工程量
  492. let data = node.data;
  493. let option = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS,'rationQuanACToRationUnit');
  494. if(node.data.quantityEXP=='GCLMXHJ'||(option==true&&node.sourceType === project.Ration.getSourceType()&&data.unit)) {//还需加入判读是否转换,如果是来自工程量明细的话,默认都进行转换
  495. let times = parseInt(data.unit);
  496. if (isNaN(times)) {
  497. times = 1
  498. }
  499. value = value / times;
  500. }
  501. let EXPString=node.data.quantityEXP+"";
  502. if(option==false&&node.sourceType === project.Ration.getSourceType()&&EXPString!='GCLMXHJ'&&EXPString.indexOf("QDL")==-1&&data.unit){//勾选不根据单位转换工程量,且定额是手输的,
  503. let times = parseInt(data.unit);
  504. if(!isNaN(times)){///如果定额单位可以做转换
  505. if(isNum(EXPString)){//如果表达式中只是数字
  506. node.data.quantityEXP = EXPString+" * "+times;
  507. }else {//如果表达式是一个计算式,则要加一个括号
  508. node.data.quantityEXP = "("+EXPString+") * "+times;
  509. }
  510. if(node.data.contain!=0){
  511. let billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
  512. let temValue = scMathUtil.roundForObj(value*times,getDecimal("quantity",node));
  513. billQuantity!=0?node.data.contain = scMathUtil.roundForObj(temValue/billQuantity,getDecimal("process")):'';
  514. }
  515. }
  516. }
  517. return value;
  518. };
  519. quantity_detail.prototype.reverseQuantity = function (value,node) {//根据单位反向运算出工程量
  520. let data = node.data;
  521. if(node.sourceType === project.Ration.getSourceType()&&data.unit){
  522. let times = parseInt(data.unit);
  523. if (isNaN(times)) {
  524. times = 1
  525. }
  526. value = value * times;
  527. }
  528. return value
  529. };
  530. quantity_detail.prototype.editMainTreeNodeQuantity=function (value,node,fieldName,editingText) {
  531. var me = this;
  532. if(isNaN(value)){
  533. alert("当前输入的数据类型不正确,请重新输入。");
  534. projectObj.mainController.refreshTreeNode([node]);
  535. }else {
  536. value=value?value:0;
  537. setTimeout(function () {//spreadjs事件和提示窗口会有冲突,所以要用延时的方法
  538. if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
  539. node.data.isFromDetail=0;
  540. project.quantity_detail.cleanQuantityDetail(node,true);
  541. if(node.sourceType === project.Bills.getSourceType()){
  542. me.updateBillQuantity(value,node,null,editingText);
  543. }else {
  544. me.updateRationQuantity(value,node,null,editingText);
  545. }
  546. }else {
  547. projectObj.mainController.refreshTreeNode([node]);
  548. }
  549. },100);
  550. }
  551. };
  552. quantity_detail.prototype.updateBillQuantity=function (value,node,quantityEXP,editingText) {
  553. node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
  554. value = scMathUtil.roundForObj(value,getDecimal("quantity",node));
  555. node.data.quantity = value+"";
  556. console.log(value);
  557. let needUpdateChildren = [];//需更新的子定额
  558. let gljNodes=[];//当定额工程量改变时需刷新的子工料机
  559. if(node.children.length>0){//如果有子项
  560. for(let rationNode of node.children){
  561. let EXPString = rationNode.data.quantityEXP+"";
  562. if(EXPString.indexOf("QDL")!=-1){
  563. if(EXPString=="QDL"){//定额的工程量是直接通过清单量填进来的;
  564. let times = parseInt(rationNode.data.unit);
  565. if(isNaN(times)){
  566. times = 1;
  567. }
  568. rationNode.data.quantity = scMathUtil.roundForObj(value / times,getDecimal("quantity",rationNode));
  569. rationNode.data.contain = scMathUtil.roundForObj(rationNode.data.quantity/value,getDecimal("process"));
  570. }else {//如果定额的工程量是通过计算出来的,则应该重新计算。
  571. let tem_contain = scMathUtil.roundForObj(rationNode.data.contain,getDecimal("process"));
  572. let tem_quantity = scMathUtil.roundForObj(value*tem_contain,getDecimal("quantity",rationNode)); //this.autoTransformQuantity(tem_quantity,rationNode);
  573. rationNode.data.quantity = tem_quantity;
  574. }
  575. rationNode.changed = true;
  576. needUpdateChildren.push(rationNode);
  577. if (rationNode.children.length>0){//如果有子工料机
  578. gljNodes = gljNodes.concat(rationNode.children);
  579. }
  580. }else {
  581. let tem_contain=0;
  582. if(value&&value!=0){
  583. let children_quantity = scMathUtil.roundForObj(rationNode.data.quantity,getDecimal("quantity",rationNode));
  584. // children_quantity = scMathUtil.roundForObj(this.reverseQuantity(children_quantity,rationNode),getDecimal("quantity",rationNode)); 原先是要反算的,现在改成不用反算了
  585. tem_contain =scMathUtil.roundForObj(children_quantity/value,getDecimal("process"));
  586. }
  587. rationNode.data.contain = tem_contain;
  588. rationNode.changed = true;
  589. needUpdateChildren.push(rationNode);
  590. }
  591. }
  592. }
  593. if(needUpdateChildren.length>0){//清单下的定额工程量发生了改变
  594. node.changed = true;//本身发生了改变,需要存储。
  595. /*project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
  596. project.projectGLJ.loadData();
  597. });*/
  598. project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
  599. if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  600. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  601. if(isChange){
  602. project.calcProgram.calcRationsAndSave(rations,function () {
  603. project.projectGLJ.calcQuantity();
  604. });
  605. }
  606. });
  607. }else {
  608. project.projectGLJ.calcQuantity();
  609. }
  610. });
  611. }else {
  612. node.changed = true;
  613. project.calcProgram.calcAndSave(node, function () {
  614. project.projectGLJ.calcQuantity();
  615. });
  616. }
  617. if(gljNodes.length>0){
  618. projectObj.mainController.refreshTreeNode(gljNodes);
  619. }
  620. };
  621. quantity_detail.prototype.updateRationQuantity=function(value,node,quantityEXP,editingText){
  622. node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
  623. value = scMathUtil.roundForObj(value,getDecimal("ration.quantity"));
  624. value = project.quantity_detail.autoTransformQuantity(value,node);
  625. value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node))
  626. node.data.quantity=value;
  627. if(node.parent.data.quantity&&node.parent.data.quantity!=0&&node.parent.data.quantity!=""){
  628. var billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
  629. node.data.contain = scMathUtil.roundForObj(value/billQuantity,getDecimal("process"));
  630. }else {
  631. node.data.contain=0;
  632. }
  633. node.changed = true;
  634. project.calcProgram.calcAndSave(node, function () {
  635. project.projectGLJ.calcQuantity();
  636. if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  637. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  638. if(isChange){
  639. project.calcProgram.calcRationsAndSave(rations);
  640. }
  641. });
  642. }
  643. });
  644. projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机总消耗量
  645. gljOprObj.showRationGLJSheetData();
  646. };
  647. quantity_detail.prototype.getDecimal=function (node) {
  648. var decimal = 3;
  649. if(node.sourceType === project.Bills.getSourceType()){
  650. decimal = billsQuanDecimal.decimal(node.data.unit);
  651. }else {
  652. decimal = decimalObj.ration.quantity
  653. }
  654. return;
  655. };
  656. return new quantity_detail(project);
  657. }
  658. };