project_glj.js 74 KB

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