project_glj.js 30 KB

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