project_glj.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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,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. $("#glj_tree_div").modal('hide');
  847. if(selections.length == 0) {
  848. return;
  849. }
  850. for(let glj of allGLJ){
  851. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  852. if(_.includes(selections,i_key)){
  853. let pglj = {
  854. project_id: projectObj.project.ID(),
  855. glj_id: glj.ID,
  856. name: glj.name,
  857. code: glj.code,
  858. original_code: glj.code,
  859. unit: glj.unit,
  860. specs: glj.specs,
  861. base_price: glj.basePrice,
  862. market_price: glj.basePrice,
  863. shortName: glj.shortName,
  864. type: glj.gljType,
  865. model:glj.model,
  866. adjCoe: glj.adjCoe,
  867. from:'std',
  868. repositoryId:glj.repositoryId,
  869. materialType:glj.materialType,
  870. materialCoe:glj.materialCoe,
  871. grossWeightCoe:glj.grossWeightCoe,
  872. purchaseStorageRate:glj.purchaseStorageRate,
  873. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  874. handlingLossRate:glj.handlingLossRate
  875. };
  876. if (glj.hasOwnProperty("compilationId")) {
  877. pglj.from = "cpt";
  878. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  879. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  880. }
  881. }
  882. gljList.push(pglj);
  883. }
  884. }
  885. gljList = _.sortByAll(gljList, ['type', 'code']);
  886. if(gljList.length == 0) return;
  887. let praentInfo = {
  888. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  889. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  890. };
  891. $.bootstrapLoading.start();
  892. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  893. $.bootstrapLoading.end();
  894. if(callback){
  895. callback(data);
  896. }
  897. }, function () {
  898. $.bootstrapLoading.end();
  899. });
  900. }
  901. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  902. let property = projectInfoObj.projectInfo.property;
  903. let data = {
  904. name:newVal,
  905. rootProjectID:property.rootProjectID
  906. }
  907. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  908. callback(data);
  909. });
  910. };
  911. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  912. $.bootstrapLoading.start();
  913. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  914. projectObj.project.projectGLJ.loadData(function () {
  915. if(callback){
  916. callback();
  917. }
  918. $.bootstrapLoading.end();
  919. });
  920. },function (response) {
  921. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  922. $("#save-as-tips").text(msg).show();
  923. $.bootstrapLoading.end();
  924. });
  925. };
  926. //更新是否暂估
  927. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  928. let projectGLJ = projectObj.project.projectGLJ;
  929. let datas = projectGLJ.datas;
  930. let gljList = datas.gljList;
  931. let glj = _.find(gljList, {'id': id});
  932. if(glj){//与批量更新调用相同的方法
  933. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  934. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  935. let conditions = [];
  936. if(pratioM&&pratioM.length>0){
  937. for(let p_key of pratioM ){
  938. conditions.push(gljOprObj.getConditionByKey(p_key));
  939. }
  940. }
  941. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  942. gljs.push(glj);
  943. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  944. //更新对应的工料机类型的定额
  945. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  946. let ration_nodes = [];
  947. for(r of rations){
  948. if(r){
  949. r.isEstimate =glj.is_evaluate?1:0;
  950. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  951. ration_node?ration_nodes.push(ration_node):'';
  952. }
  953. }
  954. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  955. for(rg of ration_glj_nodes){
  956. rg.data.isEstimate =glj.is_evaluate?1:0;
  957. ration_nodes.push(rg);
  958. }
  959. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  960. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  961. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  962. return gljs;
  963. }
  964. };
  965. /**
  966. * 批量更新是否暂估
  967. *传入项目工料机数组
  968. */
  969. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  970. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  971. for(let glj of gljs){
  972. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  973. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  974. let conditions = [];
  975. if(pratioM&&pratioM.length>0){
  976. for(let p_key of pratioM ){
  977. conditions.push(gljOprObj.getConditionByKey(p_key));
  978. }
  979. }
  980. let tem_gljs = this.getProjectGLJs(conditions,false);
  981. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  982. }
  983. impactGLJs = impactGLJs.concat(gljs);
  984. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  985. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  986. let neeRefreshNode = [];
  987. //更新对应的工料机类型的定额
  988. for(let item of projectObj.project.Ration.datas){
  989. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  990. let tem_g = changeMap[item.projectGLJID];
  991. item.isEstimate =tem_g.is_evaluate?1:0;
  992. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  993. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  994. }
  995. }
  996. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  997. for(let rg of ration_glj_nodes){
  998. let tem_g = changeMap[rg.data.projectGLJID];
  999. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1000. neeRefreshNode.push(rg);
  1001. }
  1002. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1003. return [impactRationNodes,impactGLJs];
  1004. };
  1005. ProjectGLJ.prototype.getByID = function (ID) {
  1006. return _.find(this.datas.gljList,{'id':ID});
  1007. };
  1008. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1009. return _.find(this.datas.gljList,function (item) {
  1010. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1011. return tem_key == conkey
  1012. })
  1013. };
  1014. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1015. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1016. let me = this;
  1017. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1018. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1019. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1020. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1021. return true;
  1022. }
  1023. })
  1024. projectObj.mainController.refreshTreeNode(nodes);
  1025. }
  1026. }
  1027. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1028. let nodes = [];
  1029. let ids = [];
  1030. if(Array.isArray(id)){
  1031. ids = id;
  1032. }else {
  1033. ids = [id];
  1034. }
  1035. if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1036. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1037. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1038. })
  1039. }
  1040. return nodes;
  1041. };
  1042. //根据工料机,取得所有受影响的定额节点
  1043. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1044. let nodes = [];
  1045. let rationMap = {};
  1046. let idArray = _.map(gljs,'id');
  1047. let gljMap = _.indexBy(gljs,'id');
  1048. //先根据项目工料机ID,找到受影响定额的ID
  1049. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1050. for (let rg of ration_glj_list) {
  1051. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1052. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1053. }
  1054. }
  1055. for (let item of projectObj.project.mainTree.items) {
  1056. if (item.sourceType == ModuleNames.ration) {
  1057. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1058. let tem_g = gljMap[item.data.projectGLJID];
  1059. if(tem_g){
  1060. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1061. item.data.marketPrice = this.getMarketPrice(tem_g);
  1062. nodes.push(item);
  1063. }
  1064. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1065. nodes.push(item)
  1066. }
  1067. }
  1068. }
  1069. return nodes;
  1070. };
  1071. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1072. for (let ration_glj of gljOprObj.sheetData) {
  1073. if (ration_glj.projectGLJID == glj.id) {
  1074. ration_glj.basePrice = this.getBasePrice(glj);
  1075. ration_glj.marketPrice = this.getMarketPrice(glj);
  1076. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1077. }
  1078. }
  1079. }
  1080. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1081. }
  1082. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1083. let parentGlj = [];
  1084. //
  1085. let projectGljs = this.datas.gljList;
  1086. let indexList = gljKeyArray;
  1087. for (let d of data) {
  1088. if (d) {
  1089. let glj = _.find(projectGljs, function (item) {
  1090. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1091. });
  1092. if (glj) {
  1093. if(refreshPrice==true){
  1094. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1095. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1096. this.setAdjustPrice(glj);
  1097. this.refreshRationGLJPrice(glj);
  1098. this.refreshTreeNodePriceIfNeed(glj);
  1099. }
  1100. parentGlj.push(glj);
  1101. }
  1102. }
  1103. }
  1104. return parentGlj;
  1105. }
  1106. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1107. switch (glj.unit_price.type + '') {
  1108. // 人工: 调整基价=基价单价*调整系数
  1109. case GLJTypeConst.LABOUR:
  1110. case GLJTypeConst.MACHINE_LABOUR:
  1111. glj.adjust_price = this.getAdjustPrice(glj);
  1112. break;
  1113. // 机械类型的算法
  1114. case GLJTypeConst.MACHINE:
  1115. console.log('机械');
  1116. break;
  1117. // 材料、主材、设备
  1118. default:
  1119. glj.adjust_price = glj.unit_price.base_price;
  1120. }
  1121. }
  1122. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1123. let proGLJ = projectObj.project.projectGLJ;
  1124. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  1125. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  1126. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1127. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1128. };
  1129. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1130. let proGLJ = projectObj.project.projectGLJ;
  1131. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  1132. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  1133. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1134. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1135. };
  1136. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1137. let proGLJ = projectObj.project.projectGLJ;
  1138. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  1139. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  1140. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1141. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1142. };
  1143. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1144. let proGLJ = projectObj.project.projectGLJ;
  1145. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  1146. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  1147. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1148. let tenderCoe = 1;
  1149. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1150. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1151. }
  1152. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1153. };
  1154. ProjectGLJ.prototype.isEstimateType = function(type){
  1155. let typeString = type + "";
  1156. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1157. return type;
  1158. }
  1159. return false;
  1160. };
  1161. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1162. let gljTypeMap = this.datas.constData.gljTypeMap;
  1163. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1164. };
  1165. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1166. let project_gljs = this.datas.gljList;
  1167. let changeArray=[];
  1168. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1169. let rationDatas = projectObj.project.Ration.datas;
  1170. let billsDatas = projectObj.project.Bills.datas;
  1171. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1172. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1173. this.quantityChangeMap = {};
  1174. for(let pglj of project_gljs){
  1175. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1176. }
  1177. }else if(this.quantityChangeMap != null){
  1178. for(let pglj of project_gljs){
  1179. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1180. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1181. changeArray.push(pglj);
  1182. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1183. }
  1184. }else { //映射表没有,说明是新添加的项目工料机
  1185. changeArray.push(pglj);
  1186. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1187. }
  1188. }
  1189. }
  1190. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1191. };
  1192. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1193. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1194. let rationDatas = projectObj.project.Ration.datas;
  1195. let billsDatas = projectObj.project.Bills.datas;
  1196. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1197. };