project_glj.js 30 KB

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