project_glj.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. }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. $.bootstrapLoading.start();
  287. try {
  288. let result = await ajaxPost('/glj/updateCalcMaterial',data);
  289. glj.unit_price[updateField] = value;
  290. if(ext){
  291. for(let key in ext){
  292. glj.unit_price[key] = ext[key];
  293. }
  294. }
  295. if(updateField == 'calcMaterial' && value ==0){///标记为0即删除材料计算标记,要删除其下挂的原价计算,运费计算,定额计算,消耗量重新计算
  296. let connect_key = gljUtil.getIndex(glj);
  297. _.remove(this.datas.originalList,{'connect_key':connect_key});
  298. _.remove(this.datas.freightList,{'connect_key':connect_key});
  299. this.calcQuantity();
  300. // to do 删除定额计算
  301. }
  302. projectGljObject.refreshDataSheet();
  303. materialCalcObj.showDatas();
  304. }catch (e){
  305. console.log(e)
  306. }finally {
  307. $.bootstrapLoading.end();
  308. }
  309. }
  310. };
  311. ProjectGLJ.prototype.materialCal = function (id,dataMap) {
  312. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  313. let unitPirceDecimal = getDecimal("glj.unitPrice");
  314. let process = getDecimal("process");
  315. let glj = _.find(this.datas.gljList,{'id':id});
  316. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  317. if(!glj) return;
  318. let unitPrice = {id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  319. //先计算原价
  320. let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap);
  321. doc['originalPrice'] = originalPrice+'';
  322. doc['supplyLocation'] = supplyLocation;
  323. //再计算运费
  324. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  325. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  326. let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap);
  327. doc['unitFreight'] = unitFreight+'';
  328. //计算场外运输损耗
  329. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  330. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  331. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  332. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  333. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  334. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  335. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  336. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  337. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  338. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  339. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  340. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  341. //计算采购及保管费
  342. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  343. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  344. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  345. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  346. doc['purchaseStorage'] = purchaseStorage+'';
  347. //再计算预算价
  348. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  349. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  350. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  351. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  352. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  353. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  354. let o_unit = glj.unit_price;
  355. for(let key in doc){
  356. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  357. unitPrice.doc[key] = doc[key];
  358. }
  359. return unitPrice
  360. };
  361. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap) {
  362. let process = getDecimal("process");
  363. let unitPirce = getDecimal("glj.unitPrice");
  364. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  365. let sum = 0;
  366. let freightList = _.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  367. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  368. for(let f of freightList){
  369. let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe;
  370. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  371. let t = dataMap["freight"]["update"][f.ID];
  372. if(t){
  373. if(t['unitFreight']) unitFreight = t['unitFreight'];
  374. if(t['kmDistance']) kmDistance = t['kmDistance'];
  375. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  376. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  377. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  378. if(t['otherFee']) otherFee = t['otherFee'];
  379. if(t['weightCoe']) weightCoe = t['weightCoe'];
  380. }
  381. }
  382. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  383. if(f.ID ==dataMap["freight"]["delete"]) continue;
  384. }
  385. //开始计算
  386. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  387. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  388. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  389. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  390. let t = scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  391. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  392. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  393. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  394. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  395. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  396. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  397. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  398. t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  399. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  400. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  401. sum = scMathUtil.roundForObj(sum + t,process);
  402. }
  403. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  404. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  405. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  406. }
  407. return scMathUtil.roundForObj(sum,unitPirce);
  408. };
  409. ProjectGLJ.prototype.priceCalc = function (glj,dataMap) {
  410. let process = getDecimal("process");
  411. let unitPirce = getDecimal("glj.unitPrice");
  412. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  413. let original_price = 0;
  414. let supplyList = [];
  415. let supplyLocation = "";
  416. let priceList = _.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  417. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  418. for(let p of priceList){
  419. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  420. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  421. let t = dataMap["price"]["update"][p.ID];
  422. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  423. if(t && t["coe"]) coe =t["coe"];
  424. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  425. }
  426. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  427. if(p.ID ==dataMap["price"]["delete"]) continue;
  428. }
  429. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  430. coe = scMathUtil.roundForObj(coe,unitPirce);
  431. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  432. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  433. supplyList.push(supplyLocation);
  434. }
  435. supplyLocation = supplyList.join(',');
  436. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  437. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  438. original_price = doc['originalPrice']?doc['originalPrice']:glj.unit_price.originalPrice;
  439. supplyLocation = doc['supplyLocation']?doc['supplyLocation']:glj.unit_price.supplyLocation;
  440. }
  441. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation];
  442. };
  443. ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
  444. let me = this;
  445. let gljList = [];
  446. for(let d of datas){
  447. let g = updateUnit(d.id,d.unitPrice);
  448. if(g) gljList.push(g);
  449. }
  450. this.calcQuantity();
  451. //刷新项目工料机表显示
  452. projectGljObject.refreshDataSheet();
  453. //重新计算相关节点
  454. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  455. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  456. //刷新定额工料机
  457. gljOprObj.refreshView();
  458. //socket推送更新信息
  459. projectGljObject.onUnitFileChange();
  460. function updateUnit(id,unitPrice) {
  461. let glj = _.find(me.datas.gljList,{'id':id});
  462. if(glj && !_.isEmpty(unitPrice.doc)){
  463. for(let key in unitPrice.doc){
  464. glj.unit_price[key] = unitPrice.doc[key];
  465. }
  466. }
  467. return glj;
  468. }
  469. };
  470. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  471. this.m_updateUnitPrice([{id:id,unitPrice:unitPrice}]);
  472. };
  473. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  474. try {
  475. let unitPrice = this.materialCal(pgljID,{price:{add:datas}});
  476. $.bootstrapLoading.start();
  477. let result = await ajaxPost('/glj/addOriginalCalc',{datas:datas,unitPrice:unitPrice});
  478. this.datas.originalList = this.datas.originalList.concat(result);
  479. this.updateUnitPrice(pgljID,unitPrice);
  480. materialCalcObj.showDatas();
  481. }catch (e){
  482. console.log(e)
  483. }finally {
  484. $.bootstrapLoading.end();
  485. }
  486. };
  487. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  488. let tasks = [];
  489. let updateDatas=[];
  490. try {
  491. for(let d of datas){
  492. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  493. if(_.isEmpty(unitPrice.doc)) continue;
  494. tasks.push({updateOne: {filter: {id: unitPrice.id,unit_price_file_id:unitPrice.unit_price_file_id}, update: unitPrice.doc}})
  495. updateDatas.push({id:d.id,unitPrice:unitPrice})
  496. }
  497. $.bootstrapLoading.start();
  498. let result = await ajaxPost('/glj/updateMaterialCalc',{tasks:tasks});
  499. this.m_updateUnitPrice(updateDatas);
  500. materialCalcObj.showDatas();
  501. }catch (e){
  502. console.log(e)
  503. }finally {
  504. $.bootstrapLoading.end();
  505. }
  506. };
  507. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  508. try {
  509. let updateMap = {};
  510. let tasks = [];
  511. for(let d of datas){
  512. updateMap[d.ID] = d.doc;
  513. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  514. }
  515. let unitPrice = this.materialCal(pgljID,{freight:{update:updateMap}});
  516. $.bootstrapLoading.start();
  517. let result = await ajaxPost('/glj/updateFreightCalc',{tasks:tasks,unitPrice:unitPrice});
  518. for(let o of this.datas.freightList){
  519. if(updateMap[o.ID]){
  520. gljUtil.updateProperty(o,updateMap[o.ID]);
  521. }
  522. }
  523. this.updateUnitPrice(pgljID,unitPrice);
  524. materialCalcObj.showDatas();
  525. }catch (e){
  526. console.log(e)
  527. }finally {
  528. $.bootstrapLoading.end();
  529. }
  530. };
  531. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  532. try {
  533. let updateMap = {};
  534. let tasks = [];
  535. for(let d of datas){
  536. updateMap[d.ID] = d.doc;
  537. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  538. }
  539. let unitPrice = this.materialCal(pgljID,{price:{update:updateMap}});
  540. $.bootstrapLoading.start();
  541. let result = await ajaxPost('/glj/updateOriginalCalc',{tasks:tasks,unitPrice:unitPrice});
  542. for(let o of this.datas.originalList){
  543. if(updateMap[o.ID]){
  544. gljUtil.updateProperty(o,updateMap[o.ID]);
  545. }
  546. }
  547. this.updateUnitPrice(pgljID,unitPrice);
  548. materialCalcObj.showDatas();
  549. }catch (e){
  550. console.log(e)
  551. }finally {
  552. $.bootstrapLoading.end();
  553. }
  554. };
  555. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  556. try {
  557. let unitPrice = this.materialCal(pgljID,{freight:{add:datas}});
  558. $.bootstrapLoading.start();
  559. let result = await ajaxPost('/glj/addFreightCalc',{datas:datas,unitPrice:unitPrice});
  560. this.datas.freightList = this.datas.freightList.concat(result);
  561. this.updateUnitPrice(pgljID,unitPrice);
  562. materialCalcObj.showDatas();
  563. }catch (e){
  564. console.log(e)
  565. }finally {
  566. $.bootstrapLoading.end();
  567. }
  568. };
  569. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  570. try {
  571. let data={ID:ID};
  572. // 计算预算价
  573. let unitPrice = this.materialCal(pgljID,{price:{'delete':ID}});
  574. data.unitPrice = unitPrice;
  575. $.bootstrapLoading.start();
  576. await ajaxPost('/glj/deletePriceCalc',data);
  577. _.remove(this.datas.originalList,{'ID':data.ID});
  578. //更新单价文件的值
  579. this.updateUnitPrice(pgljID,unitPrice);
  580. materialCalcObj.showDatas();
  581. }catch (e){
  582. console.log(e)
  583. }finally {
  584. $.bootstrapLoading.end();
  585. }
  586. };
  587. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  588. try {
  589. let data={ID:ID};
  590. // 计算预算价
  591. let unitPrice = this.materialCal(pgljID,{freight:{'delete':ID}});
  592. data.unitPrice = unitPrice;
  593. $.bootstrapLoading.start();
  594. let result = await ajaxPost('/glj/deleteFreightCalc',data);
  595. console.log(result);
  596. _.remove(this.datas.freightList,{'ID':data.ID});
  597. // 更新单价文件的值
  598. this.updateUnitPrice(pgljID,unitPrice);
  599. materialCalcObj.showDatas();
  600. }catch (e){
  601. console.log(e)
  602. }finally {
  603. $.bootstrapLoading.end();
  604. }
  605. };
  606. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  607. let me = this;
  608. let projectGljs = this.datas.gljList;
  609. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  610. let glj = _.find(projectGljs, {'id': pgljID});
  611. if (glj) {
  612. if(glj.unit_price[updateField] == newval){
  613. return;
  614. }
  615. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  616. 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};
  617. let callback = function (data) {
  618. if (updateField == 'base_price') {
  619. glj.unit_price.base_price = newval;
  620. me.setAdjustPrice(glj);
  621. } else {
  622. glj.unit_price.market_price = newval;
  623. }
  624. //更新回传的父节点项目工料机价格
  625. let gljs = me.getProjectGLJs(data);
  626. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  627. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  628. gljOprObj.showRationGLJSheetData();
  629. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  630. gljs.push(glj);
  631. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  632. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  633. projectGljObject.onUnitFileChange(data);
  634. if(cb){
  635. cb(gljs);
  636. }
  637. $.bootstrapLoading.end();
  638. }
  639. $.bootstrapLoading.start();
  640. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  641. $.bootstrapLoading.end();
  642. });
  643. } else {
  644. gljOprObj.showRationGLJSheetData();
  645. }
  646. };
  647. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  648. let me = this;
  649. //更新是否暂估和供货方式时,要做特殊处理
  650. $.bootstrapLoading.start();
  651. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  652. $.bootstrapLoading.end();
  653. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  654. console.log(updateMap);
  655. for(let idKey in updateMap){
  656. let gljID = parseInt(idKey);
  657. let glj = me.getByID(gljID);
  658. let doc = updateMap[idKey];
  659. for(let property in doc){
  660. glj[property] = doc[property];
  661. }
  662. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  663. supplyChangeIDs.push(gljID);
  664. }
  665. if(doc.hasOwnProperty("is_evaluate")){
  666. evaluate_gljs.push(glj);
  667. }
  668. }
  669. if(supplyChangeIDs.length>0){
  670. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  671. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  672. }
  673. if(evaluate_gljs.length > 0){
  674. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  675. rationNodes = rationNodes.concat(impactRationNodes);
  676. }
  677. if(rationNodes.length > 0){
  678. rationNodes = _.uniq(rationNodes,'data');
  679. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  680. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  681. });
  682. }
  683. if(callback){
  684. callback();
  685. }
  686. })
  687. };
  688. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  689. let me = this;
  690. let projectGljs = me.datas.gljList;
  691. let updateData = [];
  692. let newValueMap = {};
  693. let gljs=[];
  694. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  695. if(changeInfo.length<=0){
  696. callback?callback():'';
  697. return
  698. }
  699. for(let ci of changeInfo){
  700. let dataCode = setting.header[ci.col].dataCode;
  701. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  702. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  703. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  704. let glj = _.find(projectGljs, {'id': recode.id});
  705. let newValue = ci.value;
  706. if(glj&&glj.unit_price[editField]!=newValue){
  707. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  708. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  709. newValueMap[glj.id]={field:editField,value:newValue};
  710. gljs.push(glj);
  711. }
  712. }
  713. }
  714. console.log(updateData);
  715. if(updateData.length > 0){
  716. $.bootstrapLoading.start();
  717. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  718. let parentData = [];
  719. //更新缓存
  720. for(let g of gljs){
  721. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  722. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  723. }
  724. //更新父工料机价格
  725. for(let r of result){
  726. let pdata = r.updateOne.filter;
  727. let set = r.updateOne.update.$set;
  728. for(let skey in set){
  729. pdata[skey] = set[skey];
  730. }
  731. parentData.push(pdata);
  732. }
  733. let pgljs = me.getProjectGLJs(parentData);
  734. gljs = gljs.concat(pgljs);
  735. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  736. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  737. gljOprObj.showRationGLJSheetData();
  738. projectGljObject.onUnitFileChange(gljs);
  739. if(callback){
  740. callback(gljs);
  741. }
  742. $.bootstrapLoading.end();
  743. }, function (err) {
  744. $.bootstrapLoading.end();
  745. });
  746. }
  747. };
  748. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  749. let me = this;
  750. $.bootstrapLoading.start();
  751. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  752. let parent = updateData[updateData.length - 1];
  753. let parentGlj = me.getByConKey(parent.connect_key);
  754. for(let u of updateData){
  755. if(u.type == 'mix_ratio'){
  756. let tem = updateMap[u.query.id];
  757. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  758. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  759. if(subData){
  760. subData.consumption = u.doc.consumption;
  761. }
  762. let m_list = me.datas.mixRatioMap[parent.connect_key];
  763. let m_ratioData = _.find(m_list,{"id":u.query.id});
  764. if(m_ratioData){
  765. m_ratioData.consumption = u.doc.consumption;
  766. }
  767. }
  768. }
  769. parentGlj.unit_price.market_price = parent.market_price;
  770. parentGlj.unit_price.base_price = parent.base_price;
  771. me.calcQuantity();
  772. if(callback){
  773. callback();
  774. }
  775. $.bootstrapLoading.end();
  776. },function () {
  777. $.bootstrapLoading.end();
  778. })
  779. };
  780. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  781. let me = this;
  782. $.bootstrapLoading.start();
  783. CommonAjax.specialPost( '/glj/update',data,function (result) {
  784. let glj = me.getByID(data.id);//更新缓存
  785. let impactList = [];
  786. glj[data.field] = data.value;
  787. if(data.extend&&data.extend!=""){
  788. let extend = JSON.parse(data.extend);
  789. for (let key in extend) {
  790. glj[key] = extend[key];
  791. }
  792. }
  793. if(data.field == 'is_evaluate'){
  794. impactList = me.changeIsEvaluate(data.id);
  795. }
  796. if(callback){
  797. callback(impactList);
  798. }
  799. $.bootstrapLoading.end();
  800. });
  801. };
  802. ProjectGLJ.prototype.getRatioData=function(id,callback){
  803. this.getRatioId = id;
  804. if(id){
  805. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  806. let ratios = JSON.parse(response.data);
  807. if(callback){
  808. callback(ratios);
  809. }
  810. },function () {//取不到组成物的情况
  811. callback([]);
  812. })
  813. }else {
  814. if(callback){
  815. callback([]);
  816. }
  817. }
  818. };
  819. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  820. $.bootstrapLoading.start();
  821. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  822. projectObj.project.property.unitPriceFile = response.unitFile;
  823. projectObj.project.projectGLJ.loadData(function () {
  824. if(callback){
  825. callback();
  826. }
  827. $.bootstrapLoading.end();
  828. });
  829. }, function (err) {
  830. if($.bootstrapLoading.isLoading()){
  831. $.bootstrapLoading.end();
  832. }
  833. alert(err.msg);
  834. });
  835. };
  836. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  837. $.bootstrapLoading.start();
  838. try {
  839. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  840. await this.synLoadData();
  841. projectGljObject.refreshDataSheet();
  842. gljOprObj.refreshView();
  843. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  844. projectGljObject.onUnitFileChange();
  845. }catch (err){
  846. console.log(err);
  847. }finally {
  848. $.bootstrapLoading.end();
  849. }
  850. };
  851. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  852. let gljList = [],allGLJ = gljOprObj.AllRecode;
  853. if(selections.length == 0) {
  854. return;
  855. }
  856. for(let glj of allGLJ){
  857. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  858. if(_.includes(selections,i_key)){
  859. let pglj = {
  860. project_id: projectObj.project.ID(),
  861. glj_id: glj.ID,
  862. name: glj.name,
  863. code: glj.code,
  864. original_code: glj.code,
  865. unit: glj.unit,
  866. specs: glj.specs,
  867. base_price: glj.basePrice,
  868. market_price: glj.basePrice,
  869. shortName: glj.shortName,
  870. type: glj.gljType,
  871. model:glj.model,
  872. adjCoe: glj.adjCoe,
  873. from:'std',
  874. repositoryId:glj.repositoryId,
  875. materialType:glj.materialType,
  876. materialCoe:glj.materialCoe,
  877. grossWeightCoe:glj.grossWeightCoe,
  878. purchaseStorageRate:glj.purchaseStorageRate,
  879. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  880. handlingLossRate:glj.handlingLossRate
  881. };
  882. if (glj.hasOwnProperty("compilationId")) {
  883. pglj.from = "cpt";
  884. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  885. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  886. }
  887. }
  888. gljList.push(pglj);
  889. }
  890. }
  891. gljList = _.sortByAll(gljList, ['type', 'code']);
  892. if(gljList.length == 0) return;
  893. let praentInfo = {
  894. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  895. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  896. };
  897. $.bootstrapLoading.start();
  898. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  899. $.bootstrapLoading.end();
  900. if(callback){
  901. callback(data);
  902. }
  903. }, function () {
  904. $.bootstrapLoading.end();
  905. });
  906. }
  907. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  908. let property = projectObj.project.projectInfo.property;
  909. let data = {
  910. name:newVal,
  911. rootProjectID:property.rootProjectID
  912. }
  913. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  914. callback(data);
  915. });
  916. };
  917. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  918. $.bootstrapLoading.start();
  919. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  920. projectObj.project.projectGLJ.loadData(function () {
  921. if(callback){
  922. callback();
  923. }
  924. $.bootstrapLoading.end();
  925. });
  926. },function (response) {
  927. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  928. $("#save-as-tips").text(msg).show();
  929. $.bootstrapLoading.end();
  930. });
  931. };
  932. //更新是否暂估
  933. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  934. let projectGLJ = projectObj.project.projectGLJ;
  935. let datas = projectGLJ.datas;
  936. let gljList = datas.gljList;
  937. let glj = _.find(gljList, {'id': id});
  938. if(glj){//与批量更新调用相同的方法
  939. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  940. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  941. let conditions = [];
  942. if(pratioM&&pratioM.length>0){
  943. for(let p_key of pratioM ){
  944. conditions.push(gljOprObj.getConditionByKey(p_key));
  945. }
  946. }
  947. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  948. gljs.push(glj);
  949. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  950. //更新对应的工料机类型的定额
  951. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  952. let ration_nodes = [];
  953. for(r of rations){
  954. if(r){
  955. r.isEstimate =glj.is_evaluate?1:0;
  956. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  957. ration_node?ration_nodes.push(ration_node):'';
  958. }
  959. }
  960. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  961. for(rg of ration_glj_nodes){
  962. rg.data.isEstimate =glj.is_evaluate?1:0;
  963. ration_nodes.push(rg);
  964. }
  965. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  966. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  967. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  968. return gljs;
  969. }
  970. };
  971. /**
  972. * 批量更新是否暂估
  973. *传入项目工料机数组
  974. */
  975. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  976. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  977. for(let glj of gljs){
  978. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  979. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  980. let conditions = [];
  981. if(pratioM&&pratioM.length>0){
  982. for(let p_key of pratioM ){
  983. conditions.push(gljOprObj.getConditionByKey(p_key));
  984. }
  985. }
  986. let tem_gljs = this.getProjectGLJs(conditions,false);
  987. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  988. }
  989. impactGLJs = impactGLJs.concat(gljs);
  990. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  991. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  992. let neeRefreshNode = [];
  993. //更新对应的工料机类型的定额
  994. for(let item of projectObj.project.Ration.datas){
  995. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  996. let tem_g = changeMap[item.projectGLJID];
  997. item.isEstimate =tem_g.is_evaluate?1:0;
  998. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  999. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  1000. }
  1001. }
  1002. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1003. for(let rg of ration_glj_nodes){
  1004. let tem_g = changeMap[rg.data.projectGLJID];
  1005. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1006. neeRefreshNode.push(rg);
  1007. }
  1008. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1009. return [impactRationNodes,impactGLJs];
  1010. };
  1011. ProjectGLJ.prototype.getByID = function (ID) {
  1012. return _.find(this.datas.gljList,{'id':ID});
  1013. };
  1014. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1015. return _.find(this.datas.gljList,function (item) {
  1016. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1017. return tem_key == conkey
  1018. })
  1019. };
  1020. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1021. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1022. let me = this;
  1023. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1024. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1025. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1026. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1027. return true;
  1028. }
  1029. })
  1030. projectObj.mainController.refreshTreeNode(nodes);
  1031. }
  1032. }
  1033. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1034. let nodes = [];
  1035. let ids = [];
  1036. if(Array.isArray(id)){
  1037. ids = id;
  1038. }else {
  1039. ids = [id];
  1040. }
  1041. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1042. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1043. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1044. })
  1045. }
  1046. return nodes;
  1047. };
  1048. //根据工料机,取得所有受影响的定额节点
  1049. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1050. let nodes = [];
  1051. let rationMap = {};
  1052. let idArray = _.map(gljs,'id');
  1053. let gljMap = _.indexBy(gljs,'id');
  1054. //先根据项目工料机ID,找到受影响定额的ID
  1055. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1056. for (let rg of ration_glj_list) {
  1057. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1058. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1059. }
  1060. }
  1061. for (let item of projectObj.project.mainTree.items) {
  1062. if (item.sourceType == ModuleNames.ration) {
  1063. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1064. let tem_g = gljMap[item.data.projectGLJID];
  1065. if(tem_g){
  1066. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1067. item.data.marketPrice = this.getMarketPrice(tem_g);
  1068. nodes.push(item);
  1069. }
  1070. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1071. nodes.push(item)
  1072. }
  1073. }
  1074. }
  1075. return nodes;
  1076. };
  1077. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1078. for (let ration_glj of gljOprObj.sheetData) {
  1079. if (ration_glj.projectGLJID == glj.id) {
  1080. ration_glj.basePrice = this.getBasePrice(glj);
  1081. ration_glj.marketPrice = this.getMarketPrice(glj);
  1082. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1083. }
  1084. }
  1085. }
  1086. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1087. }
  1088. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1089. let parentGlj = [];
  1090. //
  1091. let projectGljs = this.datas.gljList;
  1092. let indexList = gljKeyArray;
  1093. for (let d of data) {
  1094. if (d) {
  1095. let glj = _.find(projectGljs, function (item) {
  1096. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1097. });
  1098. if (glj) {
  1099. if(refreshPrice==true){
  1100. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1101. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1102. this.setAdjustPrice(glj);
  1103. this.refreshRationGLJPrice(glj);
  1104. this.refreshTreeNodePriceIfNeed(glj);
  1105. }
  1106. parentGlj.push(glj);
  1107. }
  1108. }
  1109. }
  1110. return parentGlj;
  1111. }
  1112. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1113. switch (glj.unit_price.type + '') {
  1114. // 人工: 调整基价=基价单价*调整系数
  1115. case GLJTypeConst.LABOUR:
  1116. case GLJTypeConst.MACHINE_LABOUR:
  1117. glj.adjust_price = this.getAdjustPrice(glj);
  1118. break;
  1119. // 机械类型的算法
  1120. case GLJTypeConst.MACHINE:
  1121. console.log('机械');
  1122. break;
  1123. // 材料、主材、设备
  1124. default:
  1125. glj.adjust_price = glj.unit_price.base_price;
  1126. }
  1127. }
  1128. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1129. let proGLJ = projectObj.project.projectGLJ;
  1130. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1131. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1132. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1133. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1134. };
  1135. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1136. let proGLJ = projectObj.project.projectGLJ;
  1137. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1138. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1139. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1140. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1141. };
  1142. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1143. let proGLJ = projectObj.project.projectGLJ;
  1144. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1145. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1146. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1147. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1148. };
  1149. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1150. let proGLJ = projectObj.project.projectGLJ;
  1151. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1152. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1153. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1154. let tenderCoe = 1;
  1155. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1156. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1157. }
  1158. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1159. };
  1160. ProjectGLJ.prototype.isEstimateType = function(type){
  1161. let typeString = type + "";
  1162. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1163. return type;
  1164. }
  1165. return false;
  1166. };
  1167. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1168. let gljTypeMap = this.datas.constData.gljTypeMap;
  1169. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1170. };
  1171. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1172. let project_gljs = this.datas.gljList;
  1173. let changeArray=[];
  1174. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1175. let rationDatas = projectObj.project.Ration.datas;
  1176. let billsDatas = projectObj.project.Bills.datas;
  1177. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1178. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1179. this.quantityChangeMap = {};
  1180. for(let pglj of project_gljs){
  1181. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1182. }
  1183. }else if(this.quantityChangeMap != null){
  1184. for(let pglj of project_gljs){
  1185. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1186. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1187. changeArray.push(pglj);
  1188. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1189. }
  1190. }else { //映射表没有,说明是新添加的项目工料机
  1191. changeArray.push(pglj);
  1192. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1193. }
  1194. }
  1195. }
  1196. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1197. };
  1198. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1199. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1200. let rationDatas = projectObj.project.Ration.datas;
  1201. let billsDatas = projectObj.project.Bills.datas;
  1202. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1203. };