project_glj.js 72 KB

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