quantity_detail.js 33 KB

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