quantity_detail.js 33 KB

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