project_glj.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  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,error=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. if(error) error();
  34. },
  35. beforeSend: function () {
  36. self.isLoading = true;
  37. },
  38. success: function (response) {
  39. self.isLoading = false;
  40. if (response.err === 1) {
  41. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取人材机数据失败!';
  42. alert(msg);
  43. if(error) error();
  44. return false;
  45. }
  46. self.refreshByDatas(response.data);
  47. // 回调函数
  48. if (callback !== null) {
  49. callback(response.data);
  50. }
  51. // 存入缓存
  52. projectObj.project.projectGLJ = self;
  53. }
  54. });
  55. };
  56. //更新项目工料机数据和缓存
  57. ProjectGLJ.prototype.refreshByDatas = function(datas){
  58. this.datas = datas;
  59. this.calcQuantity();
  60. };
  61. ProjectGLJ.prototype.synLoadData = function () {
  62. return new Promise(function (resolve, reject) {
  63. projectObj.project.projectGLJ.loadData(function (data) {
  64. resolve(data)
  65. },function () {
  66. reject("获取工料机数据失败")
  67. })
  68. })
  69. }
  70. ProjectGLJ.prototype.loadToCache = function (data) {
  71. this.datas = data;
  72. projectObj.project.projectGLJ = this;
  73. }
  74. /**
  75. * 获取对应工料机数据
  76. *
  77. * @param {String} code
  78. * @return {Object}
  79. */
  80. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  81. return _.find(this.datas.gljList, {'id': ID});
  82. };
  83. // CSL, 2018-02-08 甲供、甲定。
  84. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  85. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  86. // 所以这里要合并处理。
  87. let mixSupply = [];
  88. for (let s of supplyTypeArr){
  89. switch (s) {
  90. case 1:
  91. mixSupply.push('部分甲供');
  92. break;
  93. case 2:
  94. mixSupply.push('完全甲供');
  95. break;
  96. case 3:
  97. mixSupply.push('甲定乙供');
  98. break;
  99. default:
  100. mixSupply.push('自行采购');
  101. }
  102. };
  103. mixSupply = mixSupply.concat(supplyTypeArr);
  104. return _.filter(this.datas.gljList, function (glj) {
  105. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  106. });
  107. };
  108. ProjectGLJ.prototype.testGLJs = function () {
  109. let gljs = [];
  110. for (let glj of this.datas.gljList){
  111. let o = new Object();
  112. o.name = glj.name;
  113. o.supply = glj.supply;
  114. o.quantity = glj.quantity;
  115. o.supply_quantity = glj.supply_quantity;
  116. gljs.push(o);
  117. };
  118. return gljs;
  119. };
  120. /**
  121. * 修改工料机数据
  122. *
  123. * @param {Number} id
  124. * @param {Object} data
  125. * @return {boolean}
  126. */
  127. ProjectGLJ.prototype.updateData = function (id, data) {
  128. let result = false;
  129. if (this.datas === null) {
  130. return result;
  131. }
  132. let gljList = this.datas.gljList;
  133. if (gljList === undefined) {
  134. return result;
  135. }
  136. // 查找对应的index
  137. let index = -1;
  138. for (let tmp in gljList) {
  139. if (gljList[tmp].id === id) {
  140. index = tmp;
  141. break;
  142. }
  143. }
  144. if (index < 0) {
  145. return result;
  146. }
  147. // 修改数据
  148. for (let tmpIndex in data) {
  149. if (tmpIndex.indexOf('_price') >= 0) {
  150. // 修改unit_price中的对象
  151. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  152. } else {
  153. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  154. }
  155. }
  156. };
  157. /**
  158. * 加载缓存数据到spread
  159. *
  160. * @return {void}
  161. */
  162. ProjectGLJ.prototype.loadCacheData = function (resort) {
  163. // 加载工料机数据
  164. let data = this.datas === null ? null : this.datas;
  165. if (data === null) {
  166. return;
  167. }
  168. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  169. console.log("filter start");
  170. jsonData = filterProjectGLJ(jsonData);
  171. console.log("filter end");
  172. jsonData = sortProjectGLJ(jsonData);
  173. console.log("sort end");
  174. if(projectGLJSheet&&projectGLJSpread){
  175. setTimeout(spreadInit, 1);
  176. /*projectGLJSheet.setData(jsonData);
  177. projectGLJSpread.specialColumn(jsonData);*/
  178. }
  179. };
  180. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval,callback) {
  181. if (updateField == 'marketPrice') {
  182. this.updatePrice(recode, "market_price", newval,"rg",callback);
  183. }
  184. if (updateField == 'basePrice') {
  185. this.updatePrice(recode, "base_price", newval,"rg",callback);
  186. }
  187. };
  188. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  189. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  190. projectObj.project.Ration.updateContain(newval,node);
  191. }if(updateField == "quantity"){
  192. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  193. } else {
  194. this.updateGLJProperty(node, updateField, newval);
  195. }
  196. };
  197. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  198. let rationTypeGLJ = node.data;
  199. let postData = {};
  200. if (rationTypeGLJ[updateField] == newval) {
  201. projectObj.mainController.refreshTreeNode([node]);
  202. return;
  203. }
  204. let data = {
  205. glj_id: rationTypeGLJ.GLJID,
  206. project_id: rationTypeGLJ.projectID,
  207. code: rationTypeGLJ.code,
  208. original_code: rationTypeGLJ.original_code,
  209. name: rationTypeGLJ.name,
  210. shortName: rationTypeGLJ.shortName,
  211. specs: rationTypeGLJ.specs,
  212. unit: rationTypeGLJ.unit,
  213. type: rationTypeGLJ.subType,
  214. type_of_work: rationTypeGLJ.subType,
  215. base_price: rationTypeGLJ.basePrice,
  216. market_price: rationTypeGLJ.basePrice,
  217. repositoryId: rationTypeGLJ.repositoryId,
  218. adjCoe: rationTypeGLJ.adjCoe,
  219. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  220. };
  221. if (updateField == 'subType') {
  222. data.type = newval;
  223. data.type_of_work = newval;
  224. data.shortName = this.getShortNameByID(newval);
  225. } else {
  226. data[updateField] = newval;
  227. }
  228. postData.ration = {
  229. ID: rationTypeGLJ.ID,
  230. projectID: rationTypeGLJ.projectID
  231. };
  232. postData.updateData = data;
  233. $.bootstrapLoading.start();
  234. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  235. console.log(result); //更新节点信息
  236. node.updateData[updateField] = newval;
  237. node.updateData.projectGLJID = result.id;
  238. node.updateData.code = result.code;
  239. node.updateData.basePrice = result.unit_price.base_price;
  240. node.updateData.marketUnitFee = result.unit_price.market_price;
  241. node.updateData.isAdd = result.unit_price.is_add;
  242. node.updateData.isEstimate = result.is_evaluate;
  243. node.updateData.shortName = result.unit_price.short_name;
  244. //触发计算并更新节点信息
  245. node.changed = true;
  246. projectObj.project.projectGLJ.loadData(function () {
  247. projectObj.project.calcProgram.calcAndSave(node);
  248. $.bootstrapLoading.end();
  249. });//重新加载项目工料机数据
  250. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  251. }, function (err) {
  252. $.bootstrapLoading.end();
  253. });
  254. }
  255. ProjectGLJ.prototype.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  256. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  257. return getDecimal("glj.unitPriceHasMix");
  258. }else {
  259. return getDecimal('glj.unitPrice');
  260. }
  261. };
  262. ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,value,ext) {//只有添加、删除走这个方法
  263. let glj = _.find(this.datas.gljList,{'id':projectGLJ.id});
  264. if (glj) {
  265. if(glj.unit_price[updateField] == value){
  266. return;
  267. }
  268. if(updateField == 'calcMaterial'){
  269. ext=ext?ext:{};
  270. if(value == 1){//添加材料计算操作,把单位毛重/采购保管费率等数据复制一份
  271. ext['grossWeightCoe_n'] = glj.unit_price.grossWeightCoe;
  272. ext['purchaseStorageRate_n'] = glj.unit_price.purchaseStorageRate;
  273. ext['offSiteTransportLossRate_n'] = glj.unit_price.offSiteTransportLossRate;
  274. ext['handlingLossRate_n'] = glj.unit_price.handlingLossRate;
  275. ext['totalLoadingTimes'] = '1';
  276. }else if(value == 0){//删除操作,恢复单位毛重/采购保管费率等数据
  277. ext['supplyLocation'] = '';
  278. ext['originalPrice'] = '0';
  279. ext['unitFreight']='0';
  280. ext['totalLoadingTimes']='0';
  281. ext['offSiteTransportLoss']='0';
  282. ext['purchaseStorage']='0';
  283. ext['packageRecoverValue']='0';
  284. }
  285. }
  286. let data = {id: glj.unit_price.id,updateField:updateField ,value: value,unit_price_file_id:glj.unit_price.unit_price_file_id,ext:ext};
  287. $.bootstrapLoading.start();
  288. try {
  289. let result = await ajaxPost('/glj/updateCalcMaterial',data);
  290. glj.unit_price[updateField] = value;
  291. if(ext){
  292. for(let key in ext){
  293. glj.unit_price[key] = ext[key];
  294. }
  295. }
  296. if(updateField == 'calcMaterial' && value ==0){///标记为0即删除材料计算标记,要删除其下挂的原价计算,运费计算,定额计算,消耗量重新计算
  297. let connect_key = gljUtil.getIndex(glj);
  298. _.remove(this.datas.originalList,{'connect_key':connect_key});
  299. _.remove(this.datas.freightList,{'connect_key':connect_key});
  300. this.calcQuantity();
  301. // to do 删除定额计算
  302. }
  303. projectGljObject.refreshDataSheet();
  304. materialCalcObj.showDatas();
  305. }catch (e){
  306. console.log(e)
  307. }finally {
  308. $.bootstrapLoading.end();
  309. }
  310. }
  311. };
  312. ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生改变时重算所有计算材料的价格
  313. let priceMap = {};
  314. for(let unitPrice of unitPriecs){
  315. if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
  316. }
  317. let freightListMap = _.groupBy(this.datas.freightList,'connect_key');//取运费计算项映射表
  318. let originalListMap = _.groupBy(this.datas.originalList,'connect_key');//取原价计算项映射表
  319. let sumFreightUpdateMap = {}; //存放所有材料下的运费更新信息;
  320. let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
  321. for(let g of this.datas.gljList){
  322. if(g.quantity !== 0 && g.quantity !== '0' && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
  323. //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
  324. let fOrPDataMap = {};
  325. let tIndex = gljUtil.getIndex(g);
  326. //运费和原价中的工料机只要有一个包含该材料,就要重算
  327. if(freightListMap[tIndex]){ //运费重算
  328. let freightUpdateMap = {};
  329. for(let f of freightListMap[tIndex]){
  330. if(f.conveyance != "自办运输") continue;//不是自办运输的不用管
  331. let calf = ifNeedReCalc(f,priceMap);
  332. if(calf){
  333. let f_task = this.calcEachFreightOrPrice(f,"freight",priceMap);
  334. if(f_task){
  335. freightUpdateMap[f_task.ID] = f_task.doc;
  336. sumFreightUpdateMap[f_task.ID] = f_task.doc;
  337. }
  338. }
  339. }
  340. if(!_.isEmpty(freightUpdateMap)) fOrPDataMap["freight"] = {update:freightUpdateMap};
  341. }
  342. //原价重算
  343. if(originalListMap[tIndex]){ //运费重算
  344. let originalUpdateMap = {};
  345. for(let o of originalListMap[tIndex]){
  346. let calo = ifNeedReCalc(o,priceMap);
  347. if(calo){
  348. let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
  349. if(o_task){
  350. originalUpdateMap[o_task.ID] = o_task.doc;
  351. sumOriginalUpdateMap[o_task.ID] = o_task.doc;
  352. }
  353. }
  354. }
  355. if(!_.isEmpty(originalUpdateMap)) fOrPDataMap["price"] = {update:originalUpdateMap};
  356. }
  357. //判断映射表是否为空,如果为空则说明不用计算
  358. if(!_.isEmpty(fOrPDataMap)){
  359. let t_unipPrice = this.materialCal(g.id,fOrPDataMap,g,freightListMap[tIndex],originalListMap[tIndex]);
  360. if(t_unipPrice) unitPriecs.push(t_unipPrice);
  361. }
  362. }
  363. }
  364. let sumUpdateMap = {};
  365. if(!_.isEmpty(sumFreightUpdateMap))sumUpdateMap["freight"] = {update:sumFreightUpdateMap};
  366. if(!_.isEmpty(sumOriginalUpdateMap))sumUpdateMap["price"] = {update:sumOriginalUpdateMap};
  367. return [unitPriecs,sumUpdateMap];
  368. function ifNeedReCalc(obj,IDMap) {
  369. let calcf = false;
  370. if(obj.ration_gljs){
  371. for(let rg of obj.ration_gljs){
  372. if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
  373. calcf = true;
  374. break;
  375. }
  376. }
  377. }
  378. return calcf;
  379. }
  380. };
  381. ProjectGLJ.prototype.materialCal = function (id,dataMap,tglj,tfreightList,tpriceList) {
  382. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  383. let unitPirceDecimal = getDecimal("glj.unitPrice");
  384. let process = getDecimal("process");
  385. let glj = tglj?tglj: _.find(this.datas.gljList,{'id':id});
  386. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  387. if(!glj) return;
  388. let unitPrice = {projectGLJID:glj.id,id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  389. //先计算原价
  390. let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap,tpriceList);
  391. doc['originalPrice'] = originalPrice+'';
  392. doc['supplyLocation'] = supplyLocation;
  393. //再计算运费
  394. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  395. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  396. let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap,tfreightList);
  397. doc['unitFreight'] = unitFreight+'';
  398. //计算场外运输损耗
  399. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  400. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  401. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  402. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  403. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  404. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  405. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  406. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  407. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  408. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  409. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  410. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  411. //计算采购及保管费
  412. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  413. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  414. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  415. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  416. doc['purchaseStorage'] = purchaseStorage+'';
  417. //再计算预算价
  418. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  419. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  420. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  421. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  422. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  423. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  424. let o_unit = glj.unit_price;
  425. for(let key in doc){
  426. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  427. unitPrice.doc[key] = doc[key];
  428. }
  429. return unitPrice
  430. };
  431. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreightList) {
  432. let process = getDecimal("process");
  433. let unitPirce = getDecimal("glj.unitPrice");
  434. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  435. let sum = 0;
  436. let freightList = tfreightList?tfreightList:_.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  437. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  438. for(let f of freightList){
  439. let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe,conveyance = f.conveyance,calcType=f.calcType,materialType=f.materialType;
  440. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  441. let t = dataMap["freight"]["update"][f.ID];
  442. if(t){
  443. if(t['unitFreight']) unitFreight = t['unitFreight'];
  444. if(t['kmDistance']) kmDistance = t['kmDistance'];
  445. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  446. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  447. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  448. if(t['otherFee']) otherFee = t['otherFee'];
  449. if(t['weightCoe']) weightCoe = t['weightCoe'];
  450. if(t['conveyance']) conveyance = t['conveyance'];
  451. if(t['calcType']) calcType = t['calcType'];
  452. if(t['materialType']) materialType = t['materialType'];
  453. }
  454. }
  455. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  456. if(dataMap["freight"]["delete"][f.ID]) continue;
  457. }
  458. //开始计算
  459. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  460. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  461. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  462. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  463. let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
  464. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  465. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  466. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  467. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  468. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  469. if(calcType == "内蒙古") t = scMathUtil.roundForObj(t/1.09,process); //内蒙古要除以税率1.09;
  470. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  471. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  472. t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  473. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  474. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  475. sum = scMathUtil.roundForObj(sum + t,process);
  476. }
  477. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  478. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  479. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  480. }
  481. return scMathUtil.roundForObj(sum,unitPirce);
  482. function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
  483. if(calcType =="内蒙古") return materialCalcObj.calNeiMengTotalFreight(kmDistance,materialType);
  484. //如果运输方式为自办运输,则直接返回单位运价即可;
  485. let price = conveyance == "自办运输" ? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  486. return price
  487. }
  488. };
  489. ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
  490. let process = getDecimal("process");
  491. let unitPirce = getDecimal("glj.unitPrice");
  492. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  493. let original_price = 0;
  494. let supplyList = [];
  495. let supplyLocation = "";
  496. let priceList = tpriceList?tpriceList:_.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  497. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  498. for(let p of priceList){
  499. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  500. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  501. let t = dataMap["price"]["update"][p.ID];
  502. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  503. if(t && t["coe"]) coe =t["coe"];
  504. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  505. }
  506. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  507. if(dataMap["price"]["delete"][p.ID]) continue;
  508. }
  509. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  510. coe = scMathUtil.roundForObj(coe,unitPirce);
  511. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  512. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  513. supplyList.push(supplyLocation);
  514. }
  515. supplyLocation = supplyList.join(',');
  516. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  517. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  518. original_price = doc['originalPrice']?doc['originalPrice']:glj.unit_price.originalPrice;
  519. supplyLocation = doc['supplyLocation']?doc['supplyLocation']:glj.unit_price.supplyLocation;
  520. }
  521. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation];
  522. };
  523. ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
  524. let me = this;
  525. let gljList = [];
  526. for(let d of datas){
  527. let g = updateUnit(d.projectGLJID,d);
  528. if(g) gljList.push(g);
  529. }
  530. this.calcQuantity();
  531. //刷新项目工料机表显示
  532. projectGljObject.refreshDataSheet();
  533. //重新计算相关节点
  534. /* 2019-10-29 这里改成修改材料计算后先不自动计算,先在项目属性上做标记,切换到其它标签页时才做自动计算
  535. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  536. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  537. */
  538. //刷新定额工料机
  539. gljOprObj.refreshView();
  540. //项目单价文件修改标记
  541. projectObj.project.projectInfo.changeMark = 'unitFile';
  542. //socket推送更新信息
  543. projectGljObject.onUnitFileChange(true);
  544. function updateUnit(id,unitPrice) {
  545. let glj = _.find(me.datas.gljList,{'id':id});
  546. if(glj && !_.isEmpty(unitPrice.doc)){
  547. for(let key in unitPrice.doc){
  548. glj.unit_price[key] = unitPrice.doc[key];
  549. }
  550. }
  551. return glj;
  552. }
  553. };
  554. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  555. this.m_updateUnitPrice([unitPrice]);
  556. };
  557. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  558. await this.updateMaterialCalcTasks(pgljID,datas,"add","price");
  559. };
  560. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  561. let updateDatas=[];
  562. try {
  563. for(let d of datas){
  564. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  565. if(_.isEmpty(unitPrice.doc)) continue;
  566. updateDatas.push(unitPrice);
  567. }
  568. if(updateDatas.length ==0 ) return;
  569. let [unitPrices,sumMap] = this.calcAllMaterial(updateDatas);
  570. sumMap = {"unitPrice":unitPrices};
  571. $.bootstrapLoading.start();
  572. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  573. this.refreshMaterialCalcCache(sumMap);
  574. materialCalcObj.showDatas();
  575. }catch (e){
  576. console.log(e)
  577. }finally {
  578. $.bootstrapLoading.end();
  579. }
  580. };
  581. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  582. let updateMap = {};
  583. for(let d of datas){
  584. updateMap[d.ID] = d.doc;
  585. }
  586. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
  587. };
  588. ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
  589. //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表;
  590. try {
  591. let actionMap={};
  592. let calMap = {};
  593. actionMap[actionType] = dataMap;
  594. calMap[model] = actionMap;//{freight:{update:updateMap}
  595. let unitPrice = this.materialCal(pgljID,calMap);//计算当前这一条材料
  596. let [unitPrices,sumMap] = this.calcAllMaterial([unitPrice]);//计算完一条材料后,还要计算因为这条材料而受影响的其它所有材料
  597. if(actionType == "update") {//更新情况
  598. if (sumMap[model] && sumMap[model][actionType]) {//这一步,合并需要提交后台修改的数据
  599. let tt = sumMap[model][actionType];
  600. for (let d of datas) {
  601. tt[d.ID] = d.doc;
  602. }
  603. } else {
  604. sumMap[model] = actionMap;
  605. }
  606. }else {
  607. sumMap[model] = actionMap;
  608. }
  609. sumMap["unitPrice"] = unitPrices;
  610. $.bootstrapLoading.start();
  611. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  612. this.refreshMaterialCalcCache(sumMap);
  613. materialCalcObj.showDatas();
  614. }catch (e){
  615. console.log(e)
  616. }finally {
  617. $.bootstrapLoading.end();
  618. }
  619. };
  620. ProjectGLJ.prototype.updateUserFreight =async function (data) {
  621. try {
  622. $.bootstrapLoading.start();
  623. let result = await ajaxPost('/glj/updateUserFreight',data);
  624. // this.refreshMaterialCalcCache(sumMap);
  625. //materialCalcObj.showDatas();
  626. }catch (e){
  627. console.log(e)
  628. }finally {
  629. $.bootstrapLoading.end();
  630. }
  631. };
  632. ProjectGLJ.prototype.getUserFreights = async function () {//初始化车船税选择
  633. try {
  634. let result = await ajaxGet("/glj/getUserFreights");
  635. console.log(result);
  636. return result;
  637. }catch (e){
  638. console.log(e)
  639. }
  640. };
  641. ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap){
  642. if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
  643. if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
  644. if(updateMap["unitPrice"]) {
  645. if(Array.isArray(updateMap["unitPrice"])){
  646. this.m_updateUnitPrice(updateMap["unitPrice"]);
  647. }else {
  648. this.m_updateUnitPrice([updateMap["unitPrice"]]);
  649. }
  650. }
  651. function updateList(list,updateMap) {
  652. if(updateMap["update"]){
  653. let map = updateMap["update"];
  654. for(let o of list){
  655. if(map[o.ID]){
  656. gljUtil.updateProperty(o,map[o.ID]);
  657. }
  658. }
  659. }
  660. if(updateMap["add"]){
  661. for(let a of updateMap["add"]){
  662. list.push(a);
  663. }
  664. }
  665. if(updateMap["delete"]){
  666. for(let ID in updateMap["delete"]){
  667. _.remove(list,{'ID':ID});
  668. }
  669. }
  670. }
  671. };
  672. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  673. let updateMap = {};
  674. for(let d of datas){
  675. updateMap[d.ID] = d.doc;
  676. }
  677. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","price");
  678. };
  679. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  680. await this.updateMaterialCalcTasks(pgljID,datas,"add","freight");
  681. };
  682. ProjectGLJ.prototype.addMaterialRation = async function (code,type,parentID,connect_key){
  683. let libIDs = rationLibObj.getStdRationLibIDs();
  684. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  685. let selectedLib = sessionStorage.getItem("stdRationLib");
  686. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  687. let datas = {userID: userID,defaultLibID:defaultLibID, rationRepIds: libIDs, code: code,type:type,parentID:parentID,quantityDecimal:getDecimal("ration.quantity"),connect_key:connect_key,projectID:projectObj.project.ID()};
  688. datas.actionType="add";
  689. await this.updateMaterialRation(datas);
  690. };
  691. ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate) {
  692. $.bootstrapLoading.start();
  693. try {
  694. await ajaxPost("/glj/changeAssistProductionFeeRate",{unitFileID:projectObj.project.property.unitPriceFile.id,assistProductionFeeRate:newFeeRate});
  695. this.datas.constData.assistProductionFeeRate = newFeeRate;
  696. //todo 调用材料计算方法,所有材料重算一遍
  697. let [unitPrices,sumMap] = this.calcAllMaterial([]);
  698. sumMap["unitPrice"] = unitPrices;
  699. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  700. this.refreshMaterialCalcCache(sumMap);
  701. materialCalcObj.showDatas();
  702. }catch (err){
  703. console.log(err);
  704. }finally {
  705. $.bootstrapLoading.end();
  706. }
  707. };
  708. ProjectGLJ.prototype.updateMaterialRation = async function (datas){
  709. try {
  710. let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
  711. $.bootstrapLoading.start();
  712. let result = await ajaxPost('/ration/updateMaterialRation',datas);
  713. if(datas.actionType=="add" && result.projectGLJDatas) this.refreshByDatas(result.projectGLJDatas);//这一步已经更新了运费和原价数据
  714. if(datas.actionType == "delete"){
  715. let parent = _.find(lists,{ID:datas.parentID}) ;
  716. if(parent){
  717. _.remove(parent.rations,{ID:datas.rationID});
  718. _.remove(parent.ration_gljs,{rationID:datas.rationID});
  719. }
  720. }
  721. if(datas.actionType == "update"){
  722. let parent = _.find(lists,{ID:datas.parentID}) ;
  723. let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
  724. if(ration){
  725. if(datas.field == "code" && result.projectGLJDatas){
  726. this.refreshByDatas(result.projectGLJDatas);
  727. }else {
  728. ration[datas.field] = datas.value;
  729. if(datas.ext){
  730. for(let key in datas.ext){
  731. ration[key] = datas.ext[key];
  732. }
  733. }
  734. }
  735. if(datas.ration_gljs){//更新定额工料机数量
  736. let gljMap = _.indexBy(parent.ration_gljs,"ID");
  737. for(let g of datas.ration_gljs){
  738. if(gljMap[g.ID]) gljMap[g.ID].quantity = g.quantity;
  739. }
  740. }
  741. }
  742. }
  743. }catch (e){
  744. console.log(e)
  745. }finally {
  746. //materialCalcObj.showDatas();
  747. this.calcMaterialRation(datas.parentID,datas.type);
  748. $.bootstrapLoading.end();
  749. }
  750. };
  751. ProjectGLJ.prototype.getHighlandFee = function (feeType) {
  752. let rates = projectObj.project.FeeRate.getActivateFeeRate().rates;
  753. let matchType = false;
  754. let rate = 0;
  755. //获取高原取费类别,是先按feeType取顶层的费率,然后取子项中的“高原地区施工增加费”
  756. if(!feeType||feeType=="") return 0;//空时为0
  757. let hightlandRate = null;
  758. let topParentID = null;
  759. for(let r of rates){//费率是按顺序排的,所以先取到顶层,之后的就是目标了。
  760. if(matchType && r.ParentID == topParentID) break; //如果feeType已经匹配过了,又经过了下一个顶层节点,那说明该feeType下没有高原费率
  761. if(r.name == feeType){
  762. matchType = true;
  763. topParentID = r.ParentID;
  764. }
  765. if(matchType && r.name == "高原地区施工增加费"){
  766. //顶层先匹配上了,第一个就是要找的费率
  767. hightlandRate = r;
  768. break;
  769. }
  770. }
  771. if(hightlandRate){
  772. rate = scMathUtil.roundForObj(hightlandRate.rate,getDecimal("feeRate"));
  773. }
  774. return rate*0.01
  775. };
  776. ProjectGLJ.prototype.calcEachFreightOrPrice = function (temp,type,priceMap) {//
  777. if(temp){
  778. if(type == "freight" && temp.conveyance !="自办运输") return null;
  779. let sum =0;
  780. let gljMap = {};
  781. let pgljMap =_.indexBy(this.datas.gljList, 'id');
  782. for(let g of temp.ration_gljs){
  783. gljMap[g.rationID]?gljMap[g.rationID].push(g):gljMap[g.rationID]=[g];
  784. }
  785. for(let r of temp.rations){
  786. sum = scMathUtil.roundForObj(sum + calcRation(r,gljMap[r.ID],pgljMap,priceMap),6);
  787. }
  788. sum = scMathUtil.roundForObj(sum,getDecimal("glj.unitPrice"))+"";
  789. if(type == "freight" && temp.unitFreight!= sum) return {ID:temp.ID,doc:{unitFreight:sum}};
  790. if(type == "price" && temp.supplyPrice !=sum) return {ID:temp.ID,doc:{supplyPrice:sum}};
  791. }
  792. return null;
  793. function calcRation(ration,gljs,pMap,priceMap){
  794. let result = 0;
  795. if(gljs){
  796. //to do 计算有辅助定额的情况
  797. let processDecimal = getDecimal("process");
  798. let hightFeeRate = projectObj.project.projectGLJ.getHighlandFee(ration.feeType);//高原取费类别费率
  799. let assFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")) * 0.01;//辅助生产间接费费率
  800. let laberSum = 0;
  801. let machineSum = 0;
  802. let rationQuantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
  803. for(let g of gljs){
  804. gljOprObj.setGLJPrice(g,pMap[g.projectGLJID]);
  805. if(priceMap && priceMap[g.projectGLJID]) g.marketPrice = scMathUtil.roundForObj(priceMap[g.projectGLJID]);
  806. let quantity = scMathUtil.roundForObj(g.quantity,getDecimal("glj.quantity"));
  807. let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity,processDecimal);//市场价
  808. let rt = scMathUtil.roundForObj(quantity * g.basePrice * rationQuantity,processDecimal);//定额价
  809. if(g.type == gljUtil.gljType.LABOUR) laberSum = scMathUtil.roundForObj(laberSum+rt,processDecimal);
  810. if(gljUtil.getMainType(g.type) == 3) machineSum = scMathUtil.roundForObj(machineSum+rt,processDecimal);
  811. result = scMathUtil.roundForObj(result + t,processDecimal);
  812. }
  813. let as = scMathUtil.roundForObj(laberSum * assFeeRate,processDecimal);//人工消耗量*定额价*定额工程量*辅助生产间接费费率
  814. let tt = scMathUtil.roundForObj(laberSum + machineSum,processDecimal);//人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量
  815. let hs = scMathUtil.roundForObj(tt*hightFeeRate,processDecimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
  816. result = scMathUtil.roundForObj(as + result,processDecimal);
  817. result = scMathUtil.roundForObj(hs + result,processDecimal);
  818. }
  819. return result;
  820. }
  821. };
  822. ProjectGLJ.prototype.calcMaterialAssQuantity = function (parent,ration,newAssList) {
  823. let updateList = [];
  824. let assList = calcAssList(newAssList);
  825. for(let glj of parent.ration_gljs){
  826. if(glj.rationID == ration.ID){
  827. updateList.push(calcAssGljQuantity(glj,assList));
  828. }
  829. }
  830. return updateList;
  831. function calcAssGljQuantity(g,assList) {
  832. g.quantity = scMathUtil.roundForObj(g.rationItemQuantity,getDecimal("glj.quantity"));
  833. for(let a of assList){
  834. let ass = a.ass;
  835. let matchGlj = null;
  836. for(let aglj of ass.rationGljList){
  837. if(aglj.gljId == g.GLJID){
  838. matchGlj = aglj;
  839. break;
  840. }
  841. }
  842. if(matchGlj){
  843. let calQuantity =scMathUtil.roundForObj(matchGlj.consumeAmt*a.times,6);
  844. g.quantity = scMathUtil.roundForObj(calQuantity + g.quantity,getDecimal("glj.quantity"))+"";
  845. }
  846. }
  847. return {ID:g.ID,quantity:g.quantity}
  848. }
  849. function calcAssList(rationAssList){
  850. let calAss = [];
  851. for(let ass of rationAssList){
  852. let times = calculateTimes(ass);
  853. if(times!=0){
  854. calAss.push({ass:ass.assRation,times:times});
  855. }
  856. }
  857. return calAss;
  858. }
  859. function calculateTimes(ass){
  860. if(ass.name != "运距m") return 0;//只计算运距;
  861. let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
  862. let r = false;
  863. if(times<0){
  864. r=true;
  865. times=times*-1;
  866. }
  867. if(ass.carryBit=='四舍五入'){
  868. times = _.round(times,ass.decimal);
  869. }else if (ass.carryBit=='进一'){
  870. times =_.ceil(times,ass.decimal);
  871. }else if(ass.carryBit == '舍一'){
  872. times = _.floor(times,ass.decimal);
  873. }
  874. if(r){
  875. times=times*-1;
  876. }
  877. return scMathUtil.roundTo(times,-6);
  878. }
  879. };
  880. ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的运费或者原价
  881. let lists = type == "freight"?this.datas.freightList:this.datas.originalList;
  882. let temp = _.find(lists,{ID:ID});
  883. if(temp){
  884. let task = this.calcEachFreightOrPrice(temp,type);
  885. let material = materialCalcObj.getMaterialSelected();
  886. if(task && material){
  887. if(type == "freight") projectObj.project.projectGLJ.updateFreightCalc([task],material.id);
  888. if(type == "price") projectObj.project.projectGLJ.updatePriceCalc([task],material.id);
  889. }
  890. }
  891. };
  892. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  893. let map = {};
  894. map[ID] = true;
  895. await this.updateMaterialCalcTasks(pgljID,ID,"delete","price");
  896. };
  897. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  898. let map = {};
  899. map[ID] = true;
  900. await this.updateMaterialCalcTasks(pgljID,map,"delete","freight");
  901. };
  902. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  903. let me = this;
  904. let projectGljs = this.datas.gljList;
  905. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  906. let glj = _.find(projectGljs, {'id': pgljID});
  907. if (glj) {
  908. if(glj.unit_price[updateField] == newval){
  909. return;
  910. }
  911. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  912. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id,unit_price_file_id:glj.unit_price.unit_price_file_id};
  913. let callback = function (data) {
  914. if (updateField == 'base_price') {
  915. glj.unit_price.base_price = newval;
  916. me.setAdjustPrice(glj);
  917. } else {
  918. glj.unit_price.market_price = newval;
  919. }
  920. //更新回传的父节点项目工料机价格
  921. let gljs = me.getProjectGLJs(data);
  922. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  923. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  924. gljOprObj.showRationGLJSheetData();
  925. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  926. gljs.push(glj);
  927. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  928. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  929. projectGljObject.onUnitFileChange(data);
  930. if(cb){
  931. cb(gljs);
  932. }
  933. $.bootstrapLoading.end();
  934. }
  935. $.bootstrapLoading.start();
  936. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  937. $.bootstrapLoading.end();
  938. });
  939. } else {
  940. gljOprObj.showRationGLJSheetData();
  941. }
  942. };
  943. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  944. let me = this;
  945. //更新是否暂估和供货方式时,要做特殊处理
  946. $.bootstrapLoading.start();
  947. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  948. $.bootstrapLoading.end();
  949. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  950. for(let idKey in updateMap){
  951. let gljID = parseInt(idKey);
  952. let glj = me.getByID(gljID);
  953. let doc = updateMap[idKey];
  954. for(let property in doc){
  955. glj[property] = doc[property];
  956. }
  957. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  958. supplyChangeIDs.push(gljID);
  959. }
  960. if(doc.hasOwnProperty("is_evaluate")){
  961. evaluate_gljs.push(glj);
  962. }
  963. }
  964. if(supplyChangeIDs.length>0){
  965. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  966. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  967. }
  968. if(evaluate_gljs.length > 0){
  969. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  970. rationNodes = rationNodes.concat(impactRationNodes);
  971. }
  972. if(rationNodes.length > 0){
  973. rationNodes = _.uniq(rationNodes,'data');
  974. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  975. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  976. });
  977. }
  978. if(callback){
  979. callback();
  980. }
  981. })
  982. };
  983. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  984. let me = this;
  985. let projectGljs = me.datas.gljList;
  986. let updateData = [];
  987. let newValueMap = {};
  988. let gljs=[];
  989. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  990. if(changeInfo.length<=0){
  991. callback?callback():'';
  992. return
  993. }
  994. for(let ci of changeInfo){
  995. let dataCode = setting.header[ci.col].dataCode;
  996. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  997. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  998. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  999. let glj = _.find(projectGljs, {'id': recode.id});
  1000. let newValue = ci.value;
  1001. if(glj&&glj.unit_price[editField]!=newValue){
  1002. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  1003. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  1004. newValueMap[glj.id]={field:editField,value:newValue};
  1005. gljs.push(glj);
  1006. }
  1007. }
  1008. }
  1009. if(updateData.length > 0){
  1010. $.bootstrapLoading.start();
  1011. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  1012. let parentData = [];
  1013. //更新缓存
  1014. for(let g of gljs){
  1015. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  1016. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  1017. }
  1018. //更新父工料机价格
  1019. for(let r of result){
  1020. let pdata = r.updateOne.filter;
  1021. let set = r.updateOne.update.$set;
  1022. for(let skey in set){
  1023. pdata[skey] = set[skey];
  1024. }
  1025. parentData.push(pdata);
  1026. }
  1027. let pgljs = me.getProjectGLJs(parentData);
  1028. gljs = gljs.concat(pgljs);
  1029. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1030. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1031. gljOprObj.showRationGLJSheetData();
  1032. projectGljObject.onUnitFileChange(gljs);
  1033. if(callback){
  1034. callback(gljs);
  1035. }
  1036. $.bootstrapLoading.end();
  1037. }, function (err) {
  1038. $.bootstrapLoading.end();
  1039. });
  1040. }
  1041. };
  1042. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  1043. let me = this;
  1044. $.bootstrapLoading.start();
  1045. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  1046. let parent = updateData[updateData.length - 1];
  1047. let parentGlj = me.getByConKey(parent.connect_key);
  1048. for(let u of updateData){
  1049. if(u.type == 'mix_ratio'){
  1050. let tem = updateMap[u.query.id];
  1051. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  1052. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  1053. if(subData){
  1054. subData.consumption = u.doc.consumption;
  1055. }
  1056. let m_list = me.datas.mixRatioMap[parent.connect_key];
  1057. let m_ratioData = _.find(m_list,{"id":u.query.id});
  1058. if(m_ratioData){
  1059. m_ratioData.consumption = u.doc.consumption;
  1060. }
  1061. }
  1062. }
  1063. parentGlj.unit_price.market_price = parent.market_price;
  1064. parentGlj.unit_price.base_price = parent.base_price;
  1065. me.calcQuantity();
  1066. if(callback){
  1067. callback();
  1068. }
  1069. $.bootstrapLoading.end();
  1070. },function () {
  1071. $.bootstrapLoading.end();
  1072. })
  1073. };
  1074. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  1075. let me = this;
  1076. $.bootstrapLoading.start();
  1077. CommonAjax.specialPost( '/glj/update',data,function (result) {
  1078. let glj = me.getByID(data.id);//更新缓存
  1079. let impactList = [];
  1080. glj[data.field] = data.value;
  1081. if(data.extend&&data.extend!=""){
  1082. let extend = JSON.parse(data.extend);
  1083. for (let key in extend) {
  1084. glj[key] = extend[key];
  1085. }
  1086. }
  1087. if(data.field == 'is_evaluate'){
  1088. impactList = me.changeIsEvaluate(data.id);
  1089. }
  1090. if(callback){
  1091. callback(impactList);
  1092. }
  1093. $.bootstrapLoading.end();
  1094. });
  1095. };
  1096. ProjectGLJ.prototype.getRatioData=function(id,callback){
  1097. this.getRatioId = id;
  1098. if(id){
  1099. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  1100. let ratios = JSON.parse(response.data);
  1101. if(callback){
  1102. callback(ratios);
  1103. }
  1104. },function () {//取不到组成物的情况
  1105. callback([]);
  1106. })
  1107. }else {
  1108. if(callback){
  1109. callback([]);
  1110. }
  1111. }
  1112. };
  1113. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  1114. $.bootstrapLoading.start();
  1115. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  1116. projectObj.project.property.unitPriceFile = response.unitFile;
  1117. projectObj.project.projectGLJ.loadData(function () {
  1118. if(callback){
  1119. callback();
  1120. }
  1121. $.bootstrapLoading.end();
  1122. });
  1123. }, function (err) {
  1124. if($.bootstrapLoading.isLoading()){
  1125. $.bootstrapLoading.end();
  1126. }
  1127. alert(err.msg);
  1128. });
  1129. };
  1130. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  1131. $.bootstrapLoading.start();
  1132. try {
  1133. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  1134. await this.synLoadData();
  1135. projectGljObject.refreshDataSheet();
  1136. gljOprObj.refreshView();
  1137. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  1138. projectGljObject.onUnitFileChange();
  1139. }catch (err){
  1140. console.log(err);
  1141. }finally {
  1142. $.bootstrapLoading.end();
  1143. }
  1144. };
  1145. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  1146. let gljList = [],allGLJ = gljOprObj.AllRecode;
  1147. if(selections.length == 0) {
  1148. return;
  1149. }
  1150. for(let glj of allGLJ){
  1151. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  1152. if(_.includes(selections,i_key)){
  1153. let pglj = {
  1154. project_id: projectObj.project.ID(),
  1155. glj_id: glj.ID,
  1156. name: glj.name,
  1157. code: glj.code,
  1158. original_code: glj.code,
  1159. unit: glj.unit,
  1160. specs: glj.specs,
  1161. base_price: glj.basePrice,
  1162. market_price: glj.basePrice,
  1163. shortName: glj.shortName,
  1164. type: glj.gljType,
  1165. model:glj.model,
  1166. adjCoe: glj.adjCoe,
  1167. from:'std',
  1168. repositoryId:glj.repositoryId,
  1169. materialType:glj.materialType,
  1170. materialCoe:glj.materialCoe,
  1171. grossWeightCoe:glj.grossWeightCoe,
  1172. purchaseStorageRate:glj.purchaseStorageRate,
  1173. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  1174. handlingLossRate:glj.handlingLossRate
  1175. };
  1176. if (glj.hasOwnProperty("compilationId")) {
  1177. pglj.from = "cpt";
  1178. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  1179. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  1180. }
  1181. }
  1182. gljList.push(pglj);
  1183. }
  1184. }
  1185. gljList = _.sortByAll(gljList, ['type', 'code']);
  1186. if(gljList.length == 0) return;
  1187. let praentInfo = {
  1188. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  1189. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  1190. };
  1191. $.bootstrapLoading.start();
  1192. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  1193. $.bootstrapLoading.end();
  1194. if(callback){
  1195. callback(data);
  1196. }
  1197. }, function () {
  1198. $.bootstrapLoading.end();
  1199. });
  1200. }
  1201. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  1202. let property = projectObj.project.projectInfo.property;
  1203. let data = {
  1204. name:newVal,
  1205. rootProjectID:property.rootProjectID
  1206. }
  1207. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  1208. callback(data);
  1209. });
  1210. };
  1211. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  1212. $.bootstrapLoading.start();
  1213. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  1214. projectObj.project.projectGLJ.loadData(function () {
  1215. if(callback){
  1216. callback();
  1217. }
  1218. $.bootstrapLoading.end();
  1219. });
  1220. },function (response) {
  1221. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  1222. $("#save-as-tips").text(msg).show();
  1223. $.bootstrapLoading.end();
  1224. });
  1225. };
  1226. //更新是否暂估
  1227. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  1228. let projectGLJ = projectObj.project.projectGLJ;
  1229. let datas = projectGLJ.datas;
  1230. let gljList = datas.gljList;
  1231. let glj = _.find(gljList, {'id': id});
  1232. if(glj){//与批量更新调用相同的方法
  1233. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1234. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  1235. let conditions = [];
  1236. if(pratioM&&pratioM.length>0){
  1237. for(let p_key of pratioM ){
  1238. conditions.push(gljOprObj.getConditionByKey(p_key));
  1239. }
  1240. }
  1241. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  1242. gljs.push(glj);
  1243. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1244. //更新对应的工料机类型的定额
  1245. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  1246. let ration_nodes = [];
  1247. for(r of rations){
  1248. if(r){
  1249. r.isEstimate =glj.is_evaluate?1:0;
  1250. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  1251. ration_node?ration_nodes.push(ration_node):'';
  1252. }
  1253. }
  1254. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  1255. for(rg of ration_glj_nodes){
  1256. rg.data.isEstimate =glj.is_evaluate?1:0;
  1257. ration_nodes.push(rg);
  1258. }
  1259. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  1260. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  1261. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1262. return gljs;
  1263. }
  1264. };
  1265. /**
  1266. * 批量更新是否暂估
  1267. *传入项目工料机数组
  1268. */
  1269. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  1270. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  1271. for(let glj of gljs){
  1272. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1273. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  1274. let conditions = [];
  1275. if(pratioM&&pratioM.length>0){
  1276. for(let p_key of pratioM ){
  1277. conditions.push(gljOprObj.getConditionByKey(p_key));
  1278. }
  1279. }
  1280. let tem_gljs = this.getProjectGLJs(conditions,false);
  1281. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  1282. }
  1283. impactGLJs = impactGLJs.concat(gljs);
  1284. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  1285. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  1286. let neeRefreshNode = [];
  1287. //更新对应的工料机类型的定额
  1288. for(let item of projectObj.project.Ration.datas){
  1289. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  1290. let tem_g = changeMap[item.projectGLJID];
  1291. item.isEstimate =tem_g.is_evaluate?1:0;
  1292. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  1293. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  1294. }
  1295. }
  1296. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1297. for(let rg of ration_glj_nodes){
  1298. let tem_g = changeMap[rg.data.projectGLJID];
  1299. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1300. neeRefreshNode.push(rg);
  1301. }
  1302. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1303. return [impactRationNodes,impactGLJs];
  1304. };
  1305. ProjectGLJ.prototype.getByID = function (ID) {
  1306. return _.find(this.datas.gljList,{'id':ID});
  1307. };
  1308. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1309. return _.find(this.datas.gljList,function (item) {
  1310. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1311. return tem_key == conkey
  1312. })
  1313. };
  1314. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1315. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1316. let me = this;
  1317. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1318. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1319. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1320. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1321. return true;
  1322. }
  1323. })
  1324. projectObj.mainController.refreshTreeNode(nodes);
  1325. }
  1326. }
  1327. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1328. let nodes = [];
  1329. let ids = [];
  1330. if(Array.isArray(id)){
  1331. ids = id;
  1332. }else {
  1333. ids = [id];
  1334. }
  1335. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1336. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1337. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1338. })
  1339. }
  1340. return nodes;
  1341. };
  1342. //根据工料机,取得所有受影响的定额节点
  1343. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1344. let nodes = [];
  1345. let rationMap = {};
  1346. let idArray = _.map(gljs,'id');
  1347. let gljMap = _.indexBy(gljs,'id');
  1348. //先根据项目工料机ID,找到受影响定额的ID
  1349. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1350. for (let rg of ration_glj_list) {
  1351. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1352. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1353. }
  1354. }
  1355. for (let item of projectObj.project.mainTree.items) {
  1356. if (item.sourceType == ModuleNames.ration) {
  1357. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1358. let tem_g = gljMap[item.data.projectGLJID];
  1359. if(tem_g){
  1360. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1361. item.data.marketPrice = this.getMarketPrice(tem_g);
  1362. nodes.push(item);
  1363. }
  1364. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1365. nodes.push(item)
  1366. }
  1367. }
  1368. }
  1369. return nodes;
  1370. };
  1371. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1372. for (let ration_glj of gljOprObj.sheetData) {
  1373. if (ration_glj.projectGLJID == glj.id) {
  1374. ration_glj.basePrice = this.getBasePrice(glj);
  1375. ration_glj.marketPrice = this.getMarketPrice(glj);
  1376. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1377. }
  1378. }
  1379. }
  1380. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1381. }
  1382. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1383. let parentGlj = [];
  1384. //
  1385. let projectGljs = this.datas.gljList;
  1386. let indexList = gljKeyArray;
  1387. for (let d of data) {
  1388. if (d) {
  1389. let glj = _.find(projectGljs, function (item) {
  1390. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1391. });
  1392. if (glj) {
  1393. if(refreshPrice==true){
  1394. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1395. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1396. this.setAdjustPrice(glj);
  1397. this.refreshRationGLJPrice(glj);
  1398. this.refreshTreeNodePriceIfNeed(glj);
  1399. }
  1400. parentGlj.push(glj);
  1401. }
  1402. }
  1403. }
  1404. return parentGlj;
  1405. }
  1406. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1407. switch (glj.unit_price.type + '') {
  1408. // 人工: 调整基价=基价单价*调整系数
  1409. case GLJTypeConst.LABOUR:
  1410. case GLJTypeConst.MACHINE_LABOUR:
  1411. glj.adjust_price = this.getAdjustPrice(glj);
  1412. break;
  1413. // 机械类型的算法
  1414. case GLJTypeConst.MACHINE:
  1415. console.log('机械');
  1416. break;
  1417. // 材料、主材、设备
  1418. default:
  1419. glj.adjust_price = glj.unit_price.base_price;
  1420. }
  1421. }
  1422. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1423. let proGLJ = projectObj.project.projectGLJ;
  1424. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1425. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1426. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1427. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1428. };
  1429. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1430. let proGLJ = projectObj.project.projectGLJ;
  1431. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1432. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1433. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1434. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1435. };
  1436. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1437. let proGLJ = projectObj.project.projectGLJ;
  1438. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1439. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1440. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1441. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1442. };
  1443. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1444. let proGLJ = projectObj.project.projectGLJ;
  1445. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1446. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1447. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1448. let tenderCoe = 1;
  1449. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1450. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1451. }
  1452. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1453. };
  1454. ProjectGLJ.prototype.isEstimateType = function(type){
  1455. let typeString = type + "";
  1456. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1457. return type;
  1458. }
  1459. return false;
  1460. };
  1461. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1462. let gljTypeMap = this.datas.constData.gljTypeMap;
  1463. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1464. };
  1465. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1466. let project_gljs = this.datas.gljList;
  1467. let changeArray=[];
  1468. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1469. let rationDatas = projectObj.project.Ration.datas;
  1470. let billsDatas = projectObj.project.Bills.datas;
  1471. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1472. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1473. this.quantityChangeMap = {};
  1474. for(let pglj of project_gljs){
  1475. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1476. }
  1477. }else if(this.quantityChangeMap != null){
  1478. for(let pglj of project_gljs){
  1479. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1480. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1481. changeArray.push(pglj);
  1482. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1483. }
  1484. }else { //映射表没有,说明是新添加的项目工料机
  1485. changeArray.push(pglj);
  1486. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1487. }
  1488. }
  1489. }
  1490. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1491. };
  1492. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1493. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1494. let rationDatas = projectObj.project.Ration.datas;
  1495. let billsDatas = projectObj.project.Bills.datas;
  1496. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1497. };