project_glj.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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. if(glj.unit_price[updateField] == newval){
  244. return;
  245. }
  246. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id};
  247. let callback = function (data) {
  248. if (updateField == 'base_price') {
  249. glj.unit_price.base_price = newval;
  250. me.setAdjustPrice(glj);
  251. } else {
  252. glj.unit_price.market_price = newval;
  253. }
  254. //更新回传的父节点项目工料机价格
  255. let gljs = me.getProjectGLJs(data);
  256. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  257. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  258. gljOprObj.showRationGLJSheetData();
  259. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  260. gljs.push(glj);
  261. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  262. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  263. socket.emit('unitFileChangeNotify', JSON.stringify(data));
  264. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  265. if(cb){
  266. cb(gljs);
  267. }
  268. $.bootstrapLoading.end();
  269. }
  270. $.bootstrapLoading.start();
  271. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  272. $.bootstrapLoading.end();
  273. });
  274. } else {
  275. gljOprObj.showRationGLJSheetData();
  276. }
  277. };
  278. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) {
  279. let me = this;
  280. let projectGljs = me.datas.gljList;
  281. let decimal = getDecimal('glj.unitPrice');
  282. let updateData = [];
  283. let newValueMap = {};
  284. let gljs=[];
  285. for(let ci of changeInfo){
  286. let dataCode = projectGljObject.projectGljSetting.header[ci.col].dataCode;
  287. let recode = projectGljObject.projectGljSheetData[ci.row];
  288. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  289. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  290. let newValue= scMathUtil.roundForObj(ci.value,decimal);
  291. let glj = _.find(projectGljs, {'id': recode.id});
  292. if(glj&&glj.unit_price[editField]!=newValue){
  293. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  294. newValueMap[glj.id]={field:editField,value:newValue};
  295. gljs.push(glj);
  296. }
  297. }
  298. }
  299. console.log(updateData);
  300. if(updateData.length > 0){
  301. $.bootstrapLoading.start();
  302. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  303. let parentData = [];
  304. //更新缓存
  305. for(let g of gljs){
  306. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  307. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  308. }
  309. //更新父工料机价格
  310. for(let r of result){
  311. let pdata = r.updateOne.filter;
  312. let set = r.updateOne.update.$set;
  313. for(let skey in set){
  314. pdata[skey] = set[skey];
  315. }
  316. parentData.push(pdata);
  317. }
  318. let pgljs = me.getProjectGLJs(parentData);
  319. gljs = gljs.concat(pgljs);
  320. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  321. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  322. gljOprObj.showRationGLJSheetData();
  323. socket.emit('unitFileChangeNotify', JSON.stringify(gljs));
  324. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  325. if(callback){
  326. callback(gljs);
  327. }
  328. $.bootstrapLoading.end();
  329. }, function (err) {
  330. $.bootstrapLoading.end();
  331. });
  332. }
  333. };
  334. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  335. let me = this;
  336. $.bootstrapLoading.start();
  337. CommonAjax.specialPost( '/glj/update',data,function (result) {
  338. let glj = me.getByID(data.id);//更新缓存
  339. let impactList = [];
  340. glj[data.field] = data.value;
  341. if(data.extend&&data.extend!=""){
  342. let extend = JSON.parse(data.extend);
  343. for (let key in extend) {
  344. glj[key] = extend[key];
  345. }
  346. }
  347. if(data.field == 'is_evaluate'){
  348. impactList = me.changeIsEvaluate(data.id);
  349. }
  350. if(callback){
  351. callback(impactList);
  352. }
  353. $.bootstrapLoading.end();
  354. });
  355. };
  356. ProjectGLJ.prototype.getRatioData=function(id,callback){
  357. if(id){
  358. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  359. let ratios = JSON.parse(response.data);
  360. if(callback){
  361. callback(ratios);
  362. }
  363. },function () {//取不到组成物的情况
  364. callback([]);
  365. })
  366. }else {
  367. if(callback){
  368. callback([]);
  369. }
  370. }
  371. };
  372. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  373. $.bootstrapLoading.start();
  374. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  375. projectObj.project.projectGLJ.loadData(function () {
  376. if(callback){
  377. callback();
  378. }
  379. $.bootstrapLoading.end();
  380. });
  381. });
  382. };
  383. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  384. $.bootstrapLoading.start();
  385. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  386. projectObj.project.projectGLJ.loadData(function () {
  387. if(callback){
  388. callback();
  389. }
  390. $.bootstrapLoading.end();
  391. });
  392. },function (response) {
  393. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  394. $("#save-as-tips").text(msg).show();
  395. $.bootstrapLoading.end();
  396. });
  397. };
  398. //更新是否暂估
  399. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  400. let projectGLJ = projectObj.project.projectGLJ;
  401. let datas = projectGLJ.datas;
  402. let gljList = datas.gljList;
  403. let glj = _.find(gljList, {'id': id});
  404. if(glj){
  405. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  406. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  407. let conditions = [];
  408. if(pratioM&&pratioM.length>0){
  409. for(let p_key of pratioM ){
  410. conditions.push(gljOprObj.getConditionByKey(p_key));
  411. }
  412. }
  413. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  414. gljs.push(glj);
  415. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  416. //更新对应的工料机类型的定额
  417. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  418. let ration_nodes = [];
  419. for(r of rations){
  420. if(r){
  421. r.isEstimate =glj.is_evaluate?1:0;
  422. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  423. ration_node?ration_nodes.push(ration_node):'';
  424. }
  425. }
  426. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  427. for(rg of ration_glj_nodes){
  428. rg.data.isEstimate =glj.is_evaluate?1:0;
  429. ration_nodes.push(rg);
  430. }
  431. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";
  432. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  433. return gljs;
  434. }
  435. }
  436. ProjectGLJ.prototype.getByID = function (ID) {
  437. return _.find(this.datas.gljList,{'id':ID});
  438. };
  439. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  440. return _.find(this.datas.gljList,function (item) {
  441. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  442. return tem_key == conkey
  443. })
  444. };
  445. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  446. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  447. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  448. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  449. tem.data.marketUnitFee = data.unit_price.market_price;
  450. return true;
  451. }
  452. })
  453. projectObj.mainController.refreshTreeNode(nodes);
  454. }
  455. }
  456. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  457. let nodes = [];
  458. if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  459. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  460. return tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == id
  461. })
  462. }
  463. return nodes;
  464. };
  465. //根据工料机,取得所有受影响的定额节点
  466. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  467. let nodes = [];
  468. let rationMap = {};
  469. let idArray = _.map(gljs,'id');
  470. let priceArray = _.map(gljs,'unit_price');
  471. //先根据项目工料机ID,找到受影响定额的ID
  472. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  473. for (let rg of ration_glj_list) {
  474. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  475. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  476. }
  477. }
  478. for (let item of projectObj.project.mainTree.items) {
  479. if (item.sourceType == ModuleNames.ration) {
  480. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  481. let idx = _.indexOf(idArray,item.data.projectGLJID);
  482. if (idx != -1) {
  483. item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价
  484. nodes.push(item);
  485. }
  486. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  487. nodes.push(item)
  488. }
  489. }
  490. }
  491. return nodes;
  492. };
  493. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  494. for (let ration_glj of gljOprObj.sheetData) {
  495. if (ration_glj.projectGLJID == glj.id) {
  496. ration_glj.basePrice = glj.unit_price.base_price;
  497. ration_glj.marketPrice = glj.unit_price.market_price;
  498. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  499. }
  500. }
  501. }
  502. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  503. }
  504. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  505. let parentGlj = [];
  506. //
  507. let projectGljs = this.datas.gljList;
  508. let indexList = gljKeyArray;
  509. for (let d of data) {
  510. if (d) {
  511. let condition = {};
  512. for (let index of indexList) {
  513. if (d[index] != null && d[index] != undefined && d[index] != '') {
  514. condition[index] = d[index]
  515. }
  516. }
  517. let glj = _.find(projectGljs, condition);
  518. if (glj) {
  519. if(refreshPrice==true){
  520. d.base_price?glj.unit_price.base_price = d.base_price:'';
  521. d.market_price?glj.unit_price.market_price = d.market_price:'';
  522. this.setAdjustPrice(glj);
  523. this.refreshRationGLJPrice(glj);
  524. this.refreshTreeNodePriceIfNeed(glj);
  525. }
  526. parentGlj.push(glj);
  527. }
  528. }
  529. }
  530. return parentGlj;
  531. }
  532. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  533. switch (glj.unit_price.type + '') {
  534. // 人工: 调整基价=基价单价*调整系数
  535. case GLJTypeConst.LABOUR:
  536. case GLJTypeConst.MACHINE_LABOUR:
  537. glj.adjust_price = this.getAdjustPrice(glj);
  538. break;
  539. // 机械类型的算法
  540. case GLJTypeConst.MACHINE:
  541. console.log('机械');
  542. break;
  543. // 材料、主材、设备
  544. default:
  545. glj.adjust_price = glj.unit_price.base_price;
  546. }
  547. }
  548. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  549. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  550. let decimal = getDecimal("glj.unitPrice");
  551. let quantity_decimal = getDecimal("glj.quantity");
  552. let process_decimal = getDecimal("process");
  553. let tem_decimal = isRadio==true?process_decimal:decimal;
  554. if (glj.unit_price.type == GLJTypeConst.LABOUR || glj.unit_price.type == GLJTypeConst.MACHINE_LABOUR) {//人工、机上人工,调整价根据定额价*调整系数计算得出。
  555. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  556. //let labour=1;
  557. let coe = labour && labour.coe ? labour.coe : 1;
  558. return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal)), -tem_decimal);
  559. } else if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
  560. let p =0;
  561. for(let ratio of glj.ratio_data){
  562. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  563. 'code': ratio.code,
  564. 'name': ratio.name,
  565. 'specs':ratio.specs,
  566. 'type': ratio.type,
  567. 'unit': ratio.unit
  568. })
  569. if(tem){
  570. let priceData={};
  571. gljOprObj.setGLJPrice(priceData,tem,true);
  572. p+=scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  573. }
  574. }
  575. return scMathUtil.roundForObj(p,decimal);
  576. } else {//对于其他普通材料等,无调整系数,调整价=定额价。
  577. return glj.unit_price.base_price
  578. }
  579. };
  580. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  581. let price_decimal = getDecimal("glj.unitPrice");
  582. let quantity_decimal = getDecimal("glj.quantity");
  583. let process_decimal = getDecimal("process");
  584. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  585. let p =0;
  586. for(let ratio of glj.ratio_data){
  587. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  588. 'code': ratio.code,
  589. 'name': ratio.name,
  590. 'specs':ratio.specs,
  591. 'type': ratio.type,
  592. 'unit': ratio.unit
  593. });
  594. if(tem){
  595. let priceData={};
  596. gljOprObj.setGLJPrice(priceData,tem,true);
  597. p+=scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  598. }
  599. }
  600. return scMathUtil.roundForObj(p,price_decimal);
  601. }else {
  602. let tem_decimal = isRadio==true?process_decimal:price_decimal;
  603. return scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal);
  604. }
  605. };
  606. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  607. let price_decimal = getDecimal("glj.unitPrice");
  608. let quantity_decimal = getDecimal("glj.quantity");
  609. let process_decimal = getDecimal("process");
  610. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  611. let p =0;
  612. for(let ratio of glj.ratio_data){
  613. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  614. 'code': ratio.code,
  615. 'name': ratio.name,
  616. 'specs':ratio.specs,
  617. 'type': ratio.type,
  618. 'unit': ratio.unit
  619. });
  620. if(tem){
  621. let priceData={};
  622. gljOprObj.setGLJPrice(priceData,tem,true);
  623. p+=scMathUtil.roundForObj(priceData.marketPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  624. }
  625. }
  626. return scMathUtil.roundForObj(p,price_decimal);
  627. }else {
  628. let tem_decimal = isRadio==true?process_decimal:price_decimal;
  629. return scMathUtil.roundForObj(glj.unit_price.market_price,tem_decimal);
  630. }
  631. }
  632. ProjectGLJ.prototype.isEstimateType = function(type){
  633. let typeString = type + "";
  634. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  635. return type;
  636. }
  637. return false;
  638. };
  639. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  640. let gljTypeMap = this.datas.constData.gljTypeMap;
  641. return gljTypeMap["typeId" + ID].shortName;
  642. };
  643. ProjectGLJ.prototype.calcQuantity = function (){
  644. let project_gljs = this.datas.gljList;
  645. let mixRatioConnectData = this.datas.mixRatioConnectData;
  646. let mixRatioMap = this.datas.mixRatioMap;
  647. let rations = projectObj.project.Ration.datas;
  648. let rationMap = _.indexBy(rations,'ID');
  649. let quantityMap={};
  650. let rationGljGroup = _.groupBy(projectObj.project.ration_glj.datas,'projectGLJID')
  651. let q_decimal = getDecimal("glj.quantity");
  652. for(let pglj of project_gljs ){
  653. let pg_index = gljOprObj.getIndex(pglj,gljKeyArray);
  654. pglj.subdivisionQuantity = 0;
  655. pglj.techQuantity = 0;
  656. pglj.quantity = 0;
  657. let gljGroup = rationGljGroup[pglj.id]?rationGljGroup[pglj.id]:[];//定额工料机没有,有可能是定额类型的工料机
  658. let result = this.getQuantityPerGLJ(gljGroup,rations,rationMap,pglj,quantityMap);
  659. pglj.subdivisionQuantity = result.subdivisionQuantity;
  660. pglj.techQuantity = result.techQuantity;
  661. pglj.quantity = result.quantity;
  662. quantityMap[pg_index] = pglj;
  663. }
  664. //计算做为组成物的消耗量
  665. for(let pkey in mixRatioMap){
  666. let mixRatioList = mixRatioMap[pkey];
  667. for(let m of mixRatioList){
  668. let m_index = gljOprObj.getIndex(m,gljKeyArray);
  669. let m_glj = quantityMap[m_index];
  670. let p_glj = quantityMap[pkey];
  671. if(m_glj&&p_glj){
  672. let quantity = scMathUtil.roundForObj(p_glj.quantity*parseFloat(m.consumption),q_decimal);
  673. let techQuantity = scMathUtil.roundForObj(p_glj.techQuantity*parseFloat(m.consumption),q_decimal);
  674. let subdivisionQuantity = scMathUtil.roundForObj(p_glj.subdivisionQuantity*parseFloat(m.consumption),q_decimal);
  675. m_glj.quantity = scMathUtil.roundForObj(m_glj.quantity+quantity,q_decimal);
  676. m_glj.techQuantity = scMathUtil.roundForObj(m_glj.techQuantity+techQuantity,q_decimal);
  677. m_glj.subdivisionQuantity = scMathUtil.roundForObj(m_glj.subdivisionQuantity+subdivisionQuantity,q_decimal);
  678. }
  679. }
  680. }
  681. }
  682. ProjectGLJ.prototype.getQuantityPerGLJ = function (ration_glj_list,rations,rationMap,pglj) {
  683. let billIDs = projectObj.project.Bills.getSubdivisionProjectLeavesID();//取分部分项上的所有叶子清单ID
  684. let tech_billIDS = projectObj.project.Bills.getTechLeavesID();//取所有技术措施项目叶子清单IDs
  685. let mixRatioMap = this.datas.mixRatioMap;
  686. let q_decimal = getDecimal("glj.quantity");
  687. let result={};
  688. let quantity_sum=0;//工料机汇总消耗量
  689. let sum = 0;//分部分项总消耗量
  690. let tech_sum = 0;//技术措施总消耗量
  691. for(let rg of ration_glj_list){
  692. let tem_ration = rationMap[rg.rationID];
  693. let r_quantity = tem_ration?scMathUtil.roundForObj(tem_ration.quantity,q_decimal):0;
  694. let glj_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal);
  695. if(!r_quantity){
  696. continue;
  697. }
  698. let total = scMathUtil.roundForObj(glj_quantity*r_quantity, q_decimal);
  699. quantity_sum = scMathUtil.roundForObj(quantity_sum+total,q_decimal);
  700. if(_.includes(billIDs,rg.billsItemID)){//计算分部分项
  701. sum = scMathUtil.roundForObj(sum+total,q_decimal);
  702. }
  703. if(_.includes(tech_billIDS,rg.billsItemID)){//计算技术措施项目消耗量
  704. tech_sum = scMathUtil.roundForObj(tech_sum+total,q_decimal);
  705. }
  706. }
  707. for(let ra of rations){//计算定额类型工料机的消耗量
  708. if(ra.type == rationType.gljRation&&ra.projectGLJID===pglj.id){
  709. let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
  710. r_quantity = r_quantity?r_quantity:0;
  711. quantity_sum = scMathUtil.roundForObj(quantity_sum+r_quantity,q_decimal);
  712. if(_.includes(billIDs,ra.billsItemID)){//计算分部分项
  713. sum = scMathUtil.roundForObj(sum+r_quantity,q_decimal);
  714. }
  715. if(_.includes(tech_billIDS,ra.billsItemID)){//计算技术措施项目消耗量
  716. tech_sum = scMathUtil.roundForObj(tech_sum+r_quantity,q_decimal);
  717. }
  718. }
  719. }
  720. result.subdivisionQuantity = sum;
  721. result.techQuantity = tech_sum;
  722. result.quantity = quantity_sum;
  723. return result;
  724. }