quantity_detail.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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(!this.regexChecking(args.editingText)||!this.referenceChecking(args.editingText,args.row,doc)){
  281. gljOprObj.showQuantityDetailData();
  282. return;
  283. }
  284. if(recode.hasOwnProperty('rationID')){
  285. query.rationID=recode.rationID;
  286. }else {
  287. query.billID = recode.billID
  288. }
  289. query.refreshQuantity=true;
  290. if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
  291. if(!args.replace){//为了批量粘贴时不重复提示,普通编辑时不受影响
  292. hintBox.infoBox('操作确认', '确定要使用工程量明细替换原工程量吗?', 2, function () {
  293. args.replace = true;
  294. query.index = args.row;
  295. me.updateQuantityRegex(query,doc,args,batchCallback)
  296. }, function () {
  297. me.cleanQuantityDetail(selected,true);
  298. },['确定','取消'],false);
  299. return;
  300. }
  301. }
  302. query.index = args.row;
  303. me.updateQuantityRegex(query,doc,args,batchCallback);
  304. }else {
  305. me.normalUpdate(query,doc,args,batchCallback);
  306. }
  307. };
  308. quantity_detail.prototype.updateQuantityRegex=function(query,doc,args,batchCallback){
  309. var needupdate = false;
  310. if(args.editingText==null){
  311. needupdate =true;
  312. }else {
  313. args.editingText = _.trim(args.editingText,/\r\n/);
  314. if(this.regexChecking(args.editingText)&&this.referenceChecking(args.editingText,args.row,doc)){
  315. needupdate = true;
  316. }
  317. }
  318. if(needupdate){
  319. this.commonUpdate("/quantity_detail/updateRegex",{query:query,doc:doc},args,batchCallback);
  320. }else {
  321. var sheet = subSpread.getActiveSheet();
  322. sheet.getCell(args.row,args.col).value(gljOprObj.detailData[args.row].regex);
  323. }
  324. };
  325. quantity_detail.prototype.isSummationUpdate=function (args,detailList,newval) {
  326. var query={
  327. ID:detailList[args.row].ID,
  328. projectID:detailList[args.row].projectID
  329. };
  330. var selected = projectObj.project.mainTree.selected;
  331. query.refreshQuantity=true;
  332. if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
  333. hintBox.infoBox('操作确认', '确定要使用工程量明细替换原工程量吗?', 2, function () {
  334. summationUpdate(args,detailList,newval,query);
  335. }, function () {
  336. query.refreshQuantity=false;
  337. summationUpdate(args,detailList,newval,query);
  338. },['确定','取消'],false);
  339. return;
  340. }
  341. summationUpdate(args,detailList,newval,query);
  342. function summationUpdate(args,detailList,newval,query) {
  343. if(detailList[args.row].hasOwnProperty('rationID')){
  344. query.rationID=detailList[args.row].rationID;
  345. }else {
  346. query.billID = detailList[args.row].billID
  347. }
  348. var doc={
  349. isSummation:newval
  350. };
  351. projectObj.project.quantity_detail.normalUpdate(query,doc);
  352. }
  353. };
  354. quantity_detail.prototype.commonUpdate = function (url,postData,args,batchCallback) {
  355. var me = this;
  356. $.bootstrapLoading.start();
  357. var callback = function (data) {
  358. $.bootstrapLoading.end();
  359. me.refreshAfterUpdate(data,batchCallback);
  360. if(batchCallback){
  361. batchCallback(args)
  362. }else if(data.node){
  363. me.refreshRationOrBillNodes(data.node);
  364. }
  365. }
  366. CommonAjax.post(url,postData,callback,function () {
  367. $.bootstrapLoading.end();
  368. });
  369. };
  370. quantity_detail.prototype.normalUpdate=function(query,doc,args,batchCallback){
  371. var url = "/quantity_detail/update";
  372. this.commonUpdate(url,{query:query,doc:doc},args,batchCallback);
  373. };
  374. quantity_detail.prototype.regexChecking=function(text){
  375. var regex=/^[0-9Cc\+\-\*\^/\(\)\.]*$/g;
  376. if(!regex.test(text)){
  377. alert("输入了非法字符,请重新输入!")
  378. return false;
  379. }else {
  380. return true;
  381. }
  382. };
  383. quantity_detail.prototype.referenceChecking=function (text,row,doc) {
  384. text = text.toUpperCase();
  385. //text= this.replaceSqr(text);
  386. var me = this;
  387. var refReg = /C\d+/g;
  388. var self ='C'+(row+1);
  389. var refList = text.match(refReg);
  390. var invalidate = _.includes(refList,self);
  391. var referenceIndexs = [];
  392. var indexOut = false;
  393. _.forEach(refList,function (item) {
  394. var ref_index = parseInt(item.substring(1));
  395. if(ref_index>gljOprObj.detailData.length){
  396. indexOut=true;
  397. return;
  398. }else {
  399. referenceIndexs.push(ref_index);
  400. }
  401. });
  402. if(indexOut){
  403. alert("引用有误,请重新输入!");
  404. return false;
  405. }
  406. referenceIndexs=_.uniq(referenceIndexs);
  407. doc.referenceIndexs = referenceIndexs;
  408. this.temList = referenceIndexs;
  409. invalidate=this.getAllReferenceList((row+1),referenceIndexs);
  410. if(invalidate){
  411. alert("计算式中产生了循环引用,请重新输入!");
  412. return false;
  413. }
  414. return true;
  415. };
  416. quantity_detail.prototype.getAllReferenceList=function(original,refList){
  417. var me =this;
  418. var invalidate=false;
  419. _.forEach(refList,function (item) {
  420. if(me.getReferenceList(item,original)){
  421. invalidate=true;
  422. }
  423. })
  424. return invalidate;
  425. };
  426. quantity_detail.prototype.getReferenceList=function(item,original) {
  427. var invalidate =false;
  428. if(gljOprObj.detailData.length>=item){
  429. var recode = gljOprObj.detailData[item - 1];
  430. if (recode.referenceIndexs.length > 0) {
  431. if(_.includes(recode.referenceIndexs,original)){
  432. invalidate = true;
  433. return invalidate;
  434. }
  435. this.temList = this.temList.concat(recode.referenceIndexs);
  436. _.forEach(recode.referenceIndex, function (item) {
  437. if(this.getReferenceList(item,original)){
  438. invalidate = true;
  439. }
  440. })
  441. }
  442. }
  443. return invalidate;
  444. };
  445. quantity_detail.prototype.replaceSqr = function(text) {
  446. var squarRegex = /\([^\^]+\)\^\d+/g;
  447. var sqararr = text.match(squarRegex);
  448. var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
  449. var sqararr2=text.match(squarRegex2);
  450. if(sqararr){
  451. text=converSqrByArr(sqararr,text);
  452. }
  453. if(sqararr2){
  454. text=converSqrByArr(sqararr2,text);
  455. }
  456. return text;
  457. };
  458. quantity_detail.prototype.converSqrByArr = function (sqararr,text) {
  459. var temp = text;
  460. sqararr.forEach(function (item) {
  461. var arr = item.split('\^');
  462. var y = parseInt(arr[1]);
  463. var x_arr = [];
  464. for (var i = 0; i < y; i++) {
  465. x_arr.push(arr[0]);
  466. }
  467. var temStr = x_arr.join('*');
  468. temp = temp.replace(item, temStr);
  469. });
  470. return temp;
  471. };
  472. quantity_detail.prototype.getDetailByRationID = function (rationID) {
  473. return _.filter(this.datas,{'rationID':rationID});
  474. };
  475. quantity_detail.prototype.getDetailByBillID = function (billID) {
  476. return _.filter(this.datas,{'billID':billID});
  477. };
  478. quantity_detail.prototype.addDatasToList = function (datas) {
  479. let me = projectObj.project.quantity_detail;
  480. if(datas&&datas.length>0){
  481. if (me.datas && Array.isArray(me.datas)) {
  482. me.datas = me.datas.concat(datas);
  483. } else {
  484. me.datas = datas;
  485. }
  486. }
  487. };
  488. quantity_detail.prototype.deleteByRation = function(ration){
  489. var detail_list = this.datas;
  490. _.remove(detail_list,{'rationID':ration.ID});
  491. };
  492. quantity_detail.prototype.deleteByBills=function(deleteData){
  493. var detail_list = this.datas;
  494. var billIDList = [];
  495. for(var i=0;i<deleteData.length;i++){
  496. if(deleteData[i].type=='delete'){
  497. billIDList.push(deleteData[i].data.ID);
  498. }
  499. }
  500. var newList =_.filter(detail_list,(d)=>{
  501. return !_.includes(billIDList,d.billID);
  502. });
  503. if(newList!=undefined){
  504. this.datas = newList;
  505. }
  506. };
  507. quantity_detail.prototype.cleanQuantityDetail = function (node,needSave) {
  508. node =node?node:projectObj.project.mainTree.selected;
  509. let query={projectID:node.data.projectID};
  510. if(node.sourceType === project.Bills.getSourceType()){
  511. query.billID = node.data.ID;
  512. this.deleteByBills([{type:'delete',data:node.data}]);
  513. }else if(node.sourceType === project.Ration.getSourceType()){
  514. this.deleteByRation(node.data);
  515. query.rationID = node.data.ID;
  516. }
  517. if(needSave===true){
  518. query.refreshQuantity=false;
  519. CommonAjax.post("/quantity_detail/save",query);
  520. }
  521. gljOprObj.detailData=[];
  522. sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,[]);
  523. };
  524. quantity_detail.prototype.quantityEditChecking = function(value,node,fieldName){
  525. var validate = true;
  526. if(fieldName=='quantity'){
  527. if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
  528. var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?')
  529. if(c){
  530. validate = true;
  531. }else {
  532. validate = false;
  533. }
  534. }
  535. }
  536. return validate;
  537. };
  538. quantity_detail.prototype.autoTransformQuantity = function(value,node){//根据单位转换定额工程量
  539. let data = node.data;
  540. let option = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS,'rationQuanACToRationUnit');
  541. if(node.data.quantityEXP=='GCLMXHJ'||(option==true&&node.sourceType === project.Ration.getSourceType()&&data.unit)) {//还需加入判读是否转换,如果是来自工程量明细的话,默认都进行转换
  542. let times = parseInt(data.unit);
  543. if (isNaN(times)) {
  544. times = 1
  545. }
  546. value = value / times;
  547. }
  548. let EXPString=node.data.quantityEXP+"";
  549. if(option==false&&node.sourceType === project.Ration.getSourceType()&&EXPString!='GCLMXHJ'&&EXPString.indexOf("QDL")==-1&&data.unit){//勾选不根据单位转换工程量,且定额是手输的,
  550. let times = parseInt(data.unit);
  551. if(!isNaN(times)){///如果定额单位可以做转换
  552. if(node.data.quantityEXP){
  553. if(isNum(EXPString)){//如果表达式中只是数字
  554. node.data.quantityEXP = EXPString+" * "+times;
  555. }else {//如果表达式是一个计算式,则要加一个括号
  556. node.data.quantityEXP = "("+EXPString+") * "+times;
  557. }
  558. }
  559. if(node.data.contain!=0){
  560. let billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
  561. let temValue = scMathUtil.roundForObj(value*times,getDecimal("quantity",node));
  562. billQuantity!=0?node.data.contain = scMathUtil.roundForObj(temValue/billQuantity,getDecimal("process")):'';
  563. }
  564. }
  565. }
  566. return value;
  567. };
  568. quantity_detail.prototype.reverseQuantity = function (value,node) {//根据单位反向运算出工程量
  569. let data = node.data;
  570. if(node.sourceType === project.Ration.getSourceType()&&data.unit){
  571. let times = parseInt(data.unit);
  572. if (isNaN(times)) {
  573. times = 1;
  574. }
  575. value = value * times;
  576. }
  577. return value
  578. };
  579. quantity_detail.prototype.editMainTreeNodeQuantity=function (value,node,fieldName,editingText) {
  580. var me = this;
  581. if(isNaN(value)){
  582. alert("当前输入的数据类型不正确,请重新输入。");
  583. projectObj.mainController.refreshTreeNode([node]);
  584. }else {
  585. value=value?value:0;
  586. if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
  587. hintBox.infoBox('操作确认', '已有工程量明细,是否清空明细表,采用手工输入的表达式?', 2, function () {
  588. node.data.isFromDetail=0;
  589. me.updateMainTreeNodeQuantity(value,node,editingText);
  590. }, function () {
  591. projectObj.mainController.refreshTreeNode([node]);
  592. },['确定','取消'],false);
  593. return;
  594. }
  595. me.updateMainTreeNodeQuantity(value,node,editingText);
  596. }
  597. };
  598. quantity_detail.prototype.updateMainTreeNodeQuantity = function(value,node,editingText){
  599. let me = this;
  600. project.quantity_detail.cleanQuantityDetail(node,true);
  601. if(node.sourceType === project.Bills.getSourceType()){
  602. me.updateBillQuantity(value,node,null,editingText);
  603. }else {
  604. me.updateRationQuantity(value,node,null,editingText);
  605. }
  606. };
  607. quantity_detail.prototype.updateBillQuantity=function (value,node,quantityEXP,editingText) {
  608. node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
  609. value = scMathUtil.roundForObj(value,getDecimal("quantity",node));
  610. node.data.quantity = value+"";
  611. console.log(value);
  612. let needUpdateChildren = [];//需更新的子定额
  613. let gljNodes=[];//当定额工程量改变时需刷新的子工料机
  614. if(node.children.length>0){//如果有子项
  615. for(let rationNode of node.children){
  616. let EXPString = rationNode.data.quantityEXP+"";
  617. if(EXPString.indexOf("QDL")!=-1){
  618. if(EXPString=="QDL"){//定额的工程量是直接通过清单量填进来的;
  619. let times = parseInt(rationNode.data.unit);
  620. if(isNaN(times)){
  621. times = 1;
  622. }
  623. rationNode.data.quantity = scMathUtil.roundForObj(value / times,getDecimal("quantity",rationNode));
  624. rationNode.data.contain = scMathUtil.roundForObj(rationNode.data.quantity/value,getDecimal("process"));
  625. }else {//如果定额的工程量是通过计算出来的,则应该重新计算。
  626. let tem_contain = scMathUtil.roundForObj(rationNode.data.contain,getDecimal("process"));
  627. let tem_quantity = scMathUtil.roundForObj(value*tem_contain,getDecimal("quantity",rationNode)); //this.autoTransformQuantity(tem_quantity,rationNode);
  628. rationNode.data.quantity = tem_quantity;
  629. }
  630. rationNode.changed = true;
  631. needUpdateChildren.push(rationNode);
  632. if (rationNode.children.length>0){//如果有子工料机
  633. gljNodes = gljNodes.concat(rationNode.children);
  634. }
  635. }else {
  636. let tem_contain=0;
  637. if(value&&value!=0){
  638. let children_quantity = scMathUtil.roundForObj(rationNode.data.quantity,getDecimal("quantity",rationNode));
  639. // children_quantity = scMathUtil.roundForObj(this.reverseQuantity(children_quantity,rationNode),getDecimal("quantity",rationNode)); 原先是要反算的,现在改成不用反算了
  640. tem_contain =scMathUtil.roundForObj(children_quantity/value,getDecimal("process"));
  641. }
  642. rationNode.data.contain = tem_contain;
  643. rationNode.changed = true;
  644. needUpdateChildren.push(rationNode);
  645. }
  646. }
  647. }
  648. if(needUpdateChildren.length>0){//清单下的定额工程量发生了改变
  649. node.changed = true;//本身发生了改变,需要存储。
  650. /*project.calcProgram.calcNodesAndSave(needUpdateChildren, function () {
  651. project.projectGLJ.loadData();
  652. });*/
  653. project.calcProgram.calcNodesAndSave(needUpdateChildren, function () {
  654. project.projectGLJ.calcQuantity();
  655. if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  656. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  657. if(isChange){
  658. project.calcProgram.calcNodesAndSave(rations,function () {
  659. project.projectGLJ.calcQuantity();
  660. });
  661. }
  662. });
  663. }
  664. });
  665. }else {
  666. node.changed = true;
  667. project.calcProgram.calcAndSave(node, function () {
  668. project.projectGLJ.calcQuantity();
  669. });
  670. }
  671. if(gljNodes.length>0){
  672. projectObj.mainController.refreshTreeNode(gljNodes);
  673. }
  674. gljOprObj.refreshView();
  675. };
  676. quantity_detail.prototype.updateRationQuantity=function(value,node,quantityEXP,editingText){
  677. node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
  678. value = scMathUtil.roundForObj(value,getDecimal("ration.quantity"));
  679. value = project.quantity_detail.autoTransformQuantity(value,node);
  680. value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node))
  681. node.data.quantity=value;
  682. if(node.parent.data.quantity&&node.parent.data.quantity!=0&&node.parent.data.quantity!=""){
  683. var billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
  684. node.data.contain = scMathUtil.roundForObj(value/billQuantity,getDecimal("process"));
  685. }else {
  686. node.data.contain=0;
  687. }
  688. node.changed = true;
  689. project.calcProgram.calcAndSave(node, function () {
  690. project.projectGLJ.calcQuantity();
  691. if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  692. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  693. if(isChange){
  694. project.calcProgram.calcNodesAndSave(rations);
  695. }
  696. });
  697. }
  698. });
  699. projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机总消耗量
  700. gljOprObj.refreshView();
  701. };
  702. quantity_detail.prototype.getDecimal=function (node) {
  703. var decimal = 3;
  704. if(node.sourceType === project.Bills.getSourceType()){
  705. decimal = billsQuanDecimal.decimal(node.data.unit);
  706. }else {
  707. decimal = decimalObj.ration.quantity
  708. }
  709. return decimal;
  710. };
  711. return new quantity_detail(project);
  712. }
  713. };