quantity_detail.js 32 KB

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