project_glj.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  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.getCalcMaterialUpdateData = function(projectGLJ,updateField,value,ext){//只有添加、删除走这个方法
  263. let glj = _.find(this.datas.gljList,{'id':projectGLJ.id});
  264. if(!glj) return null;
  265. if(glj.unit_price[updateField] == value){
  266. return null;
  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. return {data:data,glj:glj}
  288. }
  289. ProjectGLJ.prototype.updateCalcMaterials = async function(projectGLJs,value) {//只有添加、删除走这个方法
  290. let updateField = 'calcMaterial';
  291. let datas = [];
  292. let dataMaps = [];
  293. for(let p of projectGLJs){
  294. let map = this.getCalcMaterialUpdateData(p,updateField,value);
  295. if(map){
  296. datas.push(map.data);
  297. dataMaps.push(map);
  298. }
  299. }
  300. if(datas.length == 0) return;
  301. $.bootstrapLoading.start();
  302. try {
  303. let result = await ajaxPost('/glj/updateCalcMaterial',datas);
  304. let calcQ = false;
  305. for(let dm of dataMaps){
  306. let glj = dm.glj;
  307. glj.unit_price[updateField] = value;
  308. if(dm.data.ext) gljUtil.setProperty(glj.unit_price,);
  309. if(updateField == 'calcMaterial' && value ==0){///标记为0即删除材料计算标记,要删除其下挂的原价计算,运费计算,定额计算,消耗量重新计算
  310. calcQ = true;
  311. let connect_key = gljUtil.getIndex(glj);
  312. _.remove(this.datas.originalList,{'connect_key':connect_key});
  313. _.remove(this.datas.freightList,{'connect_key':connect_key});
  314. }
  315. }
  316. if(calcQ) this.calcQuantity();
  317. projectGljObject.refreshDataSheet();
  318. materialCalcObj.showDatas();
  319. } catch (e){
  320. console.log(e)
  321. }finally {
  322. $.bootstrapLoading.end();
  323. }
  324. };
  325. ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,value) {//只有添加、删除走这个方法
  326. this.updateCalcMaterials([projectGLJ],value);
  327. };
  328. ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs,needReCalc) {//当材料发生改变时重算所有计算材料的价格
  329. let priceMap = {};
  330. for(let unitPrice of unitPriecs){
  331. if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
  332. }
  333. let freightListMap = _.groupBy(this.datas.freightList,'connect_key');//取运费计算项映射表
  334. let originalListMap = _.groupBy(this.datas.originalList,'connect_key');//取原价计算项映射表
  335. let sumFreightUpdateMap = {}; //存放所有材料下的运费更新信息;
  336. let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
  337. for(let g of this.datas.gljList){
  338. if(g.quantity !== 0 && g.quantity !== '0' && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
  339. //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
  340. let fOrPDataMap = {};
  341. let tIndex = gljUtil.getIndex(g);
  342. //运费和原价中的工料机只要有一个包含该材料,就要重算
  343. if(freightListMap[tIndex]){ //运费重算
  344. let freightUpdateMap = {};
  345. for(let f of freightListMap[tIndex]){
  346. if(f.conveyance != "自办运输") continue;//不是自办运输的不用管
  347. let calf = ifNeedReCalc(f,priceMap,needReCalc);
  348. if(calf){
  349. let f_task = this.calcEachFreightOrPrice(f,"freight",priceMap);
  350. if(f_task){
  351. freightUpdateMap[f_task.ID] = f_task.doc;
  352. sumFreightUpdateMap[f_task.ID] = f_task.doc;
  353. }
  354. }
  355. }
  356. if(!_.isEmpty(freightUpdateMap)) fOrPDataMap["freight"] = {update:freightUpdateMap};
  357. }
  358. //原价重算
  359. if(originalListMap[tIndex]){ //运费重算
  360. let originalUpdateMap = {};
  361. for(let o of originalListMap[tIndex]){
  362. let calo = ifNeedReCalc(o,priceMap,needReCalc);
  363. if(calo){
  364. let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
  365. if(o_task){
  366. originalUpdateMap[o_task.ID] = o_task.doc;
  367. sumOriginalUpdateMap[o_task.ID] = o_task.doc;
  368. }
  369. }
  370. }
  371. if(!_.isEmpty(originalUpdateMap)) fOrPDataMap["price"] = {update:originalUpdateMap};
  372. }
  373. //判断映射表是否为空,如果为空则说明不用计算
  374. if(!_.isEmpty(fOrPDataMap)){
  375. let t_unipPrice = this.materialCal(g.id,fOrPDataMap,g,freightListMap[tIndex],originalListMap[tIndex]);
  376. if(t_unipPrice && !_.isEmpty(t_unipPrice.doc)) unitPriecs.push(t_unipPrice);
  377. }
  378. }
  379. }
  380. let sumUpdateMap = {};
  381. if(!_.isEmpty(sumFreightUpdateMap))sumUpdateMap["freight"] = {update:sumFreightUpdateMap};
  382. if(!_.isEmpty(sumOriginalUpdateMap))sumUpdateMap["price"] = {update:sumOriginalUpdateMap};
  383. let ext = {};
  384. for(let u of unitPriecs){//计算受影响的综合电价
  385. ext[u.projectGLJID] = {marketPrice:u.doc.market_price}; //priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
  386. }
  387. let elecu = electrovalenceObj.clacNewElecPrice(ext);
  388. if(elecu) unitPriecs.push(elecu);
  389. return [unitPriecs,sumUpdateMap];
  390. function ifNeedReCalc(obj,IDMap,needReCalc = false) {
  391. let calcf = false;
  392. if(needReCalc == true) return true;//如果是通过修改费率等地方触发的,默认自动计算
  393. if(obj.ration_gljs){
  394. for(let rg of obj.ration_gljs){
  395. if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
  396. calcf = true;
  397. break;
  398. }
  399. }
  400. }
  401. return calcf;
  402. }
  403. };
  404. ProjectGLJ.prototype.materialCal = function (id,dataMap,tglj,tfreightList,tpriceList) {
  405. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  406. let unitPirceDecimal = getDecimal("glj.unitPrice");
  407. let process = getDecimal("process");
  408. let glj = tglj?tglj: _.find(this.datas.gljList,{'id':id});
  409. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  410. if(!glj) return;
  411. let unitPrice = {projectGLJID:glj.id,id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  412. //先计算原价
  413. let [originalPrice,supplyLocation,priceHeightFee] = this.priceCalc(glj,dataMap,tpriceList);
  414. doc['originalPrice'] = originalPrice+'';
  415. doc['supplyLocation'] = supplyLocation;
  416. doc['priceHeightFee'] = priceHeightFee;
  417. //再计算运费
  418. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  419. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  420. let [unitFreight,freightHeightFee] = this.freightCalc(glj,grossWeightCoe_n,dataMap,tfreightList);
  421. doc['unitFreight'] = unitFreight+'';
  422. doc['freightHeightFee'] = freightHeightFee+'';
  423. //计算场外运输损耗
  424. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  425. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  426. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  427. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  428. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  429. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  430. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  431. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  432. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  433. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  434. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  435. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  436. //计算采购及保管费
  437. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  438. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  439. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  440. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  441. doc['purchaseStorage'] = purchaseStorage+'';
  442. //再计算预算价
  443. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  444. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  445. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  446. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  447. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  448. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  449. let o_unit = glj.unit_price;
  450. for(let key in doc){
  451. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  452. unitPrice.doc[key] = doc[key];
  453. }
  454. return unitPrice
  455. };
  456. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreightList) {
  457. let process = getDecimal("process");
  458. let unitPirce = getDecimal("glj.unitPrice");
  459. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  460. let sum = 0;
  461. let height_sum=0;
  462. let freightList = tfreightList?tfreightList:_.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  463. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  464. for(let f of freightList){
  465. 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;
  466. let heightFee= f.heightFee?f.heightFee:0;
  467. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  468. let t = dataMap["freight"]["update"][f.ID];
  469. if(t){
  470. if(t['unitFreight']) unitFreight = t['unitFreight'];
  471. if(t['kmDistance']) kmDistance = t['kmDistance'];
  472. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  473. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  474. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  475. if(t['otherFee']) otherFee = t['otherFee'];
  476. if(t['weightCoe']) weightCoe = t['weightCoe'];
  477. if(t['conveyance']) conveyance = t['conveyance'];
  478. if(t['calcType']) calcType = t['calcType'];
  479. if(t['materialType']) materialType = t['materialType'];
  480. if(t['heightFee']) heightFee = t['heightFee'];
  481. }
  482. }
  483. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  484. if(dataMap["freight"]["delete"][f.ID]) continue;
  485. }
  486. //开始计算
  487. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  488. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  489. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  490. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  491. heightFee = scMathUtil.roundForObj(heightFee,unitPirce);
  492. let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
  493. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  494. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  495. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  496. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  497. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  498. if(gljUtil.isDef(materialType)&&materialType != "") t = scMathUtil.roundForObj(t/1.09,process); //内蒙古要除以税率1.09; 当材料类型有值时,说明是内蒙古计算
  499. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  500. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  501. if(conveyance !== "自办运输") t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  502. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  503. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  504. sum = scMathUtil.roundForObj(sum + t,process);
  505. heightFee = scMathUtil.roundForObj(heightFee*weightCoe,process);
  506. height_sum = scMathUtil.roundForObj(height_sum + heightFee,process);
  507. }
  508. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  509. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  510. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  511. }
  512. return [scMathUtil.roundForObj(sum,unitPirce),scMathUtil.roundForObj(height_sum,unitPirce)];
  513. function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
  514. if(gljUtil.isDef(materialType)&&materialType != "") return materialCalcObj.calNeiMengTotalFreight(kmDistance,materialType);
  515. //如果运输方式为自办运输,则直接返回单位运价即可;
  516. let price = conveyance == "自办运输" ? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  517. return price
  518. }
  519. };
  520. ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
  521. let process = getDecimal("process");
  522. let unitPirce = getDecimal("glj.unitPrice");
  523. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  524. let original_price = 0;
  525. let sumFeightFee = 0;
  526. let supplyList = [];
  527. let supplyLocation = "";
  528. let priceList = tpriceList?tpriceList:_.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  529. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  530. for(let p of priceList){
  531. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  532. let heightFee = p.heightFee?p.heightFee:0;
  533. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  534. let t = dataMap["price"]["update"][p.ID];
  535. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  536. if(t && t["coe"]) coe =t["coe"];
  537. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  538. if(t && t["heightFee"]) heightFee = t["heightFee"];
  539. }
  540. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  541. if(dataMap["price"]["delete"][p.ID]) continue;
  542. }
  543. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  544. coe = scMathUtil.roundForObj(coe,unitPirce);
  545. heightFee = scMathUtil.roundForObj(heightFee,unitPirce);
  546. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  547. let t_h = scMathUtil.roundForObj(heightFee * coe,process);
  548. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  549. sumFeightFee = scMathUtil.roundForObj(sumFeightFee+t_h,process);
  550. supplyList.push(supplyLocation);
  551. }
  552. supplyLocation = supplyList.join(',');
  553. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  554. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  555. original_price = doc['originalPrice']!==undefined?doc['originalPrice']:glj.unit_price.originalPrice;
  556. supplyLocation = doc['supplyLocation']!==undefined?doc['supplyLocation']:glj.unit_price.supplyLocation;
  557. }
  558. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation,scMathUtil.roundForObj(sumFeightFee,unitPirce)];
  559. };
  560. ProjectGLJ.prototype.m_updateUnitPrice = function (datas,isFromFeeRate=false) {//批量更新
  561. let me = this;
  562. let gljList = [];
  563. for(let d of datas){
  564. let g = updateUnit(d.projectGLJID,d);
  565. if(g) gljList.push(g);
  566. }
  567. if(isFromFeeRate == false)this.calcQuantity();
  568. //刷新项目工料机表显示
  569. projectGljObject.refreshDataSheet();
  570. //重新计算相关节点
  571. /* 2019-10-29 这里改成修改材料计算后先不自动计算,先在项目属性上做标记,切换到其它标签页时才做自动计算
  572. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  573. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  574. */
  575. //刷新定额工料机
  576. gljOprObj.refreshView();
  577. //socket推送更新信息
  578. projectGljObject.onUnitFileChange(isFromFeeRate?false:true);//如果是从更新费率过来的,不用在项目属性上做标记,费率那里已经自动计算所有节点了
  579. return gljList
  580. function updateUnit(id,unitPrice) {
  581. let glj = _.find(me.datas.gljList,{'id':id});
  582. if(glj && !_.isEmpty(unitPrice.doc)){
  583. for(let key in unitPrice.doc){
  584. glj.unit_price[key] = unitPrice.doc[key];
  585. }
  586. }
  587. return glj;
  588. }
  589. };
  590. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  591. this.m_updateUnitPrice([unitPrice]);
  592. };
  593. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  594. await this.updateMaterialCalcTasks(pgljID,datas,"add","price");
  595. };
  596. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  597. let updateDatas=[];
  598. try {
  599. for(let d of datas){
  600. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  601. if(_.isEmpty(unitPrice.doc)) continue;
  602. updateDatas.push(unitPrice);
  603. }
  604. if(updateDatas.length ==0 ) return;
  605. let [unitPrices,sumMap] = this.calcAllMaterial(updateDatas);
  606. sumMap = {"unitPrice":unitPrices};
  607. $.bootstrapLoading.start();
  608. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  609. this.refreshMaterialCalcCache(sumMap);
  610. materialCalcObj.showDatas();
  611. }catch (e){
  612. console.log(e)
  613. }finally {
  614. $.bootstrapLoading.end();
  615. }
  616. };
  617. ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
  618. //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表;
  619. try {
  620. let actionMap={};
  621. let calMap = {};
  622. actionMap[actionType] = dataMap;
  623. calMap[model] = actionMap;//{freight:{update:updateMap}
  624. let unitPrice = this.materialCal(pgljID,calMap);//计算当前这一条材料
  625. let [unitPrices,sumMap] = this.calcAllMaterial([unitPrice]);//计算完一条材料后,还要计算因为这条材料而受影响的其它所有材料
  626. if(actionType == "update") {//更新情况
  627. if (sumMap[model] && sumMap[model][actionType]) {//这一步,合并需要提交后台修改的数据
  628. let tt = sumMap[model][actionType];
  629. for(let key in dataMap) {
  630. tt[key] = dataMap[key];
  631. }
  632. } else {
  633. sumMap[model] = actionMap;
  634. }
  635. }else {
  636. sumMap[model] = actionMap;
  637. }
  638. sumMap["unitPrice"] = unitPrices;
  639. $.bootstrapLoading.start();
  640. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  641. this.refreshMaterialCalcCache(sumMap);
  642. materialCalcObj.showDatas();
  643. }catch (e){
  644. console.log(e)
  645. }finally {
  646. $.bootstrapLoading.end();
  647. }
  648. };
  649. ProjectGLJ.prototype.updateUserFreight =async function (data) {
  650. try {
  651. $.bootstrapLoading.start();
  652. let result = await ajaxPost('/glj/updateUserFreight',data);
  653. if(data.action == "add"){
  654. for(let f of data.freights){
  655. materialCalcObj.userFreightList.push(f);
  656. }
  657. }
  658. if(data.action == "update"){
  659. for(let u of materialCalcObj.userFreightList){
  660. if(u.ID == data.ID){
  661. gljUtil.updateProperty(u,data.doc);
  662. }
  663. }
  664. }
  665. materialCalcObj.showFreightDatas();
  666. }catch (e){
  667. console.log(e)
  668. }finally {
  669. $.bootstrapLoading.end();
  670. }
  671. };
  672. ProjectGLJ.prototype.getUserFreights = async function () {//初始化车船税选择
  673. try {
  674. let result = await ajaxGet("/glj/getUserFreights");
  675. return result;
  676. }catch (e){
  677. console.log(e)
  678. }
  679. };
  680. ProjectGLJ.prototype.refreshEctrovalenceCache = function (updateMap) {
  681. let elec = updateMap["electrovalence"];
  682. if(elec){
  683. let actionType = elec.actionType;
  684. if(actionType == "add"){
  685. projectObj.project.projectGLJ.datas.com_electrovalence = elec.doc;
  686. }else if(actionType == "update"){
  687. projectObj.project.projectGLJ.datas.com_electrovalence.gljList = elec.doc.gljList;
  688. }
  689. }
  690. if(updateMap["unitPrice"]) {
  691. if(Array.isArray(updateMap["unitPrice"])){
  692. this.m_updateUnitPrice(updateMap["unitPrice"]);
  693. }else {
  694. this.m_updateUnitPrice([updateMap["unitPrice"]]);
  695. }
  696. }
  697. };
  698. ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap,isFromFeeRate = false){//从费率计算过来的时候,费率那里已经做了自动计算所有节点了
  699. let gljList = [];
  700. if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
  701. if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
  702. if(updateMap["unitPrice"]) {
  703. if(Array.isArray(updateMap["unitPrice"])){
  704. gljList = this.m_updateUnitPrice(updateMap["unitPrice"],isFromFeeRate);
  705. }else {
  706. gljList = this.m_updateUnitPrice([updateMap["unitPrice"]],isFromFeeRate);
  707. }
  708. }
  709. return gljList;
  710. function updateList(list,updateMap) {
  711. if(updateMap["update"]){
  712. let map = updateMap["update"];
  713. for(let o of list){
  714. if(map[o.ID]){
  715. gljUtil.updateProperty(o,map[o.ID]);
  716. }
  717. }
  718. }
  719. if(updateMap["add"]){
  720. for(let a of updateMap["add"]){
  721. list.push(a);
  722. }
  723. }
  724. if(updateMap["delete"]){
  725. for(let ID in updateMap["delete"]){
  726. _.remove(list,{'ID':ID});
  727. }
  728. }
  729. }
  730. };
  731. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  732. let updateMap = {};
  733. for(let d of datas){
  734. updateMap[d.ID] = d.doc;
  735. }
  736. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","price");
  737. };
  738. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  739. await this.updateMaterialCalcTasks(pgljID,datas,"add","freight");
  740. };
  741. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  742. let updateMap = {};
  743. for(let d of datas){
  744. updateMap[d.ID] = d.doc;
  745. }
  746. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
  747. };
  748. ProjectGLJ.prototype.addMaterialRation = async function (code,type,parentID,connect_key){
  749. let libIDs = rationLibObj.getStdRationLibIDs();
  750. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  751. let selectedLib = sessionStorage.getItem("stdRationLib");
  752. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  753. 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()};
  754. datas.actionType="add";
  755. await this.updateMaterialRation(datas);
  756. };
  757. ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate) {
  758. $.bootstrapLoading.start();
  759. try {
  760. await ajaxPost("/glj/changeAssistProductionFeeRate",{unitFileID:projectObj.project.property.unitPriceFile.id,assistProductionFeeRate:newFeeRate});
  761. this.datas.constData.assistProductionFeeRate = newFeeRate;
  762. //todo 调用材料计算方法,所有材料重算一遍
  763. let [unitPrices,sumMap] = this.calcAllMaterial([],true);
  764. sumMap["unitPrice"] = unitPrices;
  765. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  766. this.refreshMaterialCalcCache(sumMap);
  767. materialCalcObj.showDatas();
  768. }catch (err){
  769. console.log(err);
  770. }finally {
  771. $.bootstrapLoading.end();
  772. }
  773. };
  774. ProjectGLJ.prototype.calcAllMaterialWhenChange = async function(){//当费率单价等改变时,重新计算所有材料 返回价格有变化的项目工料机
  775. let gljList = [];
  776. try {
  777. let [unitPrices,sumMap] = this.calcAllMaterial([],true);
  778. if(unitPrices.length > 0){
  779. sumMap["unitPrice"] = unitPrices;
  780. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  781. gljList = this.refreshMaterialCalcCache(sumMap,true);
  782. materialCalcObj.showDatas();
  783. }
  784. }catch (err){
  785. console.log(err);
  786. }
  787. return gljList
  788. }
  789. ProjectGLJ.prototype.loadFreightAndOriginalData = function(originalList,freightList){
  790. if(freightList) this.datas.freightList = freightList;
  791. if(originalList) this.datas.originalList = originalList;
  792. };
  793. ProjectGLJ.prototype.updateMaterialRation = async function (datas){
  794. try {
  795. let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
  796. $.bootstrapLoading.start();
  797. let result = await ajaxPost('/ration/updateMaterialRation',datas);
  798. if(datas.actionType=="add" && result.projectGLJList){
  799. this.loadNewProjectGLJToCaches(result.projectGLJList,true);
  800. this.loadFreightAndOriginalData(result.originalList,result.freightList); //这一步已经更新了运费和原价数据
  801. }
  802. if(datas.actionType == "delete"){
  803. let parent = _.find(lists,{ID:datas.parentID}) ;
  804. if(parent){
  805. _.remove(parent.rations,{ID:datas.rationID});
  806. _.remove(parent.ration_gljs,{rationID:datas.rationID});
  807. }
  808. }
  809. if(datas.actionType == "update"){
  810. let parent = _.find(lists,{ID:datas.parentID}) ;
  811. let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
  812. if(ration){
  813. if(datas.field == "code" && result.projectGLJList){
  814. this.loadNewProjectGLJToCaches(result.projectGLJList,true);
  815. this.loadFreightAndOriginalData(result.originalList,result.freightList);
  816. }else {
  817. ration[datas.field] = datas.value;
  818. if(datas.ext){
  819. for(let key in datas.ext){
  820. ration[key] = datas.ext[key];
  821. }
  822. }
  823. }
  824. if(datas.ration_gljs){//更新定额工料机数量
  825. let gljMap = _.indexBy(parent.ration_gljs,"ID");
  826. for(let g of datas.ration_gljs){
  827. if(gljMap[g.ID]) gljMap[g.ID].quantity = g.quantity;
  828. }
  829. }
  830. }
  831. }
  832. }catch (e){
  833. console.log(e)
  834. }finally {
  835. //materialCalcObj.showDatas();
  836. this.calcMaterialRation(datas.parentID,datas.type);
  837. $.bootstrapLoading.end();
  838. }
  839. };
  840. ProjectGLJ.prototype.getHighlandFee = function (feeType) {
  841. let rates = projectObj.project.FeeRate.getActivateFeeRate().rates;
  842. let matchType = false;
  843. let rate = 0;
  844. //获取高原取费类别,是先按feeType取顶层的费率,然后取子项中的“高原地区施工增加费”
  845. if(!feeType||feeType=="") return 0;//空时为0
  846. let hightlandRate = null;
  847. let topParentID = null;
  848. for(let r of rates){//费率是按顺序排的,所以先取到顶层,之后的就是目标了。
  849. if(matchType && r.ParentID == topParentID) break; //如果feeType已经匹配过了,又经过了下一个顶层节点,那说明该feeType下没有高原费率
  850. if(r.name == feeType){
  851. matchType = true;
  852. topParentID = r.ParentID;
  853. }
  854. if(matchType && r.name == "高原地区施工增加费"){
  855. //顶层先匹配上了,第一个就是要找的费率
  856. hightlandRate = r;
  857. break;
  858. }
  859. }
  860. if(hightlandRate){
  861. rate = scMathUtil.roundForObj(hightlandRate.rate,getDecimal("feeRate"));
  862. }
  863. return rate*0.01
  864. };
  865. ProjectGLJ.prototype.calcEachFreightOrPrice = function (temp,type,priceMap,needUpdate=false) {//
  866. if(temp){
  867. if(type == "freight" && temp.conveyance !="自办运输") return null;
  868. let sum =0;
  869. let heightFee = 0;
  870. let gljMap = {};
  871. let expList = [];
  872. let decimal = type == "freight"?getDecimal("glj.unitPrice"):getDecimal("glj.unitPriceHasMix");
  873. //因为材料计算的数据是保存在单价文件里的,有可能存在共享的情况,这样的话就不能用单价文件里的项目工料机ID来匹配,要用5大项匹配
  874. let pgljMap = {};
  875. if(needUpdate==false && (!temp.rations || temp.rations.length == 0))return null;//没有定额时不计算
  876. for(let pg of this.datas.gljList){
  877. pgljMap[gljUtil.getIndex(pg)] = pg
  878. }
  879. if(temp.ration_gljs){
  880. for(let g of temp.ration_gljs){
  881. gljMap[g.rationID]?gljMap[g.rationID].push(g):gljMap[g.rationID]=[g];
  882. }
  883. }
  884. if(temp.rations) {
  885. for(let r of temp.rations){
  886. let [tsum,thei,exp] = calcRation(r,gljMap[r.ID],pgljMap,priceMap);
  887. heightFee = scMathUtil.roundForObj(heightFee+thei,6);
  888. sum = scMathUtil.roundForObj(sum + tsum,6);
  889. expList.push(exp);
  890. }
  891. }
  892. sum = scMathUtil.roundForObj(sum,decimal)+"";
  893. if(type == "freight"){
  894. let exp = expList.length == 0?`${temp.otherFee}x${temp.weightCoe}`:`((${expList.join("+")})+${temp.otherFee})x${temp.weightCoe}`
  895. let ndoc = {};
  896. if(temp.unitFreight != sum) ndoc['unitFreight'] = sum;
  897. ndoc['exp'] = exp;
  898. if(temp.heightFee != heightFee) ndoc['heightFee'] = heightFee;
  899. if(!_.isEmpty(ndoc)) return {ID:temp.ID,doc:ndoc};
  900. }
  901. if(type == "price" && temp.supplyPrice !=sum) return {ID:temp.ID,doc:{supplyPrice:sum,heightFee:heightFee}}
  902. }
  903. return null;
  904. function calcRation(ration,gljs,pMap,priceMap){
  905. let result = 0;
  906. let heightFee = 0;
  907. let exp = "";
  908. if(gljs){
  909. let processDecimal = getDecimal("process");
  910. let hightFeeRate = projectObj.project.projectGLJ.getHighlandFee(ration.feeType);//高原取费类别费率
  911. let assFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")) * 0.01;//辅助生产间接费费率
  912. let laberSum = 0;
  913. let machineSum = 0;
  914. let assList=[];
  915. let expList = [];
  916. let rationQuantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
  917. for(let g of gljs){
  918. gljOprObj.setGLJPrice(g,pMap[gljUtil.getIndex(g)]);
  919. if(priceMap && priceMap[g.projectGLJID]) g.marketPrice = scMathUtil.roundForObj(priceMap[g.projectGLJID],getDecimal("glj.unitPrice"));
  920. let quantity = scMathUtil.roundForObj(g.quantity,getDecimal("glj.quantity"));
  921. let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity,processDecimal);//市场价
  922. let r_price = gljUtil.getAssUsedPrice(g);//浙江定额时特殊处理,这里取市场价
  923. let rt = scMathUtil.roundForObj(quantity * r_price * rationQuantity,processDecimal);//定额价
  924. let calString = `${quantity}x${r_price}x${rationQuantity}`;
  925. if(g.type == gljUtil.gljType.LABOUR){
  926. laberSum = scMathUtil.roundForObj(laberSum+rt,processDecimal);
  927. assList.push(`${calString}x${assFeeRate*100}%`)
  928. }
  929. if(gljUtil.getMainType(g.type) == 3) machineSum = scMathUtil.roundForObj(machineSum+rt,processDecimal);
  930. expList.push(`${quantity}x${g.marketPrice}x${rationQuantity}`);
  931. result = scMathUtil.roundForObj(result + t,processDecimal);
  932. }
  933. let as = scMathUtil.roundForObj(laberSum * assFeeRate,processDecimal);//人工消耗量*定额价*定额工程量*辅助生产间接费费率
  934. let tt = scMathUtil.roundForObj(laberSum + machineSum,processDecimal);//人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量
  935. let hs = scMathUtil.roundForObj(tt*hightFeeRate,processDecimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
  936. exp = expList.join("+");
  937. if(hightFeeRate!=0) exp += `+${tt}x${hightFeeRate*100}%`;
  938. if(assFeeRate!=0 && assList.length > 0) exp += '+'+assList.join("+");
  939. result = scMathUtil.roundForObj(as + result,processDecimal);
  940. result = scMathUtil.roundForObj(hs + result,processDecimal);
  941. heightFee = hs;
  942. }
  943. return [result,heightFee,exp];
  944. }
  945. };
  946. ProjectGLJ.prototype.calcMaterialAssQuantity = function (parent,ration,newAssList) {
  947. let updateList = [];
  948. let assList = calcAssList(newAssList);
  949. for(let glj of parent.ration_gljs){
  950. if(glj.rationID == ration.ID){
  951. updateList.push(calcAssGljQuantity(glj,assList));
  952. }
  953. }
  954. return updateList;
  955. function calcAssGljQuantity(g,assList) {
  956. g.quantity = scMathUtil.roundForObj(g.rationItemQuantity,getDecimal("glj.quantity"));
  957. for(let a of assList){
  958. let ass = a.ass;
  959. let matchGlj = null;
  960. for(let aglj of ass.rationGljList){
  961. if(aglj.gljId == g.GLJID){
  962. matchGlj = aglj;
  963. break;
  964. }
  965. }
  966. if(matchGlj){
  967. let calQuantity =scMathUtil.roundForObj(matchGlj.consumeAmt*a.times,6);
  968. g.quantity = scMathUtil.roundForObj(calQuantity + g.quantity,getDecimal("glj.quantity"))+"";
  969. }
  970. }
  971. return {ID:g.ID,quantity:g.quantity}
  972. }
  973. function calcAssList(rationAssList){
  974. let calAss = [];
  975. for(let ass of rationAssList){
  976. let times = calculateTimes(ass);
  977. if(times!=0){
  978. calAss.push({ass:ass.assRation,times:times});
  979. }
  980. }
  981. return calAss;
  982. }
  983. function calculateTimes(ass){
  984. if(ass.name.indexOf("运距") == -1) return 0;//只计算运距;
  985. let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
  986. let r = false;
  987. if(times<0){
  988. r=true;
  989. times=times*-1;
  990. }
  991. if(ass.carryBit=='四舍五入'){
  992. times = _.round(times,ass.decimal);
  993. }else if (ass.carryBit=='进一'){
  994. times =_.ceil(times,ass.decimal);
  995. }else if(ass.carryBit == '舍一'){
  996. times = _.floor(times,ass.decimal);
  997. }
  998. if(r){
  999. times=times*-1;
  1000. }
  1001. return scMathUtil.roundTo(times,-6);
  1002. }
  1003. };
  1004. ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的运费或者原价
  1005. let lists = type == "freight"?this.datas.freightList:this.datas.originalList;
  1006. let temp = _.find(lists,{ID:ID});
  1007. if(temp){
  1008. let task = this.calcEachFreightOrPrice(temp,type);
  1009. let material = materialCalcObj.getMaterialSelected();
  1010. if(task && material){
  1011. if(type == "freight") projectObj.project.projectGLJ.updateFreightCalc([task],material.id);
  1012. if(type == "price") projectObj.project.projectGLJ.updatePriceCalc([task],material.id);
  1013. }else {
  1014. materialCalcObj.showDatas();
  1015. }
  1016. }
  1017. };
  1018. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  1019. let map = {};
  1020. map[ID] = true;
  1021. await this.updateMaterialCalcTasks(pgljID,map,"delete","price");
  1022. };
  1023. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  1024. let map = {};
  1025. map[ID] = true;
  1026. await this.updateMaterialCalcTasks(pgljID,map,"delete","freight");
  1027. };
  1028. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  1029. let me = this;
  1030. let projectGljs = this.datas.gljList;
  1031. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  1032. let glj = _.find(projectGljs, {'id': pgljID});
  1033. if (glj) {
  1034. if(glj.unit_price[updateField] == newval){
  1035. return;
  1036. }
  1037. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  1038. 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};
  1039. if(updateField == 'market_price' && (this.datas.mixRatioConnectData[gljUtil.getIndex(glj)] || glj.name == "电网电")){//计算是否有受影响的综合电价
  1040. let uobj = {};
  1041. uobj[glj.id] = {marketPrice:newval};
  1042. let ext =electrovalenceObj.clacNewElecPrice(uobj);
  1043. if(ext) data.ext = ext;
  1044. }
  1045. let callback =async function (result) {
  1046. if (updateField == 'base_price') {
  1047. glj.unit_price.base_price = newval;
  1048. me.setAdjustPrice(glj);
  1049. } else {
  1050. glj.unit_price.market_price = newval;
  1051. }
  1052. let elec_glj = null;
  1053. if(data.ext){
  1054. elec_glj = _.find(projectGljs, {'id': data.ext.projectGLJID});
  1055. if(elec_glj) elec_glj.unit_price.market_price = data.ext.doc.market_price;
  1056. }
  1057. //更新回传的父节点项目工料机价格
  1058. let gljs = me.getProjectGLJs(result);
  1059. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  1060. let materialGljList =await me.calcAllMaterialWhenChange()
  1061. gljs= gljs.concat(materialGljList);
  1062. projectGljObject.refreshDataSheet();//更新工料机汇总缓存和显示
  1063. //projectObj.project.projectGLJ.loadCacheData();
  1064. gljOprObj.showRationGLJSheetData();
  1065. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  1066. gljs.push(glj);
  1067. if(elec_glj) gljs.push(elec_glj);
  1068. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1069. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1070. if(materialGljList.length==0)projectGljObject.onUnitFileChange(result);
  1071. divideObj.calcDivideAfterGLJUpdate(gljs);
  1072. if(cb){
  1073. cb(gljs);
  1074. }
  1075. $.bootstrapLoading.end();
  1076. }
  1077. $.bootstrapLoading.start();
  1078. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  1079. $.bootstrapLoading.end();
  1080. });
  1081. } else {
  1082. gljOprObj.showRationGLJSheetData();
  1083. }
  1084. };
  1085. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  1086. let me = this;
  1087. //更新是否暂估和供货方式时,要做特殊处理
  1088. $.bootstrapLoading.start();
  1089. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  1090. $.bootstrapLoading.end();
  1091. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  1092. for(let idKey in updateMap){
  1093. let gljID = parseInt(idKey);
  1094. let glj = me.getByID(gljID);
  1095. let doc = updateMap[idKey];
  1096. for(let property in doc){
  1097. glj[property] = doc[property];
  1098. }
  1099. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  1100. supplyChangeIDs.push(gljID);
  1101. }
  1102. if(doc.hasOwnProperty("is_evaluate")){
  1103. evaluate_gljs.push(glj);
  1104. }
  1105. }
  1106. if(supplyChangeIDs.length>0){
  1107. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  1108. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  1109. }
  1110. if(evaluate_gljs.length > 0){
  1111. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  1112. rationNodes = rationNodes.concat(impactRationNodes);
  1113. }
  1114. if(rationNodes.length > 0){
  1115. rationNodes = _.uniq(rationNodes,'data');
  1116. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  1117. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1118. });
  1119. }
  1120. if(callback){
  1121. callback();
  1122. }
  1123. })
  1124. };
  1125. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  1126. let me = this;
  1127. let projectGljs = me.datas.gljList;
  1128. let updateData = [];
  1129. let newValueMap = {};
  1130. let gljs=[];
  1131. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  1132. if(changeInfo.length<=0){
  1133. callback?callback():'';
  1134. return
  1135. }
  1136. for(let ci of changeInfo){
  1137. let dataCode = setting.header[ci.col].dataCode;
  1138. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  1139. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  1140. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  1141. let glj = _.find(projectGljs, {'id': recode.id});
  1142. let newValue = ci.value;
  1143. if(glj&&glj.unit_price[editField]!=newValue){
  1144. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  1145. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  1146. newValueMap[glj.id]={field:editField,value:newValue};
  1147. gljs.push(glj);
  1148. }
  1149. }
  1150. }
  1151. if(updateData.length > 0){
  1152. $.bootstrapLoading.start();
  1153. CommonAjax.post("/glj/batchUpdatePrices", updateData,async function (result) {
  1154. let parentData = [];
  1155. //更新缓存
  1156. for(let g of gljs){
  1157. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  1158. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  1159. }
  1160. //更新父工料机价格
  1161. for(let r of result){
  1162. let pdata = r.updateOne.filter;
  1163. let set = r.updateOne.update.$set;
  1164. for(let skey in set){
  1165. pdata[skey] = set[skey];
  1166. }
  1167. parentData.push(pdata);
  1168. }
  1169. let pgljs = me.getProjectGLJs(parentData);
  1170. gljs = gljs.concat(pgljs);
  1171. let materialGljList = await me.calcAllMaterialWhenChange();
  1172. gljs = gljs.concat(materialGljList);
  1173. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1174. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1175. gljOprObj.showRationGLJSheetData();
  1176. if(materialGljList.length == 0) projectGljObject.onUnitFileChange(gljs);
  1177. if(callback){
  1178. callback(gljs);
  1179. }
  1180. $.bootstrapLoading.end();
  1181. }, function (err) {
  1182. $.bootstrapLoading.end();
  1183. });
  1184. }
  1185. };
  1186. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  1187. let me = this;
  1188. $.bootstrapLoading.start();
  1189. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  1190. let unitPriceMap = {}, mu=null, parentID = null;
  1191. for(let u of updateData){
  1192. if(u.type == 'mix_ratio'){
  1193. mu = u;
  1194. }else if(u.type == 'unitPrice'){
  1195. unitPriceMap[u.projectGLJID] = u.doc;
  1196. if(u.isParent) parentID = u.projectGLJID;
  1197. }
  1198. }
  1199. if(!_.isEmpty(unitPriceMap)){
  1200. for(let g of me.datas.gljList) {
  1201. if(unitPriceMap[g.id]){
  1202. gljUtil.setProperty(g.unit_price,unitPriceMap[g.id]);
  1203. }
  1204. if(parentID == g.id) updateMixRatio(g,mu,me);
  1205. }
  1206. }
  1207. me.calcQuantity();
  1208. if(callback){
  1209. callback();
  1210. }
  1211. $.bootstrapLoading.end();
  1212. },function () {
  1213. $.bootstrapLoading.end();
  1214. })
  1215. function updateMixRatio(parent,u,me) {
  1216. let tem = updateMap[u.query.id];
  1217. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  1218. let subData = _.find(parent.ratio_data,{"id":u.query.id});
  1219. if(subData){
  1220. subData.consumption = u.doc.consumption;
  1221. }
  1222. let m_list = me.datas.mixRatioMap[gljUtil.getIndex(parent)];
  1223. let m_ratioData = _.find(m_list,{"id":u.query.id});
  1224. if(m_ratioData){
  1225. m_ratioData.consumption = u.doc.consumption;
  1226. }
  1227. }
  1228. };
  1229. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  1230. let me = this;
  1231. $.bootstrapLoading.start();
  1232. CommonAjax.specialPost( '/glj/update',data,function (result) {
  1233. let glj = me.getByID(data.id);//更新缓存
  1234. let impactList = [];
  1235. glj[data.field] = data.value;
  1236. if(data.extend&&data.extend!=""){
  1237. let extend = JSON.parse(data.extend);
  1238. for (let key in extend) {
  1239. glj[key] = extend[key];
  1240. }
  1241. }
  1242. if(data.field == 'is_evaluate'){
  1243. impactList = me.changeIsEvaluate(data.id);
  1244. }
  1245. if(callback){
  1246. callback(impactList);
  1247. }
  1248. $.bootstrapLoading.end();
  1249. });
  1250. };
  1251. ProjectGLJ.prototype.getRatioData=function(id,callback){
  1252. this.getRatioId = id;
  1253. if(id){
  1254. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  1255. let ratios = JSON.parse(response.data);
  1256. if(callback){
  1257. callback(ratios);
  1258. }
  1259. },function () {//取不到组成物的情况
  1260. callback([]);
  1261. })
  1262. }else {
  1263. if(callback){
  1264. callback([]);
  1265. }
  1266. }
  1267. };
  1268. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  1269. $.bootstrapLoading.start();
  1270. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  1271. projectObj.project.property.unitPriceFile = response.unitFile;
  1272. projectObj.project.projectGLJ.loadData(function () {
  1273. if(callback){
  1274. callback();
  1275. }
  1276. $.bootstrapLoading.end();
  1277. });
  1278. }, function (err) {
  1279. if($.bootstrapLoading.isLoading()){
  1280. $.bootstrapLoading.end();
  1281. }
  1282. alert(err.msg);
  1283. });
  1284. };
  1285. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  1286. $.bootstrapLoading.start();
  1287. try {
  1288. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  1289. await this.synLoadData();
  1290. projectGljObject.refreshDataSheet();
  1291. gljOprObj.refreshView();
  1292. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  1293. projectGljObject.onUnitFileChange();
  1294. }catch (err){
  1295. console.log(err);
  1296. }finally {
  1297. $.bootstrapLoading.end();
  1298. }
  1299. };
  1300. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  1301. let property = projectObj.project.projectInfo.property;
  1302. let data = {
  1303. name:newVal,
  1304. rootProjectID:property.rootProjectID
  1305. }
  1306. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  1307. callback(data);
  1308. });
  1309. };
  1310. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  1311. $.bootstrapLoading.start();
  1312. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  1313. projectObj.project.projectGLJ.loadData(function () {
  1314. if(callback){
  1315. callback();
  1316. }
  1317. $.bootstrapLoading.end();
  1318. });
  1319. },function (response) {
  1320. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  1321. $("#save-as-tips").text(msg).show();
  1322. $.bootstrapLoading.end();
  1323. });
  1324. };
  1325. //更新是否暂估
  1326. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  1327. let projectGLJ = projectObj.project.projectGLJ;
  1328. let datas = projectGLJ.datas;
  1329. let gljList = datas.gljList;
  1330. let glj = _.find(gljList, {'id': id});
  1331. if(glj){//与批量更新调用相同的方法
  1332. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1333. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  1334. let conditions = [];
  1335. if(pratioM&&pratioM.length>0){
  1336. for(let p_key of pratioM ){
  1337. conditions.push(gljOprObj.getConditionByKey(p_key));
  1338. }
  1339. }
  1340. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  1341. gljs.push(glj);
  1342. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1343. //更新对应的工料机类型的定额
  1344. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  1345. let ration_nodes = [];
  1346. for(r of rations){
  1347. if(r){
  1348. r.isEstimate =glj.is_evaluate?1:0;
  1349. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  1350. ration_node?ration_nodes.push(ration_node):'';
  1351. }
  1352. }
  1353. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  1354. for(rg of ration_glj_nodes){
  1355. rg.data.isEstimate =glj.is_evaluate?1:0;
  1356. ration_nodes.push(rg);
  1357. }
  1358. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  1359. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  1360. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1361. return gljs;
  1362. }
  1363. };
  1364. /**
  1365. * 批量更新是否暂估
  1366. *传入项目工料机数组
  1367. */
  1368. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  1369. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  1370. for(let glj of gljs){
  1371. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1372. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  1373. let conditions = [];
  1374. if(pratioM&&pratioM.length>0){
  1375. for(let p_key of pratioM ){
  1376. conditions.push(gljOprObj.getConditionByKey(p_key));
  1377. }
  1378. }
  1379. let tem_gljs = this.getProjectGLJs(conditions,false);
  1380. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  1381. }
  1382. impactGLJs = impactGLJs.concat(gljs);
  1383. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  1384. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  1385. let neeRefreshNode = [];
  1386. //更新对应的工料机类型的定额
  1387. for(let item of projectObj.project.Ration.datas){
  1388. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  1389. let tem_g = changeMap[item.projectGLJID];
  1390. item.isEstimate =tem_g.is_evaluate?1:0;
  1391. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  1392. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  1393. }
  1394. }
  1395. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1396. for(let rg of ration_glj_nodes){
  1397. let tem_g = changeMap[rg.data.projectGLJID];
  1398. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1399. neeRefreshNode.push(rg);
  1400. }
  1401. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1402. return [impactRationNodes,impactGLJs];
  1403. };
  1404. ProjectGLJ.prototype.getByID = function (ID) {
  1405. return _.find(this.datas.gljList,{'id':ID});
  1406. };
  1407. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1408. return _.find(this.datas.gljList,function (item) {
  1409. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1410. return tem_key == conkey
  1411. })
  1412. };
  1413. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1414. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1415. let me = this;
  1416. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1417. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1418. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1419. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1420. return true;
  1421. }
  1422. })
  1423. projectObj.mainController.refreshTreeNode(nodes);
  1424. }
  1425. }
  1426. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1427. let nodes = [];
  1428. let ids = [];
  1429. if(Array.isArray(id)){
  1430. ids = id;
  1431. }else {
  1432. ids = [id];
  1433. }
  1434. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1435. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1436. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1437. })
  1438. }
  1439. return nodes;
  1440. };
  1441. //根据工料机,取得所有受影响的定额节点
  1442. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1443. let nodes = [];
  1444. let rationMap = {};
  1445. let idArray = _.map(gljs,'id');
  1446. let gljMap = _.indexBy(gljs,'id');
  1447. //先根据项目工料机ID,找到受影响定额的ID
  1448. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1449. for (let rg of ration_glj_list) {
  1450. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1451. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1452. }
  1453. }
  1454. for (let item of projectObj.project.mainTree.items) {
  1455. if (item.sourceType == ModuleNames.ration) {
  1456. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1457. let tem_g = gljMap[item.data.projectGLJID];
  1458. if(tem_g){
  1459. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1460. item.data.marketPrice = this.getMarketPrice(tem_g);
  1461. nodes.push(item);
  1462. }
  1463. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1464. nodes.push(item)
  1465. }
  1466. }
  1467. }
  1468. return nodes;
  1469. };
  1470. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1471. for (let ration_glj of gljOprObj.sheetData) {
  1472. if (ration_glj.projectGLJID == glj.id) {
  1473. ration_glj.basePrice = this.getBasePrice(glj);
  1474. ration_glj.marketPrice = this.getMarketPrice(glj);
  1475. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1476. }
  1477. }
  1478. }
  1479. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1480. }
  1481. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1482. let parentGlj = [];
  1483. //
  1484. let projectGljs = this.datas.gljList;
  1485. let indexList = gljKeyArray;
  1486. for (let d of data) {
  1487. if (d) {
  1488. let glj = _.find(projectGljs, function (item) {
  1489. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1490. });
  1491. if (glj) {
  1492. if(refreshPrice==true){
  1493. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1494. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1495. this.setAdjustPrice(glj);
  1496. this.refreshRationGLJPrice(glj);
  1497. this.refreshTreeNodePriceIfNeed(glj);
  1498. }
  1499. parentGlj.push(glj);
  1500. }
  1501. }
  1502. }
  1503. return parentGlj;
  1504. }
  1505. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1506. switch (glj.unit_price.type + '') {
  1507. // 人工: 调整基价=基价单价*调整系数
  1508. case GLJTypeConst.LABOUR:
  1509. case GLJTypeConst.MACHINE_LABOUR:
  1510. glj.adjust_price = this.getAdjustPrice(glj);
  1511. break;
  1512. // 机械类型的算法
  1513. case GLJTypeConst.MACHINE:
  1514. console.log('机械');
  1515. break;
  1516. // 材料、主材、设备
  1517. default:
  1518. glj.adjust_price = glj.unit_price.base_price;
  1519. }
  1520. }
  1521. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1522. let proGLJ = projectObj.project.projectGLJ;
  1523. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1524. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1525. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1526. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1527. };
  1528. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1529. let proGLJ = projectObj.project.projectGLJ;
  1530. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1531. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1532. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1533. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1534. };
  1535. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1536. let proGLJ = projectObj.project.projectGLJ;
  1537. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1538. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1539. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1540. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1541. };
  1542. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1543. let proGLJ = projectObj.project.projectGLJ;
  1544. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1545. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1546. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1547. let tenderCoe = this.getTenderPriceCoe(glj);
  1548. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1549. };
  1550. ProjectGLJ.prototype.getTenderPriceCoe = function(glj,tproperty){
  1551. return gljUtil.getTenderPriceCoe(glj,tproperty);
  1552. };
  1553. ProjectGLJ.prototype.isEstimateType = function(type){
  1554. let typeString = type + "";
  1555. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1556. return type;
  1557. }
  1558. return false;
  1559. };
  1560. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1561. let gljTypeMap = this.datas.constData.gljTypeMap;
  1562. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1563. };
  1564. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1565. let project_gljs = this.datas.gljList;
  1566. let changeArray=[];
  1567. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1568. let rationDatas = projectObj.project.Ration.datas;
  1569. let billsDatas = projectObj.project.Bills.datas;
  1570. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1571. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1572. this.quantityChangeMap = {};
  1573. for(let pglj of project_gljs){
  1574. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1575. }
  1576. }else if(this.quantityChangeMap != null){
  1577. for(let pglj of project_gljs){
  1578. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1579. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1580. changeArray.push(pglj);
  1581. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1582. }
  1583. }else { //映射表没有,说明是新添加的项目工料机
  1584. changeArray.push(pglj);
  1585. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1586. }
  1587. }
  1588. }
  1589. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1590. };
  1591. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1592. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1593. let rationDatas = projectObj.project.Ration.datas;
  1594. let billsDatas = projectObj.project.Bills.datas;
  1595. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1596. };
  1597. ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
  1598. if(!datas) return;
  1599. let gljIDMap = {};
  1600. for (let d of datas){
  1601. if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
  1602. }
  1603. if(datas.length > 0 && calquantity) this.calcQuantity();
  1604. };
  1605. ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新插入的项目工料机数据增加至缓存中
  1606. if(!data) return;
  1607. let project_gljs = this.datas.gljList;
  1608. let unitPriceMap = this.datas.unitPriceMap;
  1609. let mixRatioMap = this.datas.mixRatioMap;
  1610. let mixRatioConnectData = this.datas.mixRatioConnectData;
  1611. let IDMap = !_.isEmpty(tIDMap)?tIDMap:_.indexBy(project_gljs,'id');
  1612. let tem = IDMap[data.id];
  1613. if(tem) return tem; //判断该工料机是否已经存在,是的话不用再次添加
  1614. //查看是否有组成物,有组成物的话先添加组成物信息
  1615. data.ratio_data=[];
  1616. if(data.subList && data.subList.length){
  1617. for(let s of data.subList){
  1618. let ratio = s.ratio_data;
  1619. data.ratio_data.push(ratio);
  1620. mixRatioMap[ratio.connect_key]?mixRatioMap[ratio.connect_key].push(ratio):mixRatioMap[ratio.connect_key] = [ratio];
  1621. let rIndex = gljUtil.getIndex(ratio);
  1622. mixRatioConnectData[rIndex]?mixRatioConnectData[rIndex].push(ratio.connect_key):mixRatioConnectData[rIndex] = [ratio.connect_key];
  1623. this.loadNewProjectGLJToCache(s,IDMap);
  1624. }
  1625. delete data.subList;
  1626. }
  1627. //添加unitPriceMap
  1628. let uIndex = gljUtil.getIndex(data.unit_price);
  1629. if(!unitPriceMap[uIndex]) unitPriceMap[uIndex] = data.unit_price;
  1630. this.datas.gljList.push(data);
  1631. IDMap[data.id] = data;
  1632. return data;
  1633. };
  1634. class DivideSetting {
  1635. constructor (project) {
  1636. this.project = project;
  1637. this.datas = [];
  1638. project.registerModule(ModuleNames.divide_setting, this);
  1639. };
  1640. loadData (datas) {
  1641. this.datas = datas;
  1642. };
  1643. }
  1644. class EvaluateList {
  1645. constructor (project) {
  1646. this.project = project;
  1647. this.datas = [];
  1648. project.registerModule(ModuleNames.evaluate_list, this);
  1649. };
  1650. loadData (datas) {
  1651. this.datas = datas;
  1652. };
  1653. }