project_glj.js 51 KB

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