project_glj.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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. o.quantity = glj.quantity;
  98. o.supply_quantity = glj.supply_quantity;
  99. gljs.push(o);
  100. };
  101. return gljs;
  102. };
  103. /**
  104. * 修改工料机数据
  105. *
  106. * @param {Number} id
  107. * @param {Object} data
  108. * @return {boolean}
  109. */
  110. ProjectGLJ.prototype.updateData = function (id, data) {
  111. let result = false;
  112. if (this.datas === null) {
  113. return result;
  114. }
  115. let gljList = this.datas.gljList;
  116. if (gljList === undefined) {
  117. return result;
  118. }
  119. // 查找对应的index
  120. let index = -1;
  121. for (let tmp in gljList) {
  122. if (gljList[tmp].id === id) {
  123. index = tmp;
  124. break;
  125. }
  126. }
  127. if (index < 0) {
  128. return result;
  129. }
  130. // 修改数据
  131. for (let tmpIndex in data) {
  132. if (tmpIndex.indexOf('_price') >= 0) {
  133. // 修改unit_price中的对象
  134. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  135. } else {
  136. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  137. }
  138. }
  139. };
  140. /**
  141. * 加载缓存数据到spread
  142. *
  143. * @return {void}
  144. */
  145. ProjectGLJ.prototype.loadCacheData = function (resort) {
  146. // 加载工料机数据
  147. let data = this.datas === null ? null : this.datas;
  148. if (data === null) {
  149. return;
  150. }
  151. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  152. console.log("filter start");
  153. jsonData = filterProjectGLJ(jsonData);
  154. console.log("filter end");
  155. jsonData = sortProjectGLJ(jsonData);
  156. console.log("sort end");
  157. if(projectGLJSheet&&projectGLJSpread){
  158. setTimeout(spreadInit, 1);
  159. /*projectGLJSheet.setData(jsonData);
  160. projectGLJSpread.specialColumn(jsonData);*/
  161. }
  162. };
  163. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval) {
  164. if (updateField == 'marketPrice') {
  165. this.updatePrice(recode, "market_price", newval,"rg");
  166. }
  167. if (updateField == 'basePrice') {
  168. this.updatePrice(recode, "base_price", newval,"rg");
  169. }
  170. };
  171. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval) {
  172. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  173. projectObj.project.Ration.updateContain(newval,node);
  174. }if(updateField == "quantity"){
  175. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField);
  176. } else {
  177. this.updateGLJProperty(node, updateField, newval);
  178. }
  179. };
  180. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  181. let rationTypeGLJ = node.data;
  182. let postData = {};
  183. if (rationTypeGLJ[updateField] == newval) {
  184. return;
  185. }
  186. let data = {
  187. glj_id: rationTypeGLJ.GLJID,
  188. project_id: rationTypeGLJ.projectID,
  189. code: rationTypeGLJ.code,
  190. original_code: rationTypeGLJ.original_code,
  191. name: rationTypeGLJ.name,
  192. shortName: rationTypeGLJ.shortName,
  193. specs: rationTypeGLJ.specs,
  194. unit: rationTypeGLJ.unit,
  195. type: rationTypeGLJ.subType,
  196. type_of_work: rationTypeGLJ.subType,
  197. base_price: rationTypeGLJ.basePrice,
  198. market_price: rationTypeGLJ.basePrice,
  199. repositoryId: rationTypeGLJ.repositoryId,
  200. adjCoe: rationTypeGLJ.adjCoe,
  201. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  202. };
  203. if (updateField == 'subType') {
  204. data.type = newval;
  205. data.type_of_work = newval;
  206. data.shortName = this.getShortNameByID(newval);
  207. } else {
  208. data[updateField] = newval;
  209. }
  210. postData.ration = {
  211. ID: rationTypeGLJ.ID,
  212. projectID: rationTypeGLJ.projectID
  213. };
  214. postData.updateData = data;
  215. $.bootstrapLoading.start();
  216. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  217. console.log(result); //更新节点信息
  218. rationTypeGLJ[updateField] = newval;
  219. rationTypeGLJ.projectGLJID = result.id;
  220. rationTypeGLJ.code = result.code;
  221. rationTypeGLJ.basePrice = result.unit_price.base_price;
  222. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  223. rationTypeGLJ.isAdd = result.unit_price.is_add;
  224. rationTypeGLJ.isEstimate = result.is_evaluate;
  225. rationTypeGLJ.shortName = result.unit_price.short_name;
  226. //触发计算并更新节点信息
  227. node.changed = true;
  228. projectObj.project.projectGLJ.loadData(function () {
  229. projectObj.project.calcProgram.calcAndSave(node);
  230. $.bootstrapLoading.end();
  231. });//重新加载项目工料机数据
  232. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  233. }, function (err) {
  234. $.bootstrapLoading.end();
  235. });
  236. }
  237. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  238. let me = this;
  239. let projectGljs = this.datas.gljList;
  240. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  241. let glj = _.find(projectGljs, {'id': pgljID});
  242. if (glj) {
  243. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id};
  244. let callback = function (data) {
  245. if (updateField == 'base_price') {
  246. glj.unit_price.base_price = newval;
  247. me.setAdjustPrice(glj);
  248. } else {
  249. glj.unit_price.market_price = newval;
  250. }
  251. //更新回传的父节点项目工料机价格
  252. let gljs = me.getProjectGLJs(data);
  253. me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  254. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  255. gljOprObj.showRationGLJSheetData();
  256. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  257. gljs.push(glj);
  258. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  259. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  260. socket.emit('unitFileChangeNotify', JSON.stringify(data));
  261. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  262. if(cb){
  263. cb(gljs);
  264. }
  265. $.bootstrapLoading.end();
  266. }
  267. $.bootstrapLoading.start();
  268. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  269. $.bootstrapLoading.end();
  270. });
  271. } else {
  272. gljOprObj.showRationGLJSheetData();
  273. }
  274. };
  275. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  276. let me = this;
  277. $.bootstrapLoading.start();
  278. CommonAjax.specialPost( '/glj/update',data,function (result) {
  279. let glj = me.getByID(data.id);//更新缓存
  280. let impactList = [];
  281. glj[data.field] = data.value;
  282. if(data.extend&&data.extend!=""){
  283. let extend = JSON.parse(data.extend);
  284. for (let key in extend) {
  285. glj[key] = extend[key];
  286. }
  287. }
  288. if(data.field == 'is_evaluate'){
  289. impactList = me.changeIsEvaluate(data.id);
  290. }
  291. if(callback){
  292. callback(impactList);
  293. }
  294. $.bootstrapLoading.end();
  295. });
  296. };
  297. ProjectGLJ.prototype.getRatioData=function(id,callback){
  298. if(id){
  299. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  300. let ratios = JSON.parse(response.data);
  301. if(callback){
  302. callback(ratios);
  303. }
  304. },function () {//取不到组成物的情况
  305. callback([]);
  306. })
  307. }else {
  308. if(callback){
  309. callback([]);
  310. }
  311. }
  312. };
  313. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  314. $.bootstrapLoading.start();
  315. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  316. projectObj.project.projectGLJ.loadData(function () {
  317. if(callback){
  318. callback();
  319. }
  320. $.bootstrapLoading.end();
  321. });
  322. });
  323. };
  324. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  325. $.bootstrapLoading.start();
  326. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  327. projectObj.project.projectGLJ.loadData(function () {
  328. if(callback){
  329. callback();
  330. }
  331. $.bootstrapLoading.end();
  332. });
  333. },function (response) {
  334. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  335. $("#save-as-tips").text(msg).show();
  336. $.bootstrapLoading.end();
  337. });
  338. };
  339. //更新是否暂估
  340. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  341. let projectGLJ = projectObj.project.projectGLJ;
  342. let datas = projectGLJ.datas;
  343. let gljList = datas.gljList;
  344. let glj = _.find(gljList, {'id': id});
  345. if(glj){
  346. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  347. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  348. let conditions = [];
  349. if(pratioM&&pratioM.length>0){
  350. for(let p_key of pratioM ){
  351. conditions.push(gljOprObj.getConditionByKey(p_key));
  352. }
  353. }
  354. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  355. gljs.push(glj);
  356. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  357. //更新对应的工料机类型的定额
  358. let ration =_.find(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  359. if(ration){
  360. ration.isEstimate =glj.is_evaluate?1:0;
  361. let ration_node = projectObj.project.mainTree.getNodeByID(ration.ID);
  362. ration_node?projectObj.mainController.refreshTreeNode([ration_node]):"";
  363. }
  364. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  365. return gljs;
  366. }
  367. }
  368. ProjectGLJ.prototype.getByID = function (ID) {
  369. return _.find(this.datas.gljList,{'id':ID});
  370. };
  371. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  372. return _.find(this.datas.gljList,function (item) {
  373. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  374. return tem_key == conkey
  375. })
  376. };
  377. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  378. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  379. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  380. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  381. tem.data.marketUnitFee = data.unit_price.market_price;
  382. return true;
  383. }
  384. })
  385. projectObj.mainController.refreshTreeNode(nodes);
  386. }
  387. }
  388. //根据工料机,取得所有受影响的定额节点
  389. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  390. let nodes = [];
  391. let rationMap = {};
  392. let idArray = _.map(gljs,'id');
  393. let priceArray = _.map(gljs,'unit_price');
  394. //先根据项目工料机ID,找到受影响定额的ID
  395. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  396. for (let rg of ration_glj_list) {
  397. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  398. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  399. }
  400. }
  401. for (let item of projectObj.project.mainTree.items) {
  402. if (item.sourceType == ModuleNames.ration) {
  403. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  404. let idx = _.indexOf(idArray,item.data.projectGLJID);
  405. if (idx != -1) {
  406. item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价
  407. nodes.push(item);
  408. }
  409. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  410. nodes.push(item)
  411. }
  412. }
  413. }
  414. return nodes;
  415. };
  416. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  417. for (let ration_glj of gljOprObj.sheetData) {
  418. if (ration_glj.projectGLJID == glj.id) {
  419. ration_glj.basePrice = glj.unit_price.base_price;
  420. ration_glj.marketPrice = glj.unit_price.market_price;
  421. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  422. }
  423. }
  424. }
  425. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  426. }
  427. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  428. let parentGlj = [];
  429. //
  430. let projectGljs = this.datas.gljList;
  431. let indexList = gljKeyArray;
  432. for (let d of data) {
  433. if (d) {
  434. let condition = {};
  435. for (let index of indexList) {
  436. if (d[index] != null && d[index] != undefined && d[index] != '') {
  437. condition[index] = d[index]
  438. }
  439. }
  440. let glj = _.find(projectGljs, condition);
  441. if (glj) {
  442. if(refreshPrice==true){
  443. glj.unit_price.base_price = d.base_price;
  444. glj.unit_price.market_price = d.market_price;
  445. this.setAdjustPrice(glj);
  446. this.refreshRationGLJPrice(glj);
  447. this.refreshTreeNodePriceIfNeed(glj);
  448. }
  449. parentGlj.push(glj);
  450. }
  451. }
  452. }
  453. return parentGlj;
  454. }
  455. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  456. switch (glj.unit_price.type + '') {
  457. // 人工: 调整基价=基价单价*调整系数
  458. case GLJTypeConst.LABOUR:
  459. case GLJTypeConst.MACHINE_LABOUR:
  460. glj.adjust_price = this.getAdjustPrice(glj);
  461. break;
  462. // 机械类型的算法
  463. case GLJTypeConst.MACHINE:
  464. console.log('机械');
  465. break;
  466. // 材料、主材、设备
  467. default:
  468. glj.adjust_price = glj.unit_price.base_price;
  469. }
  470. }
  471. ProjectGLJ.prototype.getAdjustPrice = function (glj) {
  472. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  473. let decimal = getDecimal("glj.unitPrice");
  474. let quantity_decimal = getDecimal("glj.quantity");
  475. if (glj.unit_price.type == GLJTypeConst.LABOUR || glj.unit_price.type == GLJTypeConst.MACHINE_LABOUR) {//人工、机上人工,调整价根据定额价*调整系数计算得出。
  476. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  477. //let labour=1;
  478. let coe = labour && labour.coe ? labour.coe : 1;
  479. return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price,decimal)), -decimal);
  480. } else if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
  481. let p =0;
  482. for(let ratio of glj.ratio_data){
  483. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  484. 'code': ratio.code,
  485. 'name': ratio.name,
  486. 'specs':ratio.specs,
  487. 'type': ratio.type,
  488. 'unit': ratio.unit
  489. })
  490. if(tem){
  491. let priceData={};
  492. gljOprObj.setGLJPrice(priceData,tem);
  493. p+=scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),decimal);
  494. }
  495. }
  496. return scMathUtil.roundForObj(p,decimal);
  497. } else {//对于其他普通材料等,无调整系数,调整价=定额价。
  498. return glj.unit_price.base_price
  499. }
  500. };
  501. ProjectGLJ.prototype.getBasePrice = function(glj){
  502. let price_decimal = getDecimal("glj.unitPrice");
  503. let quantity_decimal = getDecimal("glj.quantity");
  504. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  505. let p =0;
  506. for(let ratio of glj.ratio_data){
  507. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  508. 'code': ratio.code,
  509. 'name': ratio.name,
  510. 'specs':ratio.specs,
  511. 'type': ratio.type,
  512. 'unit': ratio.unit
  513. });
  514. if(tem){
  515. let priceData={};
  516. gljOprObj.setGLJPrice(priceData,tem);
  517. p+=scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),price_decimal);
  518. }
  519. }
  520. return scMathUtil.roundForObj(p,price_decimal);
  521. }else {
  522. return scMathUtil.roundForObj(glj.unit_price.base_price,price_decimal);
  523. }
  524. };
  525. ProjectGLJ.prototype.getMarketPrice = function (glj) {
  526. let price_decimal = getDecimal("glj.unitPrice");
  527. let quantity_decimal = getDecimal("glj.quantity");
  528. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  529. let p =0;
  530. for(let ratio of glj.ratio_data){
  531. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  532. 'code': ratio.code,
  533. 'name': ratio.name,
  534. 'specs':ratio.specs,
  535. 'type': ratio.type,
  536. 'unit': ratio.unit
  537. });
  538. if(tem){
  539. let priceData={};
  540. gljOprObj.setGLJPrice(priceData,tem);
  541. p+=scMathUtil.roundForObj(priceData.marketPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),price_decimal);
  542. }
  543. }
  544. return scMathUtil.roundForObj(p,price_decimal);
  545. }else {
  546. return scMathUtil.roundForObj(glj.unit_price.market_price,price_decimal);
  547. }
  548. }
  549. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  550. let gljTypeMap = this.datas.constData.gljTypeMap;
  551. return gljTypeMap["typeId" + ID].shortName;
  552. };
  553. ProjectGLJ.prototype.calcQuantity = function (){
  554. let project_gljs = this.datas.gljList;
  555. let mixRatioConnectData = this.datas.mixRatioConnectData;
  556. let mixRatioSubdivisionMap = {};
  557. let mixRatioTechMap={};
  558. for(let pglj of project_gljs ){
  559. if(pglj.quantity !== 0 && pglj.quantity !== '0'){
  560. let result = this.getQuantityPerGLJ(pglj,mixRatioSubdivisionMap,mixRatioTechMap);
  561. pglj.subdivisionQuantity = result.subdivisionQuantity;
  562. pglj.techQuantity = result.techQuantity;
  563. }
  564. }
  565. //计算做为组成物的消耗量
  566. for(let pg of project_gljs ){
  567. if(pg.quantity !== 0 && pg.quantity !== '0'){
  568. let pg_index = gljOprObj.getIndex(pg,gljKeyArray);
  569. if(mixRatioConnectData[pg_index]){
  570. if(mixRatioSubdivisionMap[pg_index]){
  571. pg.subdivisionQuantity = scMathUtil.roundForObj(mixRatioSubdivisionMap[pg_index]+pg.subdivisionQuantity,getDecimal("glj.quantity"));
  572. }
  573. if(mixRatioTechMap[pg_index]){
  574. pg.techQuantity = scMathUtil.roundForObj(mixRatioTechMap[pg_index]+pg.techQuantity,getDecimal("glj.quantity"));
  575. }
  576. }
  577. }
  578. }
  579. }
  580. ProjectGLJ.prototype.getQuantityPerGLJ = function (pglj,mixRatioSubdivisionMap,mixRatioTechMap) {
  581. let billIDs = projectObj.project.Bills.getSubdivisionProjectLeavesID();//取分部分项上的所有叶子清单ID
  582. let tech_billIDS = projectObj.project.Bills.getTechLeavesID();//取所有技术措施项目叶子清单ID
  583. let ration_glj_list = projectObj.project.ration_glj.datas;
  584. let mixRatioMap = this.datas.mixRatioMap;
  585. let rations = projectObj.project.Ration.datas;
  586. let q_decimal = getDecimal("glj.quantity");
  587. let result={};
  588. let sum = 0;
  589. let tech_sum = 0;
  590. for(let rg of ration_glj_list){
  591. if(rg.projectGLJID==pglj.id){
  592. if(_.includes(billIDs,rg.billsItemID)){//计算分部分项
  593. let total = calcQuantity(rg,mixRatioSubdivisionMap);
  594. sum = scMathUtil.roundForObj(sum+total,q_decimal);
  595. }
  596. if(_.includes(tech_billIDS,rg.billsItemID)){//计算技术措施项目消耗量
  597. let tech_total = calcQuantity(rg,mixRatioTechMap);
  598. tech_sum = scMathUtil.roundForObj(tech_sum+tech_total,q_decimal);
  599. }
  600. }
  601. }
  602. for(let ra of rations){//计算定额类型工料机的消耗量
  603. if(ra.type == rationType.gljRation&&ra.projectGLJID===pglj.id){
  604. let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
  605. r_quantity = r_quantity?r_quantity:0;
  606. if(_.includes(billIDs,ra.billsItemID)){//计算分部分项
  607. sum = scMathUtil.roundForObj(sum+r_quantity,q_decimal);
  608. }
  609. if(_.includes(tech_billIDS,ra.billsItemID)){//计算技术措施项目消耗量
  610. tech_sum = scMathUtil.roundForObj(tech_sum+r_quantity,q_decimal);
  611. }
  612. }
  613. }
  614. result.subdivisionQuantity = sum;
  615. result.techQuantity = tech_sum;
  616. return result;
  617. function calcQuantity(rg,quantityMap) { //计算工料机在所属定额下的总消耗量
  618. let tem_ration = _.find(rations,{"ID":rg.rationID});
  619. let total = parseFloat(gljOprObj.getTotalQuantity(rg,tem_ration));
  620. let r_index = gljOprObj.getIndex(rg,gljKeyArray);
  621. if(mixRatioMap.hasOwnProperty(r_index)){
  622. let mixRatioList = mixRatioMap[r_index];
  623. for(let m of mixRatioList){
  624. let m_index = gljOprObj.getIndex(m,gljKeyArray);
  625. let m_quantity = scMathUtil.roundForObj(total*m.consumption,q_decimal);
  626. if(quantityMap[m_index]){
  627. quantityMap[m_index] = scMathUtil.roundForObj(quantityMap[m_index]+m_quantity,q_decimal);
  628. }else {
  629. quantityMap[m_index] = m_quantity;
  630. }
  631. }
  632. }
  633. return total;
  634. }
  635. }