project_glj.js 51 KB

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