project_glj.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /**
  2. * 工料机汇总相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/14
  6. * @version
  7. */
  8. function ProjectGLJ() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. }
  12. /**
  13. * 加载数据
  14. *
  15. * @param {function} callback
  16. * @return {boolean}
  17. */
  18. ProjectGLJ.prototype.loadData = function (callback = null) {
  19. let self = this;
  20. if (self.isLoading) {
  21. return false;
  22. }
  23. // 加载工料机数据
  24. $.ajax({
  25. url: '/glj/getData',
  26. type: 'post',
  27. dataType: 'json',
  28. data: {project_id: scUrlUtil.GetQueryString('project')},
  29. error: function () {
  30. // alert('数据传输错误');
  31. },
  32. beforeSend: function () {
  33. self.isLoading = true;
  34. },
  35. success: function (response) {
  36. self.isLoading = false;
  37. if (response.err === 1) {
  38. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  39. alert(msg);
  40. return false;
  41. }
  42. self.datas = response.data;
  43. self.calcQuantity();
  44. // 回调函数
  45. if (callback !== null) {
  46. callback(response.data);
  47. }
  48. // 存入缓存
  49. projectObj.project.projectGLJ = self;
  50. }
  51. });
  52. };
  53. ProjectGLJ.prototype.loadToCache = function (data) {
  54. this.datas = data;
  55. projectObj.project.projectGLJ = this;
  56. }
  57. /**
  58. * 获取对应工料机数据
  59. *
  60. * @param {String} code
  61. * @return {Object}
  62. */
  63. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  64. return _.find(this.datas.gljList, {'id': ID});
  65. };
  66. // CSL, 2018-02-08 甲供、甲定。
  67. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  68. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  69. // 所以这里要合并处理。
  70. let mixSupply = [];
  71. for (let s of supplyTypeArr){
  72. switch (s) {
  73. case 1:
  74. mixSupply.push('部分甲供');
  75. break;
  76. case 2:
  77. mixSupply.push('完全甲供');
  78. break;
  79. case 3:
  80. mixSupply.push('甲定乙供');
  81. break;
  82. default:
  83. mixSupply.push('自行采购');
  84. }
  85. };
  86. mixSupply = mixSupply.concat(supplyTypeArr);
  87. return _.filter(this.datas.gljList, function (glj) {
  88. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  89. });
  90. };
  91. ProjectGLJ.prototype.testGLJs = function () {
  92. let gljs = [];
  93. for (let glj of this.datas.gljList){
  94. let o = new Object();
  95. o.name = glj.name;
  96. o.supply = glj.supply;
  97. gljs.push(o);
  98. };
  99. return gljs;
  100. };
  101. /**
  102. * 修改工料机数据
  103. *
  104. * @param {Number} id
  105. * @param {Object} data
  106. * @return {boolean}
  107. */
  108. ProjectGLJ.prototype.updateData = function (id, data) {
  109. let result = false;
  110. if (this.datas === null) {
  111. return result;
  112. }
  113. let gljList = this.datas.gljList;
  114. if (gljList === undefined) {
  115. return result;
  116. }
  117. // 查找对应的index
  118. let index = -1;
  119. for (let tmp in gljList) {
  120. if (gljList[tmp].id === id) {
  121. index = tmp;
  122. break;
  123. }
  124. }
  125. if (index < 0) {
  126. return result;
  127. }
  128. // 修改数据
  129. for (let tmpIndex in data) {
  130. if (tmpIndex.indexOf('_price') >= 0) {
  131. // 修改unit_price中的对象
  132. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  133. } else {
  134. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  135. }
  136. }
  137. };
  138. /**
  139. * 加载缓存数据到spread
  140. *
  141. * @return {void}
  142. */
  143. ProjectGLJ.prototype.loadCacheData = function (resort) {
  144. // 加载工料机数据
  145. let data = this.datas === null ? null : this.datas;
  146. if (data === null) {
  147. return;
  148. }
  149. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  150. console.log("filter start");
  151. jsonData = filterProjectGLJ(jsonData);
  152. console.log("filter end");
  153. jsonData = sortProjectGLJ(jsonData);
  154. console.log("sort end");
  155. if(projectGLJSheet&&projectGLJSpread){
  156. setTimeout(spreadInit, 1);
  157. /*projectGLJSheet.setData(jsonData);
  158. projectGLJSpread.specialColumn(jsonData);*/
  159. }
  160. };
  161. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval) {
  162. if (updateField == 'marketPrice') {
  163. this.updatePrice(recode, "market_price", newval,"rg");
  164. }
  165. if (updateField == 'basePrice') {
  166. this.updatePrice(recode, "base_price", newval,"rg");
  167. }
  168. };
  169. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval) {
  170. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  171. projectObj.project.Ration.updateContain(newval,node);
  172. }if(updateField == "quantity"){
  173. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField);
  174. } else {
  175. this.updateGLJProperty(node, updateField, newval);
  176. }
  177. };
  178. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  179. let rationTypeGLJ = node.data;
  180. let postData = {};
  181. if (rationTypeGLJ[updateField] == newval) {
  182. return;
  183. }
  184. let data = {
  185. glj_id: rationTypeGLJ.GLJID,
  186. project_id: rationTypeGLJ.projectID,
  187. code: rationTypeGLJ.code,
  188. original_code: rationTypeGLJ.original_code,
  189. name: rationTypeGLJ.name,
  190. shortName: rationTypeGLJ.shortName,
  191. specs: rationTypeGLJ.specs,
  192. unit: rationTypeGLJ.unit,
  193. type: rationTypeGLJ.subType,
  194. type_of_work: rationTypeGLJ.subType,
  195. base_price: rationTypeGLJ.basePrice,
  196. market_price: rationTypeGLJ.basePrice,
  197. repositoryId: rationTypeGLJ.repositoryId,
  198. adjCoe: rationTypeGLJ.adjCoe,
  199. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  200. };
  201. if (updateField == 'subType') {
  202. data.type = newval;
  203. data.type_of_work = newval;
  204. data.shortName = this.getShortNameByID(newval);
  205. } else {
  206. data[updateField] = newval;
  207. }
  208. postData.ration = {
  209. ID: rationTypeGLJ.ID,
  210. projectID: rationTypeGLJ.projectID
  211. };
  212. postData.updateData = data;
  213. $.bootstrapLoading.start();
  214. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  215. console.log(result); //更新节点信息
  216. rationTypeGLJ[updateField] = newval;
  217. rationTypeGLJ.projectGLJID = result.id;
  218. rationTypeGLJ.code = result.code;
  219. rationTypeGLJ.basePrice = result.unit_price.base_price;
  220. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  221. rationTypeGLJ.isAdd = result.unit_price.is_add;
  222. rationTypeGLJ.isEstimate = result.is_evaluate;
  223. rationTypeGLJ.shortName = result.unit_price.short_name;
  224. //触发计算并更新节点信息
  225. node.changed = true;
  226. projectObj.project.projectGLJ.loadData(function () {
  227. projectObj.project.calcProgram.calcAndSave(node);
  228. $.bootstrapLoading.end();
  229. });//重新加载项目工料机数据
  230. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  231. }, function (err) {
  232. $.bootstrapLoading.end();
  233. });
  234. }
  235. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  236. let me = this;
  237. let projectGljs = this.datas.gljList;
  238. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  239. let glj = _.find(projectGljs, {'id': pgljID});
  240. if (glj) {
  241. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id};
  242. let callback = function (data) {
  243. if (updateField == 'base_price') {
  244. glj.unit_price.base_price = newval;
  245. me.setAdjustPrice(glj);
  246. } else {
  247. glj.unit_price.market_price = newval;
  248. }
  249. //更新回传的父节点项目工料机价格
  250. let gljs = me.getProjectGLJs(data);
  251. me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  252. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  253. gljOprObj.showRationGLJSheetData();
  254. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  255. gljs.push(glj);
  256. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  257. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  258. socket.emit('unitFileChangeNotify', JSON.stringify(data));
  259. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  260. if(cb){
  261. cb(gljs);
  262. }
  263. $.bootstrapLoading.end();
  264. }
  265. $.bootstrapLoading.start();
  266. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  267. $.bootstrapLoading.end();
  268. });
  269. } else {
  270. gljOprObj.showRationGLJSheetData();
  271. }
  272. };
  273. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  274. let me = this;
  275. $.bootstrapLoading.start();
  276. CommonAjax.specialPost( '/glj/update',data,function (result) {
  277. let glj = me.getByID(data.id);//更新缓存
  278. let impactList = [];
  279. glj[data.field] = data.value;
  280. if(data.extend&&data.extend!=""){
  281. let extend = JSON.parse(data.extend);
  282. for (let key in extend) {
  283. glj[key] = extend[key];
  284. }
  285. }
  286. if(data.field == 'is_evaluate'){
  287. impactList = me.changeIsEvaluate(data.id);
  288. }
  289. if(callback){
  290. callback(impactList);
  291. }
  292. $.bootstrapLoading.end();
  293. });
  294. };
  295. //更新是否暂估
  296. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  297. let projectGLJ = projectObj.project.projectGLJ;
  298. let datas = projectGLJ.datas;
  299. let gljList = datas.gljList;
  300. let glj = _.find(gljList, {'id': id});
  301. if(glj){
  302. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  303. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  304. let conditions = [];
  305. if(pratioM&&pratioM.length>0){
  306. for(let p_key of pratioM ){
  307. conditions.push(gljOprObj.getConditionByKey(p_key));
  308. }
  309. }
  310. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  311. gljs.push(glj);
  312. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  313. //更新对应的工料机类型的定额
  314. let ration =_.find(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  315. if(ration){
  316. ration.isEstimate =glj.is_evaluate?1:0;
  317. let ration_node = projectObj.project.mainTree.getNodeByID(ration.ID);
  318. ration_node?projectObj.mainController.refreshTreeNode([ration_node]):"";
  319. }
  320. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  321. return gljs;
  322. }
  323. }
  324. ProjectGLJ.prototype.getByID = function (ID) {
  325. return _.find(this.datas.gljList,{'id':ID});
  326. };
  327. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  328. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  329. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  330. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  331. tem.data.marketUnitFee = data.unit_price.market_price;
  332. return true;
  333. }
  334. })
  335. projectObj.mainController.refreshTreeNode(nodes);
  336. }
  337. }
  338. //根据工料机,取得所有受影响的定额节点
  339. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  340. let nodes = [];
  341. let rationMap = {};
  342. let idArray = _.map(gljs,'id');
  343. let priceArray = _.map(gljs,'unit_price');
  344. //先根据项目工料机ID,找到受影响定额的ID
  345. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  346. for (let rg of ration_glj_list) {
  347. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  348. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  349. }
  350. }
  351. for (let item of projectObj.project.mainTree.items) {
  352. if (item.sourceType == ModuleNames.ration) {
  353. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  354. let idx = _.indexOf(idArray,item.data.projectGLJID);
  355. if (idx != -1) {
  356. item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价
  357. nodes.push(item);
  358. }
  359. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  360. nodes.push(item)
  361. }
  362. }
  363. }
  364. return nodes;
  365. };
  366. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  367. for (let ration_glj of gljOprObj.sheetData) {
  368. if (ration_glj.projectGLJID == glj.id) {
  369. ration_glj.basePrice = glj.unit_price.base_price;
  370. ration_glj.marketPrice = glj.unit_price.market_price;
  371. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  372. }
  373. }
  374. }
  375. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  376. }
  377. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  378. let parentGlj = [];
  379. //
  380. let projectGljs = this.datas.gljList;
  381. let indexList = gljKeyArray;
  382. for (let d of data) {
  383. if (d) {
  384. let condition = {};
  385. for (let index of indexList) {
  386. if (d[index] != null && d[index] != undefined && d[index] != '') {
  387. condition[index] = d[index]
  388. }
  389. }
  390. let glj = _.find(projectGljs, condition);
  391. if (glj) {
  392. if(refreshPrice==true){
  393. glj.unit_price.base_price = d.base_price;
  394. glj.unit_price.market_price = d.market_price;
  395. this.setAdjustPrice(glj);
  396. this.refreshRationGLJPrice(glj);
  397. this.refreshTreeNodePriceIfNeed(glj);
  398. }
  399. parentGlj.push(glj);
  400. }
  401. }
  402. }
  403. return parentGlj;
  404. }
  405. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  406. switch (glj.unit_price.type + '') {
  407. // 人工: 调整基价=基价单价*调整系数
  408. case GLJTypeConst.LABOUR:
  409. case GLJTypeConst.MACHINE_LABOUR:
  410. glj.adjust_price = this.getAdjustPrice(glj);
  411. break;
  412. // 机械类型的算法
  413. case GLJTypeConst.MACHINE:
  414. console.log('机械');
  415. break;
  416. // 材料、主材、设备
  417. default:
  418. glj.adjust_price = glj.unit_price.base_price;
  419. }
  420. }
  421. ProjectGLJ.prototype.getAdjustPrice = function (glj) {
  422. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  423. let decimal = getDecimal("glj.unitPrice");
  424. let quantity_decimal = getDecimal("glj.quantity");
  425. if (glj.unit_price.type == GLJTypeConst.LABOUR || glj.unit_price.type == GLJTypeConst.MACHINE_LABOUR) {//人工、机上人工,调整价根据定额价*调整系数计算得出。
  426. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  427. //let labour=1;
  428. let coe = labour && labour.coe ? labour.coe : 1;
  429. return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price,decimal)), -decimal);
  430. } else if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
  431. let p =0;
  432. for(let ratio of glj.ratio_data){
  433. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  434. 'code': ratio.code,
  435. 'name': ratio.name,
  436. 'specs':ratio.specs,
  437. 'type': ratio.type,
  438. 'unit': ratio.unit
  439. })
  440. if(tem){
  441. let priceData={};
  442. gljOprObj.setGLJPrice(priceData,tem);
  443. p+=scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),decimal);
  444. }
  445. }
  446. return scMathUtil.roundForObj(p,decimal);
  447. } else {//对于其他普通材料等,无调整系数,调整价=定额价。
  448. return glj.unit_price.base_price
  449. }
  450. };
  451. ProjectGLJ.prototype.getBasePrice = function(glj){
  452. let price_decimal = getDecimal("glj.unitPrice");
  453. let quantity_decimal = getDecimal("glj.quantity");
  454. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  455. let p =0;
  456. for(let ratio of glj.ratio_data){
  457. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  458. 'code': ratio.code,
  459. 'name': ratio.name,
  460. 'specs':ratio.specs,
  461. 'type': ratio.type,
  462. 'unit': ratio.unit
  463. });
  464. if(tem){
  465. let priceData={};
  466. gljOprObj.setGLJPrice(priceData,tem);
  467. p+=scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),price_decimal);
  468. }
  469. }
  470. return scMathUtil.roundForObj(p,price_decimal);
  471. }else {
  472. return scMathUtil.roundForObj(glj.unit_price.base_price,price_decimal);
  473. }
  474. };
  475. ProjectGLJ.prototype.getMarketPrice = function (glj) {
  476. let price_decimal = getDecimal("glj.unitPrice");
  477. let quantity_decimal = getDecimal("glj.quantity");
  478. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  479. let p =0;
  480. for(let ratio of glj.ratio_data){
  481. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  482. 'code': ratio.code,
  483. 'name': ratio.name,
  484. 'specs':ratio.specs,
  485. 'type': ratio.type,
  486. 'unit': ratio.unit
  487. });
  488. if(tem){
  489. let priceData={};
  490. gljOprObj.setGLJPrice(priceData,tem);
  491. p+=scMathUtil.roundForObj(priceData.marketPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),price_decimal);
  492. }
  493. }
  494. return scMathUtil.roundForObj(p,price_decimal);
  495. }else {
  496. return scMathUtil.roundForObj(glj.unit_price.market_price,price_decimal);
  497. }
  498. }
  499. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  500. let gljTypeMap = this.datas.constData.gljTypeMap;
  501. return gljTypeMap["typeId" + ID].shortName;
  502. };
  503. ProjectGLJ.prototype.calcQuantity = function (){
  504. let project_gljs = this.datas.gljList;
  505. let mixRatioConnectData = this.datas.mixRatioConnectData;
  506. let mixRatioSubdivisionMap = {};
  507. let mixRatioTechMap={};
  508. for(let pglj of project_gljs ){
  509. if(pglj.quantity !== 0 && pglj.quantity !== '0'){
  510. let result = this.getQuantityPerGLJ(pglj,mixRatioSubdivisionMap,mixRatioTechMap);
  511. pglj.subdivisionQuantity = result.subdivisionQuantity;
  512. pglj.techQuantity = result.techQuantity;
  513. }
  514. }
  515. //计算做为组成物的消耗量
  516. for(let pg of project_gljs ){
  517. if(pg.quantity !== 0 && pg.quantity !== '0'){
  518. let pg_index = gljOprObj.getIndex(pg,gljKeyArray);
  519. if(mixRatioConnectData[pg_index]){
  520. if(mixRatioSubdivisionMap[pg_index]){
  521. pg.subdivisionQuantity = scMathUtil.roundForObj(mixRatioSubdivisionMap[pg_index]+pg.subdivisionQuantity,getDecimal("glj.quantity"));
  522. }
  523. if(mixRatioTechMap[pg_index]){
  524. pg.techQuantity = scMathUtil.roundForObj(mixRatioTechMap[pg_index]+pg.techQuantity,getDecimal("glj.quantity"));
  525. }
  526. }
  527. }
  528. }
  529. }
  530. ProjectGLJ.prototype.getQuantityPerGLJ = function (pglj,mixRatioSubdivisionMap,mixRatioTechMap) {
  531. let billIDs = projectObj.project.Bills.getSubdivisionProjectLeavesID();//取分部分项上的所有叶子清单ID
  532. let tech_billIDS = projectObj.project.Bills.getTechLeavesID();//取所有技术措施项目叶子清单ID
  533. let ration_glj_list = projectObj.project.ration_glj.datas;
  534. let mixRatioMap = this.datas.mixRatioMap;
  535. let rations = projectObj.project.Ration.datas;
  536. let q_decimal = getDecimal("glj.quantity");
  537. let result={};
  538. let sum = 0;
  539. let tech_sum = 0;
  540. for(let rg of ration_glj_list){
  541. if(rg.projectGLJID==pglj.id){
  542. if(_.includes(billIDs,rg.billsItemID)){//计算分部分项
  543. let total = calcQuantity(rg,mixRatioSubdivisionMap);
  544. sum = scMathUtil.roundForObj(sum+total,q_decimal);
  545. }
  546. if(_.includes(tech_billIDS,rg.billsItemID)){//计算技术措施项目消耗量
  547. let tech_total = calcQuantity(rg,mixRatioTechMap);
  548. tech_sum = scMathUtil.roundForObj(tech_sum+tech_total,q_decimal);
  549. }
  550. }
  551. }
  552. for(let ra of rations){//计算定额类型工料机的消耗量
  553. if(ra.type == rationType.gljRation&&ra.projectGLJID===pglj.id){
  554. let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
  555. r_quantity = r_quantity?r_quantity:0;
  556. if(_.includes(billIDs,ra.billsItemID)){//计算分部分项
  557. sum = scMathUtil.roundForObj(sum+r_quantity,q_decimal);
  558. }
  559. if(_.includes(tech_billIDS,ra.billsItemID)){//计算技术措施项目消耗量
  560. tech_sum = scMathUtil.roundForObj(tech_sum+r_quantity,q_decimal);
  561. }
  562. }
  563. }
  564. result.subdivisionQuantity = sum;
  565. result.techQuantity = tech_sum;
  566. return result;
  567. function calcQuantity(rg,quantityMap) { //计算工料机在所属定额下的总消耗量
  568. let tem_ration = _.find(rations,{"ID":rg.rationID});
  569. let total = parseFloat(gljOprObj.getTotalQuantity(rg,tem_ration));
  570. let r_index = gljOprObj.getIndex(rg,gljKeyArray);
  571. if(mixRatioMap.hasOwnProperty(r_index)){
  572. let mixRatioList = mixRatioMap[r_index];
  573. for(let m of mixRatioList){
  574. let m_index = gljOprObj.getIndex(m,gljKeyArray);
  575. let m_quantity = scMathUtil.roundForObj(total*m.consumption,q_decimal);
  576. if(quantityMap[m_index]){
  577. quantityMap[m_index] = scMathUtil.roundForObj(quantityMap[m_index]+m_quantity,q_decimal);
  578. }else {
  579. quantityMap[m_index] = m_quantity;
  580. }
  581. }
  582. }
  583. return total;
  584. }
  585. }