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,process);
  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,supplyLocation=p.supplyLocation;
  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. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  419. }
  420. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  421. if(p.ID ==dataMap["price"]["delete"]) continue;
  422. }
  423. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  424. coe = scMathUtil.roundForObj(coe,unitPirce);
  425. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  426. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  427. supplyList.push(supplyLocation);
  428. }
  429. supplyLocation = supplyList.join(',');
  430. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  431. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  432. original_price = doc['originalPrice']?doc['originalPrice']:glj.unit_price.originalPrice;
  433. supplyLocation = doc['supplyLocation']?doc['supplyLocation']:glj.unit_price.supplyLocation;
  434. }
  435. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation];
  436. };
  437. ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
  438. let me = this;
  439. let gljList = [];
  440. for(let d of datas){
  441. let g = updateUnit(d.id,d.unitPrice);
  442. if(g) gljList.push(g);
  443. }
  444. //刷新项目工料机表显示
  445. projectGljObject.refreshDataSheet();
  446. //重新计算相关节点
  447. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  448. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  449. //刷新定额工料机
  450. gljOprObj.refreshView();
  451. //socket推送更新信息
  452. projectGljObject.onUnitFileChange();
  453. function updateUnit(id,unitPrice) {
  454. let glj = _.find(me.datas.gljList,{'id':id});
  455. if(glj && !_.isEmpty(unitPrice.doc)){
  456. for(let key in unitPrice.doc){
  457. glj.unit_price[key] = unitPrice.doc[key];
  458. }
  459. }
  460. return glj;
  461. }
  462. };
  463. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  464. this.m_updateUnitPrice([{id:id,unitPrice:unitPrice}]);
  465. };
  466. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  467. try {
  468. let unitPrice = this.materialCal(pgljID,{price:{add:datas}});
  469. $.bootstrapLoading.start();
  470. let result = await ajaxPost('/glj/addOriginalCalc',{datas:datas,unitPrice:unitPrice});
  471. this.datas.originalList = this.datas.originalList.concat(result);
  472. this.updateUnitPrice(pgljID,unitPrice);
  473. materialCalcObj.showDatas();
  474. }catch (e){
  475. console.log(e)
  476. }finally {
  477. $.bootstrapLoading.end();
  478. }
  479. };
  480. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  481. let tasks = [];
  482. let updateDatas=[];
  483. try {
  484. for(let d of datas){
  485. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  486. if(_.isEmpty(unitPrice.doc)) continue;
  487. tasks.push({updateOne: {filter: {id: unitPrice.id,unit_price_file_id:unitPrice.unit_price_file_id}, update: unitPrice.doc}})
  488. updateDatas.push({id:d.id,unitPrice:unitPrice})
  489. }
  490. $.bootstrapLoading.start();
  491. let result = await ajaxPost('/glj/updateMaterialCalc',{tasks:tasks});
  492. this.m_updateUnitPrice(updateDatas);
  493. materialCalcObj.showDatas();
  494. }catch (e){
  495. console.log(e)
  496. }finally {
  497. $.bootstrapLoading.end();
  498. }
  499. };
  500. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  501. try {
  502. let updateMap = {};
  503. let tasks = [];
  504. for(let d of datas){
  505. updateMap[d.ID] = d.doc;
  506. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  507. }
  508. let unitPrice = this.materialCal(pgljID,{freight:{update:updateMap}});
  509. $.bootstrapLoading.start();
  510. let result = await ajaxPost('/glj/updateFreightCalc',{tasks:tasks,unitPrice:unitPrice});
  511. for(let o of this.datas.freightList){
  512. if(updateMap[o.ID]){
  513. gljUtil.updateProperty(o,updateMap[o.ID]);
  514. }
  515. }
  516. this.updateUnitPrice(pgljID,unitPrice);
  517. materialCalcObj.showDatas();
  518. }catch (e){
  519. console.log(e)
  520. }finally {
  521. $.bootstrapLoading.end();
  522. }
  523. };
  524. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  525. try {
  526. let updateMap = {};
  527. let tasks = [];
  528. for(let d of datas){
  529. updateMap[d.ID] = d.doc;
  530. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  531. }
  532. let unitPrice = this.materialCal(pgljID,{price:{update:updateMap}});
  533. $.bootstrapLoading.start();
  534. let result = await ajaxPost('/glj/updateOriginalCalc',{tasks:tasks,unitPrice:unitPrice});
  535. for(let o of this.datas.originalList){
  536. if(updateMap[o.ID]){
  537. gljUtil.updateProperty(o,updateMap[o.ID]);
  538. }
  539. }
  540. this.updateUnitPrice(pgljID,unitPrice);
  541. materialCalcObj.showDatas();
  542. }catch (e){
  543. console.log(e)
  544. }finally {
  545. $.bootstrapLoading.end();
  546. }
  547. };
  548. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  549. try {
  550. let unitPrice = this.materialCal(pgljID,{freight:{add:datas}});
  551. $.bootstrapLoading.start();
  552. let result = await ajaxPost('/glj/addFreightCalc',{datas:datas,unitPrice:unitPrice});
  553. this.datas.freightList = this.datas.freightList.concat(result);
  554. this.updateUnitPrice(pgljID,unitPrice);
  555. materialCalcObj.showDatas();
  556. }catch (e){
  557. console.log(e)
  558. }finally {
  559. $.bootstrapLoading.end();
  560. }
  561. };
  562. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  563. try {
  564. let data={ID:ID};
  565. // 计算预算价
  566. let unitPrice = this.materialCal(pgljID,{price:{'delete':ID}});
  567. data.unitPrice = unitPrice;
  568. $.bootstrapLoading.start();
  569. await ajaxPost('/glj/deletePriceCalc',data);
  570. _.remove(this.datas.originalList,{'ID':data.ID});
  571. //更新单价文件的值
  572. this.updateUnitPrice(pgljID,unitPrice);
  573. materialCalcObj.showDatas();
  574. }catch (e){
  575. console.log(e)
  576. }finally {
  577. $.bootstrapLoading.end();
  578. }
  579. };
  580. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  581. try {
  582. let data={ID:ID};
  583. // 计算预算价
  584. let unitPrice = this.materialCal(pgljID,{freight:{'delete':ID}});
  585. data.unitPrice = unitPrice;
  586. $.bootstrapLoading.start();
  587. let result = await ajaxPost('/glj/deleteFreightCalc',data);
  588. console.log(result);
  589. _.remove(this.datas.freightList,{'ID':data.ID});
  590. // 更新单价文件的值
  591. this.updateUnitPrice(pgljID,unitPrice);
  592. materialCalcObj.showDatas();
  593. }catch (e){
  594. console.log(e)
  595. }finally {
  596. $.bootstrapLoading.end();
  597. }
  598. };
  599. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  600. let me = this;
  601. let projectGljs = this.datas.gljList;
  602. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  603. let glj = _.find(projectGljs, {'id': pgljID});
  604. if (glj) {
  605. if(glj.unit_price[updateField] == newval){
  606. return;
  607. }
  608. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  609. 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};
  610. let callback = function (data) {
  611. if (updateField == 'base_price') {
  612. glj.unit_price.base_price = newval;
  613. me.setAdjustPrice(glj);
  614. } else {
  615. glj.unit_price.market_price = newval;
  616. }
  617. //更新回传的父节点项目工料机价格
  618. let gljs = me.getProjectGLJs(data);
  619. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  620. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  621. gljOprObj.showRationGLJSheetData();
  622. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  623. gljs.push(glj);
  624. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  625. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  626. projectGljObject.onUnitFileChange(data);
  627. if(cb){
  628. cb(gljs);
  629. }
  630. $.bootstrapLoading.end();
  631. }
  632. $.bootstrapLoading.start();
  633. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  634. $.bootstrapLoading.end();
  635. });
  636. } else {
  637. gljOprObj.showRationGLJSheetData();
  638. }
  639. };
  640. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  641. let me = this;
  642. //更新是否暂估和供货方式时,要做特殊处理
  643. $.bootstrapLoading.start();
  644. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  645. $.bootstrapLoading.end();
  646. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  647. console.log(updateMap);
  648. for(let idKey in updateMap){
  649. let gljID = parseInt(idKey);
  650. let glj = me.getByID(gljID);
  651. let doc = updateMap[idKey];
  652. for(let property in doc){
  653. glj[property] = doc[property];
  654. }
  655. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  656. supplyChangeIDs.push(gljID);
  657. }
  658. if(doc.hasOwnProperty("is_evaluate")){
  659. evaluate_gljs.push(glj);
  660. }
  661. }
  662. if(supplyChangeIDs.length>0){
  663. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  664. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  665. }
  666. if(evaluate_gljs.length > 0){
  667. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  668. rationNodes = rationNodes.concat(impactRationNodes);
  669. }
  670. if(rationNodes.length > 0){
  671. rationNodes = _.uniq(rationNodes,'data');
  672. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  673. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  674. });
  675. }
  676. if(callback){
  677. callback();
  678. }
  679. })
  680. };
  681. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  682. let me = this;
  683. let projectGljs = me.datas.gljList;
  684. let updateData = [];
  685. let newValueMap = {};
  686. let gljs=[];
  687. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  688. if(changeInfo.length<=0){
  689. callback?callback():'';
  690. return
  691. }
  692. for(let ci of changeInfo){
  693. let dataCode = setting.header[ci.col].dataCode;
  694. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  695. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  696. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  697. let glj = _.find(projectGljs, {'id': recode.id});
  698. let newValue = ci.value;
  699. if(glj&&glj.unit_price[editField]!=newValue){
  700. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  701. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  702. newValueMap[glj.id]={field:editField,value:newValue};
  703. gljs.push(glj);
  704. }
  705. }
  706. }
  707. console.log(updateData);
  708. if(updateData.length > 0){
  709. $.bootstrapLoading.start();
  710. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  711. let parentData = [];
  712. //更新缓存
  713. for(let g of gljs){
  714. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  715. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  716. }
  717. //更新父工料机价格
  718. for(let r of result){
  719. let pdata = r.updateOne.filter;
  720. let set = r.updateOne.update.$set;
  721. for(let skey in set){
  722. pdata[skey] = set[skey];
  723. }
  724. parentData.push(pdata);
  725. }
  726. let pgljs = me.getProjectGLJs(parentData);
  727. gljs = gljs.concat(pgljs);
  728. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  729. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  730. gljOprObj.showRationGLJSheetData();
  731. projectGljObject.onUnitFileChange(gljs);
  732. if(callback){
  733. callback(gljs);
  734. }
  735. $.bootstrapLoading.end();
  736. }, function (err) {
  737. $.bootstrapLoading.end();
  738. });
  739. }
  740. };
  741. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  742. let me = this;
  743. $.bootstrapLoading.start();
  744. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  745. let parent = updateData[updateData.length - 1];
  746. let parentGlj = me.getByConKey(parent.connect_key);
  747. for(let u of updateData){
  748. if(u.type == 'mix_ratio'){
  749. let tem = updateMap[u.query.id];
  750. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  751. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  752. if(subData){
  753. subData.consumption = u.doc.consumption;
  754. }
  755. let m_list = me.datas.mixRatioMap[parent.connect_key];
  756. let m_ratioData = _.find(m_list,{"id":u.query.id});
  757. if(m_ratioData){
  758. m_ratioData.consumption = u.doc.consumption;
  759. }
  760. }
  761. }
  762. parentGlj.unit_price.market_price = parent.market_price;
  763. parentGlj.unit_price.base_price = parent.base_price;
  764. me.calcQuantity();
  765. if(callback){
  766. callback();
  767. }
  768. $.bootstrapLoading.end();
  769. },function () {
  770. $.bootstrapLoading.end();
  771. })
  772. };
  773. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  774. let me = this;
  775. $.bootstrapLoading.start();
  776. CommonAjax.specialPost( '/glj/update',data,function (result) {
  777. let glj = me.getByID(data.id);//更新缓存
  778. let impactList = [];
  779. glj[data.field] = data.value;
  780. if(data.extend&&data.extend!=""){
  781. let extend = JSON.parse(data.extend);
  782. for (let key in extend) {
  783. glj[key] = extend[key];
  784. }
  785. }
  786. if(data.field == 'is_evaluate'){
  787. impactList = me.changeIsEvaluate(data.id);
  788. }
  789. if(callback){
  790. callback(impactList);
  791. }
  792. $.bootstrapLoading.end();
  793. });
  794. };
  795. ProjectGLJ.prototype.getRatioData=function(id,callback){
  796. this.getRatioId = id;
  797. if(id){
  798. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  799. let ratios = JSON.parse(response.data);
  800. if(callback){
  801. callback(ratios);
  802. }
  803. },function () {//取不到组成物的情况
  804. callback([]);
  805. })
  806. }else {
  807. if(callback){
  808. callback([]);
  809. }
  810. }
  811. };
  812. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  813. $.bootstrapLoading.start();
  814. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  815. projectObj.project.property.unitPriceFile = response.unitFile;
  816. projectObj.project.projectGLJ.loadData(function () {
  817. if(callback){
  818. callback();
  819. }
  820. $.bootstrapLoading.end();
  821. });
  822. }, function (err) {
  823. if($.bootstrapLoading.isLoading()){
  824. $.bootstrapLoading.end();
  825. }
  826. alert(err.msg);
  827. });
  828. };
  829. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  830. $.bootstrapLoading.start();
  831. try {
  832. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  833. await this.synLoadData();
  834. projectGljObject.refreshDataSheet();
  835. gljOprObj.refreshView();
  836. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  837. projectGljObject.onUnitFileChange();
  838. }catch (err){
  839. console.log(err);
  840. }finally {
  841. $.bootstrapLoading.end();
  842. }
  843. };
  844. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  845. let gljList = [],allGLJ = gljOprObj.AllRecode;
  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 = projectObj.project.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) && projectObj.project.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(projectObj.project.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=projectObj.project.projectInfo.property.calcOptions;
  1124. let decimalObj = projectObj.project.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=projectObj.project.projectInfo.property.calcOptions;
  1131. let decimalObj = projectObj.project.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=projectObj.project.projectInfo.property.calcOptions;
  1138. let decimalObj = projectObj.project.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=projectObj.project.projectInfo.property.calcOptions;
  1145. let decimalObj = projectObj.project.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. };