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,editingText) {
  174. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  175. projectObj.project.Ration.updateContain(newval,node);
  176. }if(updateField == "quantity"){
  177. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  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. projectObj.mainController.refreshTreeNode([node]);
  187. return;
  188. }
  189. let data = {
  190. glj_id: rationTypeGLJ.GLJID,
  191. project_id: rationTypeGLJ.projectID,
  192. code: rationTypeGLJ.code,
  193. original_code: rationTypeGLJ.original_code,
  194. name: rationTypeGLJ.name,
  195. shortName: rationTypeGLJ.shortName,
  196. specs: rationTypeGLJ.specs,
  197. unit: rationTypeGLJ.unit,
  198. type: rationTypeGLJ.subType,
  199. type_of_work: rationTypeGLJ.subType,
  200. base_price: rationTypeGLJ.basePrice,
  201. market_price: rationTypeGLJ.basePrice,
  202. repositoryId: rationTypeGLJ.repositoryId,
  203. adjCoe: rationTypeGLJ.adjCoe,
  204. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  205. };
  206. if (updateField == 'subType') {
  207. data.type = newval;
  208. data.type_of_work = newval;
  209. data.shortName = this.getShortNameByID(newval);
  210. } else {
  211. data[updateField] = newval;
  212. }
  213. postData.ration = {
  214. ID: rationTypeGLJ.ID,
  215. projectID: rationTypeGLJ.projectID
  216. };
  217. postData.updateData = data;
  218. $.bootstrapLoading.start();
  219. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  220. console.log(result); //更新节点信息
  221. rationTypeGLJ[updateField] = newval;
  222. rationTypeGLJ.projectGLJID = result.id;
  223. rationTypeGLJ.code = result.code;
  224. rationTypeGLJ.basePrice = result.unit_price.base_price;
  225. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  226. rationTypeGLJ.isAdd = result.unit_price.is_add;
  227. rationTypeGLJ.isEstimate = result.is_evaluate;
  228. rationTypeGLJ.shortName = result.unit_price.short_name;
  229. //触发计算并更新节点信息
  230. node.changed = true;
  231. projectObj.project.projectGLJ.loadData(function () {
  232. projectObj.project.calcProgram.calcAndSave(node);
  233. $.bootstrapLoading.end();
  234. });//重新加载项目工料机数据
  235. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  236. }, function (err) {
  237. $.bootstrapLoading.end();
  238. });
  239. }
  240. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  241. let me = this;
  242. let projectGljs = this.datas.gljList;
  243. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  244. let glj = _.find(projectGljs, {'id': pgljID});
  245. if (glj) {
  246. if(glj.unit_price[updateField] == newval){
  247. return;
  248. }
  249. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id};
  250. let callback = function (data) {
  251. if (updateField == 'base_price') {
  252. glj.unit_price.base_price = newval;
  253. me.setAdjustPrice(glj);
  254. } else {
  255. glj.unit_price.market_price = newval;
  256. }
  257. //更新回传的父节点项目工料机价格
  258. let gljs = me.getProjectGLJs(data);
  259. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  260. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  261. gljOprObj.showRationGLJSheetData();
  262. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  263. gljs.push(glj);
  264. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  265. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  266. socket.emit('unitFileChangeNotify', JSON.stringify(data));
  267. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  268. if(cb){
  269. cb(gljs);
  270. }
  271. $.bootstrapLoading.end();
  272. }
  273. $.bootstrapLoading.start();
  274. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  275. $.bootstrapLoading.end();
  276. });
  277. } else {
  278. gljOprObj.showRationGLJSheetData();
  279. }
  280. };
  281. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) {
  282. let me = this;
  283. let projectGljs = me.datas.gljList;
  284. let decimal = getDecimal('glj.unitPrice');
  285. let updateData = [];
  286. let newValueMap = {};
  287. let gljs=[];
  288. for(let ci of changeInfo){
  289. let dataCode = projectGljObject.projectGljSetting.header[ci.col].dataCode;
  290. let recode = projectGljObject.projectGljSheetData[ci.row];
  291. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  292. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  293. let newValue= scMathUtil.roundForObj(ci.value,decimal);
  294. let glj = _.find(projectGljs, {'id': recode.id});
  295. if(glj&&glj.unit_price[editField]!=newValue){
  296. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  297. newValueMap[glj.id]={field:editField,value:newValue};
  298. gljs.push(glj);
  299. }
  300. }
  301. }
  302. console.log(updateData);
  303. if(updateData.length > 0){
  304. $.bootstrapLoading.start();
  305. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  306. let parentData = [];
  307. //更新缓存
  308. for(let g of gljs){
  309. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  310. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  311. }
  312. //更新父工料机价格
  313. for(let r of result){
  314. let pdata = r.updateOne.filter;
  315. let set = r.updateOne.update.$set;
  316. for(let skey in set){
  317. pdata[skey] = set[skey];
  318. }
  319. parentData.push(pdata);
  320. }
  321. let pgljs = me.getProjectGLJs(parentData);
  322. gljs = gljs.concat(pgljs);
  323. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  324. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  325. gljOprObj.showRationGLJSheetData();
  326. socket.emit('unitFileChangeNotify', JSON.stringify(gljs));
  327. projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
  328. if(callback){
  329. callback(gljs);
  330. }
  331. $.bootstrapLoading.end();
  332. }, function (err) {
  333. $.bootstrapLoading.end();
  334. });
  335. }
  336. };
  337. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  338. let me = this;
  339. $.bootstrapLoading.start();
  340. CommonAjax.specialPost( '/glj/update',data,function (result) {
  341. let glj = me.getByID(data.id);//更新缓存
  342. let impactList = [];
  343. glj[data.field] = data.value;
  344. if(data.extend&&data.extend!=""){
  345. let extend = JSON.parse(data.extend);
  346. for (let key in extend) {
  347. glj[key] = extend[key];
  348. }
  349. }
  350. if(data.field == 'is_evaluate'){
  351. impactList = me.changeIsEvaluate(data.id);
  352. }
  353. if(callback){
  354. callback(impactList);
  355. }
  356. $.bootstrapLoading.end();
  357. });
  358. };
  359. ProjectGLJ.prototype.getRatioData=function(id,callback){
  360. this.getRatioId = id;
  361. if(id){
  362. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  363. let ratios = JSON.parse(response.data);
  364. if(callback){
  365. callback(ratios);
  366. }
  367. },function () {//取不到组成物的情况
  368. callback([]);
  369. })
  370. }else {
  371. if(callback){
  372. callback([]);
  373. }
  374. }
  375. };
  376. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  377. $.bootstrapLoading.start();
  378. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  379. projectObj.project.projectGLJ.loadData(function () {
  380. if(callback){
  381. callback();
  382. }
  383. $.bootstrapLoading.end();
  384. });
  385. });
  386. };
  387. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  388. $.bootstrapLoading.start();
  389. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  390. projectObj.project.projectGLJ.loadData(function () {
  391. if(callback){
  392. callback();
  393. }
  394. $.bootstrapLoading.end();
  395. });
  396. },function (response) {
  397. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  398. $("#save-as-tips").text(msg).show();
  399. $.bootstrapLoading.end();
  400. });
  401. };
  402. //更新是否暂估
  403. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  404. let projectGLJ = projectObj.project.projectGLJ;
  405. let datas = projectGLJ.datas;
  406. let gljList = datas.gljList;
  407. let glj = _.find(gljList, {'id': id});
  408. if(glj){
  409. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  410. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  411. let conditions = [];
  412. if(pratioM&&pratioM.length>0){
  413. for(let p_key of pratioM ){
  414. conditions.push(gljOprObj.getConditionByKey(p_key));
  415. }
  416. }
  417. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  418. gljs.push(glj);
  419. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  420. //更新对应的工料机类型的定额
  421. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  422. let ration_nodes = [];
  423. for(r of rations){
  424. if(r){
  425. r.isEstimate =glj.is_evaluate?1:0;
  426. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  427. ration_node?ration_nodes.push(ration_node):'';
  428. }
  429. }
  430. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  431. for(rg of ration_glj_nodes){
  432. rg.data.isEstimate =glj.is_evaluate?1:0;
  433. ration_nodes.push(rg);
  434. }
  435. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";
  436. projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
  437. return gljs;
  438. }
  439. }
  440. ProjectGLJ.prototype.getByID = function (ID) {
  441. return _.find(this.datas.gljList,{'id':ID});
  442. };
  443. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  444. return _.find(this.datas.gljList,function (item) {
  445. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  446. return tem_key == conkey
  447. })
  448. };
  449. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  450. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  451. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  452. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  453. tem.data.marketUnitFee = data.unit_price.market_price;
  454. return true;
  455. }
  456. })
  457. projectObj.mainController.refreshTreeNode(nodes);
  458. }
  459. }
  460. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  461. let nodes = [];
  462. if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  463. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  464. return tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == id
  465. })
  466. }
  467. return nodes;
  468. };
  469. //根据工料机,取得所有受影响的定额节点
  470. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  471. let nodes = [];
  472. let rationMap = {};
  473. let idArray = _.map(gljs,'id');
  474. let priceArray = _.map(gljs,'unit_price');
  475. //先根据项目工料机ID,找到受影响定额的ID
  476. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  477. for (let rg of ration_glj_list) {
  478. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  479. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  480. }
  481. }
  482. for (let item of projectObj.project.mainTree.items) {
  483. if (item.sourceType == ModuleNames.ration) {
  484. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  485. let idx = _.indexOf(idArray,item.data.projectGLJID);
  486. if (idx != -1) {
  487. item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价
  488. nodes.push(item);
  489. }
  490. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  491. nodes.push(item)
  492. }
  493. }
  494. }
  495. return nodes;
  496. };
  497. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  498. for (let ration_glj of gljOprObj.sheetData) {
  499. if (ration_glj.projectGLJID == glj.id) {
  500. ration_glj.basePrice = glj.unit_price.base_price;
  501. ration_glj.marketPrice = glj.unit_price.market_price;
  502. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  503. }
  504. }
  505. }
  506. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  507. }
  508. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  509. let parentGlj = [];
  510. //
  511. let projectGljs = this.datas.gljList;
  512. let indexList = gljKeyArray;
  513. for (let d of data) {
  514. if (d) {
  515. let condition = {};
  516. for (let index of indexList) {
  517. if (d[index] != null && d[index] != undefined && d[index] != '') {
  518. condition[index] = d[index]
  519. }
  520. }
  521. let glj = _.find(projectGljs, condition);
  522. if (glj) {
  523. if(refreshPrice==true){
  524. d.base_price?glj.unit_price.base_price = d.base_price:'';
  525. d.market_price?glj.unit_price.market_price = d.market_price:'';
  526. this.setAdjustPrice(glj);
  527. this.refreshRationGLJPrice(glj);
  528. this.refreshTreeNodePriceIfNeed(glj);
  529. }
  530. parentGlj.push(glj);
  531. }
  532. }
  533. }
  534. return parentGlj;
  535. }
  536. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  537. switch (glj.unit_price.type + '') {
  538. // 人工: 调整基价=基价单价*调整系数
  539. case GLJTypeConst.LABOUR:
  540. case GLJTypeConst.MACHINE_LABOUR:
  541. glj.adjust_price = this.getAdjustPrice(glj);
  542. break;
  543. // 机械类型的算法
  544. case GLJTypeConst.MACHINE:
  545. console.log('机械');
  546. break;
  547. // 材料、主材、设备
  548. default:
  549. glj.adjust_price = glj.unit_price.base_price;
  550. }
  551. }
  552. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  553. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  554. let decimal = getDecimal("glj.unitPrice");
  555. let quantity_decimal = getDecimal("glj.quantity");
  556. let process_decimal = getDecimal("process");
  557. let tem_decimal = isRadio==true?process_decimal:decimal;
  558. if (glj.unit_price.type == GLJTypeConst.LABOUR || glj.unit_price.type == GLJTypeConst.MACHINE_LABOUR) {//人工、机上人工,调整价根据定额价*调整系数计算得出。
  559. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  560. //let labour=1;
  561. let coe = labour && labour.coe ? labour.coe : 1;
  562. return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal)), -tem_decimal);
  563. } else if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
  564. let p =0;
  565. for(let ratio of glj.ratio_data){
  566. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  567. 'code': ratio.code,
  568. 'name': ratio.name,
  569. 'specs':ratio.specs,
  570. 'type': ratio.type,
  571. 'unit': ratio.unit
  572. })
  573. if(tem){
  574. let priceData={};
  575. gljOprObj.setGLJPrice(priceData,tem,true);
  576. p+=scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  577. }
  578. }
  579. return scMathUtil.roundForObj(p,decimal);
  580. } else {//对于其他普通材料等,无调整系数,调整价=定额价。
  581. return glj.unit_price.base_price
  582. }
  583. };
  584. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  585. let price_decimal = getDecimal("glj.unitPrice");
  586. let quantity_decimal = getDecimal("glj.quantity");
  587. let process_decimal = getDecimal("process");
  588. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  589. let p =0;
  590. for(let ratio of glj.ratio_data){
  591. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  592. 'code': ratio.code,
  593. 'name': ratio.name,
  594. 'specs':ratio.specs,
  595. 'type': ratio.type,
  596. 'unit': ratio.unit
  597. });
  598. if(tem){
  599. let priceData={};
  600. gljOprObj.setGLJPrice(priceData,tem,true);
  601. p+=scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  602. }
  603. }
  604. return scMathUtil.roundForObj(p,price_decimal);
  605. }else {
  606. let tem_decimal = isRadio==true?process_decimal:price_decimal;
  607. return scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal);
  608. }
  609. };
  610. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  611. let price_decimal = getDecimal("glj.unitPrice");
  612. let quantity_decimal = getDecimal("glj.quantity");
  613. let process_decimal = getDecimal("process");
  614. if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  615. let p =0;
  616. for(let ratio of glj.ratio_data){
  617. let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{
  618. 'code': ratio.code,
  619. 'name': ratio.name,
  620. 'specs':ratio.specs,
  621. 'type': ratio.type,
  622. 'unit': ratio.unit
  623. });
  624. if(tem){
  625. let priceData={};
  626. gljOprObj.setGLJPrice(priceData,tem,true);
  627. p+=scMathUtil.roundForObj(priceData.marketPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  628. }
  629. }
  630. return scMathUtil.roundForObj(p,price_decimal);
  631. }else {
  632. let tem_decimal = isRadio==true?process_decimal:price_decimal;
  633. return scMathUtil.roundForObj(glj.unit_price.market_price,tem_decimal);
  634. }
  635. }
  636. ProjectGLJ.prototype.isEstimateType = function(type){
  637. let typeString = type + "";
  638. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  639. return type;
  640. }
  641. return false;
  642. };
  643. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  644. let gljTypeMap = this.datas.constData.gljTypeMap;
  645. return gljTypeMap["typeId" + ID].shortName;
  646. };
  647. ProjectGLJ.prototype.calcQuantity = function (init=false){
  648. let project_gljs = this.datas.gljList;
  649. let mixRatioConnectData = this.datas.mixRatioConnectData;
  650. let mixRatioMap = this.datas.mixRatioMap;
  651. let rations = projectObj.project.Ration.datas;
  652. let rationMap = _.indexBy(rations,'ID');
  653. let quantityMap={},changeArray=[];
  654. let rationGljGroup = _.groupBy(projectObj.project.ration_glj.datas,'projectGLJID')
  655. let q_decimal = getDecimal("glj.quantity");
  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. }