project_glj.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  1. /**
  2. * 工料机汇总相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/14
  6. * @version
  7. */
  8. function ProjectGLJ() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. this.quantityChangeMap=null;
  12. this.getRatioId = null;
  13. }
  14. /**
  15. * 加载数据
  16. *
  17. * @param {function} callback
  18. * @return {boolean}
  19. */
  20. ProjectGLJ.prototype.loadData = function (callback = null,error=null) {
  21. let self = this;
  22. if (self.isLoading) {
  23. return false;
  24. }
  25. // 加载工料机数据
  26. $.ajax({
  27. url: '/glj/getData',
  28. type: 'post',
  29. dataType: 'json',
  30. data: {project_id: scUrlUtil.GetQueryString('project')},
  31. error: function () {
  32. // alert('数据传输错误');
  33. if(error) error();
  34. },
  35. beforeSend: function () {
  36. self.isLoading = true;
  37. },
  38. success: function (response) {
  39. self.isLoading = false;
  40. if (response.err === 1) {
  41. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取人材机数据失败!';
  42. alert(msg);
  43. if(error) error();
  44. return false;
  45. }
  46. self.refreshByDatas(response.data);
  47. // 回调函数
  48. if (callback !== null) {
  49. callback(response.data);
  50. }
  51. // 存入缓存
  52. projectObj.project.projectGLJ = self;
  53. }
  54. });
  55. };
  56. //更新项目工料机数据和缓存
  57. ProjectGLJ.prototype.refreshByDatas = function(datas){
  58. this.datas = datas;
  59. this.calcQuantity();
  60. };
  61. ProjectGLJ.prototype.synLoadData = function () {
  62. return new Promise(function (resolve, reject) {
  63. projectObj.project.projectGLJ.loadData(function (data) {
  64. resolve(data)
  65. },function () {
  66. reject("获取工料机数据失败")
  67. })
  68. })
  69. }
  70. ProjectGLJ.prototype.loadToCache = function (data) {
  71. this.datas = data;
  72. projectObj.project.projectGLJ = this;
  73. }
  74. /**
  75. * 获取对应工料机数据
  76. *
  77. * @param {String} code
  78. * @return {Object}
  79. */
  80. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  81. return _.find(this.datas.gljList, {'id': ID});
  82. };
  83. // CSL, 2018-02-08 甲供、甲定。
  84. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  85. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  86. // 所以这里要合并处理。
  87. let mixSupply = [];
  88. for (let s of supplyTypeArr){
  89. switch (s) {
  90. case 1:
  91. mixSupply.push('部分甲供');
  92. break;
  93. case 2:
  94. mixSupply.push('完全甲供');
  95. break;
  96. case 3:
  97. mixSupply.push('甲定乙供');
  98. break;
  99. default:
  100. mixSupply.push('自行采购');
  101. }
  102. };
  103. mixSupply = mixSupply.concat(supplyTypeArr);
  104. return _.filter(this.datas.gljList, function (glj) {
  105. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  106. });
  107. };
  108. ProjectGLJ.prototype.testGLJs = function () {
  109. let gljs = [];
  110. for (let glj of this.datas.gljList){
  111. let o = new Object();
  112. o.name = glj.name;
  113. o.supply = glj.supply;
  114. o.quantity = glj.quantity;
  115. o.supply_quantity = glj.supply_quantity;
  116. gljs.push(o);
  117. };
  118. return gljs;
  119. };
  120. /**
  121. * 修改工料机数据
  122. *
  123. * @param {Number} id
  124. * @param {Object} data
  125. * @return {boolean}
  126. */
  127. ProjectGLJ.prototype.updateData = function (id, data) {
  128. let result = false;
  129. if (this.datas === null) {
  130. return result;
  131. }
  132. let gljList = this.datas.gljList;
  133. if (gljList === undefined) {
  134. return result;
  135. }
  136. // 查找对应的index
  137. let index = -1;
  138. for (let tmp in gljList) {
  139. if (gljList[tmp].id === id) {
  140. index = tmp;
  141. break;
  142. }
  143. }
  144. if (index < 0) {
  145. return result;
  146. }
  147. // 修改数据
  148. for (let tmpIndex in data) {
  149. if (tmpIndex.indexOf('_price') >= 0) {
  150. // 修改unit_price中的对象
  151. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  152. } else {
  153. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  154. }
  155. }
  156. };
  157. /**
  158. * 加载缓存数据到spread
  159. *
  160. * @return {void}
  161. */
  162. ProjectGLJ.prototype.loadCacheData = function (resort) {
  163. // 加载工料机数据
  164. let data = this.datas === null ? null : this.datas;
  165. if (data === null) {
  166. return;
  167. }
  168. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  169. console.log("filter start");
  170. jsonData = filterProjectGLJ(jsonData);
  171. console.log("filter end");
  172. jsonData = sortProjectGLJ(jsonData);
  173. console.log("sort end");
  174. if(projectGLJSheet&&projectGLJSpread){
  175. setTimeout(spreadInit, 1);
  176. /*projectGLJSheet.setData(jsonData);
  177. projectGLJSpread.specialColumn(jsonData);*/
  178. }
  179. };
  180. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval,callback) {
  181. if (updateField == 'marketPrice') {
  182. this.updatePrice(recode, "market_price", newval,"rg",callback);
  183. }
  184. if (updateField == 'basePrice') {
  185. this.updatePrice(recode, "base_price", newval,"rg",callback);
  186. }
  187. };
  188. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  189. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  190. projectObj.project.Ration.updateContain(newval,node);
  191. }if(updateField == "quantity"){
  192. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  193. } else {
  194. this.updateGLJProperty(node, updateField, newval);
  195. }
  196. };
  197. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  198. let rationTypeGLJ = node.data;
  199. let postData = {};
  200. if (rationTypeGLJ[updateField] == newval) {
  201. projectObj.mainController.refreshTreeNode([node]);
  202. return;
  203. }
  204. let data = {
  205. glj_id: rationTypeGLJ.GLJID,
  206. project_id: rationTypeGLJ.projectID,
  207. code: rationTypeGLJ.code,
  208. original_code: rationTypeGLJ.original_code,
  209. name: rationTypeGLJ.name,
  210. shortName: rationTypeGLJ.shortName,
  211. specs: rationTypeGLJ.specs,
  212. unit: rationTypeGLJ.unit,
  213. type: rationTypeGLJ.subType,
  214. type_of_work: rationTypeGLJ.subType,
  215. base_price: rationTypeGLJ.basePrice,
  216. market_price: rationTypeGLJ.basePrice,
  217. repositoryId: rationTypeGLJ.repositoryId,
  218. adjCoe: rationTypeGLJ.adjCoe,
  219. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  220. };
  221. if (updateField == 'subType') {
  222. data.type = newval;
  223. data.type_of_work = newval;
  224. data.shortName = this.getShortNameByID(newval);
  225. } else {
  226. data[updateField] = newval;
  227. }
  228. postData.ration = {
  229. ID: rationTypeGLJ.ID,
  230. projectID: rationTypeGLJ.projectID
  231. };
  232. postData.updateData = data;
  233. $.bootstrapLoading.start();
  234. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  235. console.log(result); //更新节点信息
  236. node.updateData[updateField] = newval;
  237. node.updateData.projectGLJID = result.id;
  238. node.updateData.code = result.code;
  239. node.updateData.basePrice = result.unit_price.base_price;
  240. node.updateData.marketUnitFee = result.unit_price.market_price;
  241. node.updateData.isAdd = result.unit_price.is_add;
  242. node.updateData.isEstimate = result.is_evaluate;
  243. node.updateData.shortName = result.unit_price.short_name;
  244. //触发计算并更新节点信息
  245. node.changed = true;
  246. projectObj.project.projectGLJ.loadData(function () {
  247. projectObj.project.calcProgram.calcAndSave(node);
  248. $.bootstrapLoading.end();
  249. });//重新加载项目工料机数据
  250. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  251. }, function (err) {
  252. $.bootstrapLoading.end();
  253. });
  254. }
  255. ProjectGLJ.prototype.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  256. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  257. return getDecimal("glj.unitPriceHasMix");
  258. }else {
  259. return getDecimal('glj.unitPrice');
  260. }
  261. };
  262. ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,value,ext) {//只有添加、删除走这个方法
  263. let glj = _.find(this.datas.gljList,{'id':projectGLJ.id});
  264. if (glj) {
  265. if(glj.unit_price[updateField] == value){
  266. return;
  267. }
  268. if(updateField == 'calcMaterial'){
  269. ext=ext?ext:{};
  270. if(value == 1){//添加材料计算操作,把单位毛重/采购保管费率等数据复制一份
  271. ext['grossWeightCoe_n'] = glj.unit_price.grossWeightCoe;
  272. ext['purchaseStorageRate_n'] = glj.unit_price.purchaseStorageRate;
  273. ext['offSiteTransportLossRate_n'] = glj.unit_price.offSiteTransportLossRate;
  274. ext['handlingLossRate_n'] = glj.unit_price.handlingLossRate;
  275. ext['totalLoadingTimes'] = '1';
  276. }else if(value == 0){//删除操作,恢复单位毛重/采购保管费率等数据
  277. ext['supplyLocation'] = '';
  278. ext['originalPrice'] = '0';
  279. ext['unitFreight']='0';
  280. ext['totalLoadingTimes']='0';
  281. ext['offSiteTransportLoss']='0';
  282. ext['purchaseStorage']='0';
  283. ext['packageRecoverValue']='0';
  284. }
  285. }
  286. let data = {id: glj.unit_price.id,updateField:updateField ,value: value,unit_price_file_id:glj.unit_price.unit_price_file_id,ext:ext};
  287. $.bootstrapLoading.start();
  288. try {
  289. let result = await ajaxPost('/glj/updateCalcMaterial',data);
  290. glj.unit_price[updateField] = value;
  291. if(ext){
  292. for(let key in ext){
  293. glj.unit_price[key] = ext[key];
  294. }
  295. }
  296. if(updateField == 'calcMaterial' && value ==0){///标记为0即删除材料计算标记,要删除其下挂的原价计算,运费计算,定额计算,消耗量重新计算
  297. let connect_key = gljUtil.getIndex(glj);
  298. _.remove(this.datas.originalList,{'connect_key':connect_key});
  299. _.remove(this.datas.freightList,{'connect_key':connect_key});
  300. this.calcQuantity();
  301. // to do 删除定额计算
  302. }
  303. projectGljObject.refreshDataSheet();
  304. materialCalcObj.showDatas();
  305. }catch (e){
  306. console.log(e)
  307. }finally {
  308. $.bootstrapLoading.end();
  309. }
  310. }
  311. };
  312. ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs,isFromFeeRate) {//当材料发生改变时重算所有计算材料的价格
  313. let priceMap = {};
  314. for(let unitPrice of unitPriecs){
  315. if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
  316. }
  317. let freightListMap = _.groupBy(this.datas.freightList,'connect_key');//取运费计算项映射表
  318. let originalListMap = _.groupBy(this.datas.originalList,'connect_key');//取原价计算项映射表
  319. let sumFreightUpdateMap = {}; //存放所有材料下的运费更新信息;
  320. let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
  321. for(let g of this.datas.gljList){
  322. if(g.quantity !== 0 && g.quantity !== '0' && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
  323. //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
  324. let fOrPDataMap = {};
  325. let tIndex = gljUtil.getIndex(g);
  326. //运费和原价中的工料机只要有一个包含该材料,就要重算
  327. if(freightListMap[tIndex]){ //运费重算
  328. let freightUpdateMap = {};
  329. for(let f of freightListMap[tIndex]){
  330. if(f.conveyance != "自办运输") continue;//不是自办运输的不用管
  331. let calf = ifNeedReCalc(f,priceMap);
  332. if(calf){
  333. let f_task = this.calcEachFreightOrPrice(f,"freight",priceMap);
  334. if(f_task){
  335. freightUpdateMap[f_task.ID] = f_task.doc;
  336. sumFreightUpdateMap[f_task.ID] = f_task.doc;
  337. }
  338. }
  339. }
  340. if(!_.isEmpty(freightUpdateMap)) fOrPDataMap["freight"] = {update:freightUpdateMap};
  341. }
  342. //原价重算
  343. if(originalListMap[tIndex]){ //运费重算
  344. let originalUpdateMap = {};
  345. for(let o of originalListMap[tIndex]){
  346. let calo = ifNeedReCalc(o,priceMap,isFromFeeRate);
  347. if(calo){
  348. let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
  349. if(o_task){
  350. originalUpdateMap[o_task.ID] = o_task.doc;
  351. sumOriginalUpdateMap[o_task.ID] = o_task.doc;
  352. }
  353. }
  354. }
  355. if(!_.isEmpty(originalUpdateMap)) fOrPDataMap["price"] = {update:originalUpdateMap};
  356. }
  357. //判断映射表是否为空,如果为空则说明不用计算
  358. if(!_.isEmpty(fOrPDataMap)){
  359. let t_unipPrice = this.materialCal(g.id,fOrPDataMap,g,freightListMap[tIndex],originalListMap[tIndex]);
  360. if(t_unipPrice) unitPriecs.push(t_unipPrice);
  361. }
  362. }
  363. }
  364. let sumUpdateMap = {};
  365. if(!_.isEmpty(sumFreightUpdateMap))sumUpdateMap["freight"] = {update:sumFreightUpdateMap};
  366. if(!_.isEmpty(sumOriginalUpdateMap))sumUpdateMap["price"] = {update:sumOriginalUpdateMap};
  367. let ext = {};
  368. for(let u of unitPriecs){//计算受影响的综合电价
  369. ext[u.projectGLJID] = {marketPrice:u.doc.market_price}; //priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
  370. }
  371. let elecu = electrovalenceObj.clacNewElecPrice(ext);
  372. if(elecu) unitPriecs.push(elecu);
  373. return [unitPriecs,sumUpdateMap];
  374. function ifNeedReCalc(obj,IDMap,isFromFeeRate = false) {
  375. let calcf = false;
  376. if(isFromFeeRate == true) return true;//如果是从费率过来的,默认自动计算
  377. if(obj.ration_gljs){
  378. for(let rg of obj.ration_gljs){
  379. if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
  380. calcf = true;
  381. break;
  382. }
  383. }
  384. }
  385. return calcf;
  386. }
  387. };
  388. ProjectGLJ.prototype.materialCal = function (id,dataMap,tglj,tfreightList,tpriceList) {
  389. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  390. let unitPirceDecimal = getDecimal("glj.unitPrice");
  391. let process = getDecimal("process");
  392. let glj = tglj?tglj: _.find(this.datas.gljList,{'id':id});
  393. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  394. if(!glj) return;
  395. let unitPrice = {projectGLJID:glj.id,id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  396. //先计算原价
  397. let [originalPrice,supplyLocation,priceHeightFee] = this.priceCalc(glj,dataMap,tpriceList);
  398. doc['originalPrice'] = originalPrice+'';
  399. doc['supplyLocation'] = supplyLocation;
  400. doc['priceHeightFee'] = priceHeightFee;
  401. //再计算运费
  402. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  403. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  404. let [unitFreight,freightHeightFee] = this.freightCalc(glj,grossWeightCoe_n,dataMap,tfreightList);
  405. doc['unitFreight'] = unitFreight+'';
  406. doc['freightHeightFee'] = freightHeightFee+'';
  407. //计算场外运输损耗
  408. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  409. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  410. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  411. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  412. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  413. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  414. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  415. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  416. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  417. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  418. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  419. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  420. //计算采购及保管费
  421. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  422. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  423. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  424. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  425. doc['purchaseStorage'] = purchaseStorage+'';
  426. //再计算预算价
  427. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  428. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  429. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  430. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  431. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  432. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  433. let o_unit = glj.unit_price;
  434. for(let key in doc){
  435. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  436. unitPrice.doc[key] = doc[key];
  437. }
  438. return unitPrice
  439. };
  440. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreightList) {
  441. let process = getDecimal("process");
  442. let unitPirce = getDecimal("glj.unitPrice");
  443. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  444. let sum = 0;
  445. let height_sum=0;
  446. let freightList = tfreightList?tfreightList:_.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  447. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  448. for(let f of freightList){
  449. let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe,conveyance = f.conveyance,calcType=f.calcType,materialType=f.materialType;
  450. let heightFee= f.heightFee?f.heightFee:0;
  451. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  452. let t = dataMap["freight"]["update"][f.ID];
  453. if(t){
  454. if(t['unitFreight']) unitFreight = t['unitFreight'];
  455. if(t['kmDistance']) kmDistance = t['kmDistance'];
  456. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  457. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  458. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  459. if(t['otherFee']) otherFee = t['otherFee'];
  460. if(t['weightCoe']) weightCoe = t['weightCoe'];
  461. if(t['conveyance']) conveyance = t['conveyance'];
  462. if(t['calcType']) calcType = t['calcType'];
  463. if(t['materialType']) materialType = t['materialType'];
  464. if(t['heightFee']) heightFee = t['heightFee'];
  465. }
  466. }
  467. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  468. if(dataMap["freight"]["delete"][f.ID]) continue;
  469. }
  470. //开始计算
  471. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  472. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  473. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  474. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  475. heightFee = scMathUtil.roundForObj(heightFee,unitPirce);
  476. let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
  477. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  478. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  479. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  480. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  481. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  482. if(gljUtil.isDef(materialType)&&materialType != "") t = scMathUtil.roundForObj(t/1.09,process); //内蒙古要除以税率1.09; 当材料类型有值时,说明是内蒙古计算
  483. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  484. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  485. if(conveyance !== "自办运输") t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  486. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  487. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  488. sum = scMathUtil.roundForObj(sum + t,process);
  489. heightFee = scMathUtil.roundForObj(heightFee*weightCoe,process);
  490. height_sum = scMathUtil.roundForObj(height_sum + heightFee,process);
  491. }
  492. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  493. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  494. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  495. }
  496. return [scMathUtil.roundForObj(sum,unitPirce),scMathUtil.roundForObj(height_sum,unitPirce)];
  497. function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
  498. if(gljUtil.isDef(materialType)&&materialType != "") return materialCalcObj.calNeiMengTotalFreight(kmDistance,materialType);
  499. //如果运输方式为自办运输,则直接返回单位运价即可;
  500. let price = conveyance == "自办运输" ? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  501. return price
  502. }
  503. };
  504. ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
  505. let process = getDecimal("process");
  506. let unitPirce = getDecimal("glj.unitPrice");
  507. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  508. let original_price = 0;
  509. let sumFeightFee = 0;
  510. let supplyList = [];
  511. let supplyLocation = "";
  512. let priceList = tpriceList?tpriceList:_.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  513. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  514. for(let p of priceList){
  515. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  516. let heightFee = p.heightFee?p.heightFee:0;
  517. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  518. let t = dataMap["price"]["update"][p.ID];
  519. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  520. if(t && t["coe"]) coe =t["coe"];
  521. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  522. if(t && t["heightFee"]) heightFee = t["heightFee"];
  523. }
  524. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  525. if(dataMap["price"]["delete"][p.ID]) continue;
  526. }
  527. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  528. coe = scMathUtil.roundForObj(coe,unitPirce);
  529. heightFee = scMathUtil.roundForObj(heightFee,unitPirce);
  530. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  531. let t_h = scMathUtil.roundForObj(heightFee * coe,process);
  532. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  533. sumFeightFee = scMathUtil.roundForObj(sumFeightFee+t_h,process);
  534. supplyList.push(supplyLocation);
  535. }
  536. supplyLocation = supplyList.join(',');
  537. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  538. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  539. original_price = doc['originalPrice']!==undefined?doc['originalPrice']:glj.unit_price.originalPrice;
  540. supplyLocation = doc['supplyLocation']!==undefined?doc['supplyLocation']:glj.unit_price.supplyLocation;
  541. }
  542. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation,scMathUtil.roundForObj(sumFeightFee,unitPirce)];
  543. };
  544. ProjectGLJ.prototype.m_updateUnitPrice = function (datas,isFromFeeRate) {//批量更新
  545. let me = this;
  546. let gljList = [];
  547. for(let d of datas){
  548. let g = updateUnit(d.projectGLJID,d);
  549. if(g) gljList.push(g);
  550. }
  551. if(isFromFeeRate == false)this.calcQuantity();
  552. //刷新项目工料机表显示
  553. projectGljObject.refreshDataSheet();
  554. //重新计算相关节点
  555. /* 2019-10-29 这里改成修改材料计算后先不自动计算,先在项目属性上做标记,切换到其它标签页时才做自动计算
  556. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  557. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  558. */
  559. //刷新定额工料机
  560. gljOprObj.refreshView();
  561. //socket推送更新信息
  562. projectGljObject.onUnitFileChange(isFromFeeRate?false:true);//如果是从更新费率过来的,不用在项目属性上做标记,费率那里已经自动计算所有节点了
  563. function updateUnit(id,unitPrice) {
  564. let glj = _.find(me.datas.gljList,{'id':id});
  565. if(glj && !_.isEmpty(unitPrice.doc)){
  566. for(let key in unitPrice.doc){
  567. glj.unit_price[key] = unitPrice.doc[key];
  568. }
  569. }
  570. return glj;
  571. }
  572. };
  573. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  574. this.m_updateUnitPrice([unitPrice]);
  575. };
  576. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  577. await this.updateMaterialCalcTasks(pgljID,datas,"add","price");
  578. };
  579. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  580. let updateDatas=[];
  581. try {
  582. for(let d of datas){
  583. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  584. if(_.isEmpty(unitPrice.doc)) continue;
  585. updateDatas.push(unitPrice);
  586. }
  587. if(updateDatas.length ==0 ) return;
  588. let [unitPrices,sumMap] = this.calcAllMaterial(updateDatas);
  589. sumMap = {"unitPrice":unitPrices};
  590. $.bootstrapLoading.start();
  591. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  592. this.refreshMaterialCalcCache(sumMap);
  593. materialCalcObj.showDatas();
  594. }catch (e){
  595. console.log(e)
  596. }finally {
  597. $.bootstrapLoading.end();
  598. }
  599. };
  600. ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
  601. //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表;
  602. try {
  603. let actionMap={};
  604. let calMap = {};
  605. actionMap[actionType] = dataMap;
  606. calMap[model] = actionMap;//{freight:{update:updateMap}
  607. let unitPrice = this.materialCal(pgljID,calMap);//计算当前这一条材料
  608. let [unitPrices,sumMap] = this.calcAllMaterial([unitPrice]);//计算完一条材料后,还要计算因为这条材料而受影响的其它所有材料
  609. if(actionType == "update") {//更新情况
  610. if (sumMap[model] && sumMap[model][actionType]) {//这一步,合并需要提交后台修改的数据
  611. let tt = sumMap[model][actionType];
  612. for(let key in dataMap) {
  613. tt[key] = dataMap[key];
  614. }
  615. } else {
  616. sumMap[model] = actionMap;
  617. }
  618. }else {
  619. sumMap[model] = actionMap;
  620. }
  621. sumMap["unitPrice"] = unitPrices;
  622. $.bootstrapLoading.start();
  623. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  624. this.refreshMaterialCalcCache(sumMap);
  625. materialCalcObj.showDatas();
  626. }catch (e){
  627. console.log(e)
  628. }finally {
  629. $.bootstrapLoading.end();
  630. }
  631. };
  632. ProjectGLJ.prototype.updateUserFreight =async function (data) {
  633. try {
  634. $.bootstrapLoading.start();
  635. let result = await ajaxPost('/glj/updateUserFreight',data);
  636. if(data.action == "add"){
  637. for(let f of data.freights){
  638. materialCalcObj.userFreightList.push(f);
  639. }
  640. }
  641. if(data.action == "update"){
  642. for(let u of materialCalcObj.userFreightList){
  643. if(u.ID == data.ID){
  644. gljUtil.updateProperty(u,data.doc);
  645. }
  646. }
  647. }
  648. materialCalcObj.showFreightDatas();
  649. }catch (e){
  650. console.log(e)
  651. }finally {
  652. $.bootstrapLoading.end();
  653. }
  654. };
  655. ProjectGLJ.prototype.getUserFreights = async function () {//初始化车船税选择
  656. try {
  657. let result = await ajaxGet("/glj/getUserFreights");
  658. return result;
  659. }catch (e){
  660. console.log(e)
  661. }
  662. };
  663. ProjectGLJ.prototype.refreshEctrovalenceCache = function (updateMap) {
  664. let elec = updateMap["electrovalence"];
  665. if(elec){
  666. let actionType = elec.actionType;
  667. if(actionType == "add"){
  668. projectObj.project.projectGLJ.datas.com_electrovalence = elec.doc;
  669. }else if(actionType == "update"){
  670. projectObj.project.projectGLJ.datas.com_electrovalence.gljList = elec.doc.gljList;
  671. }
  672. }
  673. if(updateMap["unitPrice"]) {
  674. if(Array.isArray(updateMap["unitPrice"])){
  675. this.m_updateUnitPrice(updateMap["unitPrice"]);
  676. }else {
  677. this.m_updateUnitPrice([updateMap["unitPrice"]]);
  678. }
  679. }
  680. };
  681. ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap,isFromFeeRate = false){//从费率计算过来的时候,费率那里已经做了自动计算所有节点了
  682. if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
  683. if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
  684. if(updateMap["unitPrice"]) {
  685. if(Array.isArray(updateMap["unitPrice"])){
  686. this.m_updateUnitPrice(updateMap["unitPrice"],isFromFeeRate);
  687. }else {
  688. this.m_updateUnitPrice([updateMap["unitPrice"]],isFromFeeRate);
  689. }
  690. }
  691. function updateList(list,updateMap) {
  692. if(updateMap["update"]){
  693. let map = updateMap["update"];
  694. for(let o of list){
  695. if(map[o.ID]){
  696. gljUtil.updateProperty(o,map[o.ID]);
  697. }
  698. }
  699. }
  700. if(updateMap["add"]){
  701. for(let a of updateMap["add"]){
  702. list.push(a);
  703. }
  704. }
  705. if(updateMap["delete"]){
  706. for(let ID in updateMap["delete"]){
  707. _.remove(list,{'ID':ID});
  708. }
  709. }
  710. }
  711. };
  712. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  713. let updateMap = {};
  714. for(let d of datas){
  715. updateMap[d.ID] = d.doc;
  716. }
  717. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","price");
  718. };
  719. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  720. await this.updateMaterialCalcTasks(pgljID,datas,"add","freight");
  721. };
  722. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  723. let updateMap = {};
  724. for(let d of datas){
  725. updateMap[d.ID] = d.doc;
  726. }
  727. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
  728. };
  729. ProjectGLJ.prototype.addMaterialRation = async function (code,type,parentID,connect_key){
  730. let libIDs = rationLibObj.getStdRationLibIDs();
  731. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  732. let selectedLib = sessionStorage.getItem("stdRationLib");
  733. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  734. let datas = {userID: userID,defaultLibID:defaultLibID, rationRepIds: libIDs, code: code,type:type,parentID:parentID,quantityDecimal:getDecimal("ration.quantity"),connect_key:connect_key,projectID:projectObj.project.ID()};
  735. datas.actionType="add";
  736. await this.updateMaterialRation(datas);
  737. };
  738. ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate) {
  739. $.bootstrapLoading.start();
  740. try {
  741. await ajaxPost("/glj/changeAssistProductionFeeRate",{unitFileID:projectObj.project.property.unitPriceFile.id,assistProductionFeeRate:newFeeRate});
  742. this.datas.constData.assistProductionFeeRate = newFeeRate;
  743. //todo 调用材料计算方法,所有材料重算一遍
  744. let [unitPrices,sumMap] = this.calcAllMaterial([]);
  745. sumMap["unitPrice"] = unitPrices;
  746. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  747. this.refreshMaterialCalcCache(sumMap);
  748. materialCalcObj.showDatas();
  749. }catch (err){
  750. console.log(err);
  751. }finally {
  752. $.bootstrapLoading.end();
  753. }
  754. };
  755. ProjectGLJ.prototype.calcAllWhenFeeRateChange = async function(){//当高原相关费率改变时,重新计算所有材料
  756. try {
  757. let [unitPrices,sumMap] = this.calcAllMaterial([],true);
  758. if(unitPrices.length > 0){
  759. sumMap["unitPrice"] = unitPrices;
  760. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  761. this.refreshMaterialCalcCache(sumMap,true);
  762. materialCalcObj.showDatas();
  763. }
  764. }catch (err){
  765. console.log(err);
  766. }
  767. }
  768. ProjectGLJ.prototype.loadFreightAndOriginalData = function(originalList,freightList){
  769. if(freightList) this.datas.freightList = freightList;
  770. if(originalList) this.datas.originalList = originalList;
  771. };
  772. ProjectGLJ.prototype.updateMaterialRation = async function (datas){
  773. try {
  774. let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
  775. $.bootstrapLoading.start();
  776. let result = await ajaxPost('/ration/updateMaterialRation',datas);
  777. if(datas.actionType=="add" && result.projectGLJList){
  778. this.loadNewProjectGLJToCaches(result.projectGLJList,true);
  779. this.loadFreightAndOriginalData(result.originalList,result.freightList); //这一步已经更新了运费和原价数据
  780. }
  781. if(datas.actionType == "delete"){
  782. let parent = _.find(lists,{ID:datas.parentID}) ;
  783. if(parent){
  784. _.remove(parent.rations,{ID:datas.rationID});
  785. _.remove(parent.ration_gljs,{rationID:datas.rationID});
  786. }
  787. }
  788. if(datas.actionType == "update"){
  789. let parent = _.find(lists,{ID:datas.parentID}) ;
  790. let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
  791. if(ration){
  792. if(datas.field == "code" && result.projectGLJList){
  793. this.loadNewProjectGLJToCaches(result.projectGLJList,true);
  794. this.loadFreightAndOriginalData(result.originalList,result.freightList);
  795. }else {
  796. ration[datas.field] = datas.value;
  797. if(datas.ext){
  798. for(let key in datas.ext){
  799. ration[key] = datas.ext[key];
  800. }
  801. }
  802. }
  803. if(datas.ration_gljs){//更新定额工料机数量
  804. let gljMap = _.indexBy(parent.ration_gljs,"ID");
  805. for(let g of datas.ration_gljs){
  806. if(gljMap[g.ID]) gljMap[g.ID].quantity = g.quantity;
  807. }
  808. }
  809. }
  810. }
  811. }catch (e){
  812. console.log(e)
  813. }finally {
  814. //materialCalcObj.showDatas();
  815. this.calcMaterialRation(datas.parentID,datas.type);
  816. $.bootstrapLoading.end();
  817. }
  818. };
  819. ProjectGLJ.prototype.getHighlandFee = function (feeType) {
  820. let rates = projectObj.project.FeeRate.getActivateFeeRate().rates;
  821. let matchType = false;
  822. let rate = 0;
  823. //获取高原取费类别,是先按feeType取顶层的费率,然后取子项中的“高原地区施工增加费”
  824. if(!feeType||feeType=="") return 0;//空时为0
  825. let hightlandRate = null;
  826. let topParentID = null;
  827. for(let r of rates){//费率是按顺序排的,所以先取到顶层,之后的就是目标了。
  828. if(matchType && r.ParentID == topParentID) break; //如果feeType已经匹配过了,又经过了下一个顶层节点,那说明该feeType下没有高原费率
  829. if(r.name == feeType){
  830. matchType = true;
  831. topParentID = r.ParentID;
  832. }
  833. if(matchType && r.name == "高原地区施工增加费"){
  834. //顶层先匹配上了,第一个就是要找的费率
  835. hightlandRate = r;
  836. break;
  837. }
  838. }
  839. if(hightlandRate){
  840. rate = scMathUtil.roundForObj(hightlandRate.rate,getDecimal("feeRate"));
  841. }
  842. return rate*0.01
  843. };
  844. ProjectGLJ.prototype.calcEachFreightOrPrice = function (temp,type,priceMap) {//
  845. if(temp){
  846. if(type == "freight" && temp.conveyance !="自办运输") return null;
  847. let sum =0;
  848. let heightFee = 0;
  849. let gljMap = {};
  850. let expList = [];
  851. let decimal = type == "freight"?getDecimal("glj.unitPrice"):getDecimal("glj.unitPriceHasMix");
  852. //因为材料计算的数据是保存在单价文件里的,有可能存在共享的情况,这样的话就不能用单价文件里的项目工料机ID来匹配,要用5大项匹配
  853. let pgljMap = {};
  854. for(let pg of this.datas.gljList){
  855. pgljMap[gljUtil.getIndex(pg)] = pg
  856. }
  857. if(temp.ration_gljs){
  858. for(let g of temp.ration_gljs){
  859. gljMap[g.rationID]?gljMap[g.rationID].push(g):gljMap[g.rationID]=[g];
  860. }
  861. }
  862. if(temp.rations) {
  863. for(let r of temp.rations){
  864. let [tsum,thei,exp] = calcRation(r,gljMap[r.ID],pgljMap,priceMap);
  865. heightFee = scMathUtil.roundForObj(heightFee+thei,6);
  866. sum = scMathUtil.roundForObj(sum + tsum,6);
  867. expList.push(exp);
  868. }
  869. }
  870. sum = scMathUtil.roundForObj(sum,decimal)+"";
  871. if(type == "freight"){
  872. let exp = `((${expList.join("+")})+${temp.otherFee})x${temp.weightCoe}`
  873. return {ID:temp.ID,doc:{unitFreight:sum,heightFee:heightFee,exp:exp}};
  874. }
  875. if(type == "price" && temp.supplyPrice !=sum) return {ID:temp.ID,doc:{supplyPrice:sum,heightFee:heightFee}}
  876. }
  877. return null;
  878. function calcRation(ration,gljs,pMap,priceMap){
  879. let result = 0;
  880. let heightFee = 0;
  881. let exp = "";
  882. if(gljs){
  883. let processDecimal = getDecimal("process");
  884. let hightFeeRate = projectObj.project.projectGLJ.getHighlandFee(ration.feeType);//高原取费类别费率
  885. let assFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")) * 0.01;//辅助生产间接费费率
  886. let laberSum = 0;
  887. let machineSum = 0;
  888. let assList=[];
  889. let expList = [];
  890. let rationQuantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
  891. for(let g of gljs){
  892. gljOprObj.setGLJPrice(g,pMap[gljUtil.getIndex(g)]);
  893. if(priceMap && priceMap[g.projectGLJID]) g.marketPrice = scMathUtil.roundForObj(priceMap[g.projectGLJID]);
  894. let quantity = scMathUtil.roundForObj(g.quantity,getDecimal("glj.quantity"));
  895. let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity,processDecimal);//市场价
  896. let r_price = gljUtil.getAssUsedPrice(g);//浙江定额时特殊处理,这里取市场价
  897. let rt = scMathUtil.roundForObj(quantity * r_price * rationQuantity,processDecimal);//定额价
  898. let calString = `${quantity}x${r_price}x${rationQuantity}`;
  899. if(g.type == gljUtil.gljType.LABOUR){
  900. laberSum = scMathUtil.roundForObj(laberSum+rt,processDecimal);
  901. assList.push(`${calString}x${assFeeRate*100}%`)
  902. }
  903. if(gljUtil.getMainType(g.type) == 3) machineSum = scMathUtil.roundForObj(machineSum+rt,processDecimal);
  904. expList.push(`${quantity}x${g.marketPrice}x${rationQuantity}`);
  905. result = scMathUtil.roundForObj(result + t,processDecimal);
  906. }
  907. let as = scMathUtil.roundForObj(laberSum * assFeeRate,processDecimal);//人工消耗量*定额价*定额工程量*辅助生产间接费费率
  908. let tt = scMathUtil.roundForObj(laberSum + machineSum,processDecimal);//人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量
  909. let hs = scMathUtil.roundForObj(tt*hightFeeRate,processDecimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
  910. exp = expList.join("+");
  911. if(hightFeeRate!=0) exp += `+${tt}x${hightFeeRate*100}%`;
  912. if(assFeeRate!=0) exp += '+'+assList.join("+");
  913. result = scMathUtil.roundForObj(as + result,processDecimal);
  914. result = scMathUtil.roundForObj(hs + result,processDecimal);
  915. heightFee = hs;
  916. }
  917. return [result,heightFee,exp];
  918. }
  919. };
  920. ProjectGLJ.prototype.calcMaterialAssQuantity = function (parent,ration,newAssList) {
  921. let updateList = [];
  922. let assList = calcAssList(newAssList);
  923. for(let glj of parent.ration_gljs){
  924. if(glj.rationID == ration.ID){
  925. updateList.push(calcAssGljQuantity(glj,assList));
  926. }
  927. }
  928. return updateList;
  929. function calcAssGljQuantity(g,assList) {
  930. g.quantity = scMathUtil.roundForObj(g.rationItemQuantity,getDecimal("glj.quantity"));
  931. for(let a of assList){
  932. let ass = a.ass;
  933. let matchGlj = null;
  934. for(let aglj of ass.rationGljList){
  935. if(aglj.gljId == g.GLJID){
  936. matchGlj = aglj;
  937. break;
  938. }
  939. }
  940. if(matchGlj){
  941. let calQuantity =scMathUtil.roundForObj(matchGlj.consumeAmt*a.times,6);
  942. g.quantity = scMathUtil.roundForObj(calQuantity + g.quantity,getDecimal("glj.quantity"))+"";
  943. }
  944. }
  945. return {ID:g.ID,quantity:g.quantity}
  946. }
  947. function calcAssList(rationAssList){
  948. let calAss = [];
  949. for(let ass of rationAssList){
  950. let times = calculateTimes(ass);
  951. if(times!=0){
  952. calAss.push({ass:ass.assRation,times:times});
  953. }
  954. }
  955. return calAss;
  956. }
  957. function calculateTimes(ass){
  958. if(ass.name.indexOf("运距") == -1) return 0;//只计算运距;
  959. let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
  960. let r = false;
  961. if(times<0){
  962. r=true;
  963. times=times*-1;
  964. }
  965. if(ass.carryBit=='四舍五入'){
  966. times = _.round(times,ass.decimal);
  967. }else if (ass.carryBit=='进一'){
  968. times =_.ceil(times,ass.decimal);
  969. }else if(ass.carryBit == '舍一'){
  970. times = _.floor(times,ass.decimal);
  971. }
  972. if(r){
  973. times=times*-1;
  974. }
  975. return scMathUtil.roundTo(times,-6);
  976. }
  977. };
  978. ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的运费或者原价
  979. let lists = type == "freight"?this.datas.freightList:this.datas.originalList;
  980. let temp = _.find(lists,{ID:ID});
  981. if(temp){
  982. let task = this.calcEachFreightOrPrice(temp,type);
  983. let material = materialCalcObj.getMaterialSelected();
  984. if(task && material){
  985. if(type == "freight") projectObj.project.projectGLJ.updateFreightCalc([task],material.id);
  986. if(type == "price") projectObj.project.projectGLJ.updatePriceCalc([task],material.id);
  987. }else {
  988. materialCalcObj.showDatas();
  989. }
  990. }
  991. };
  992. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  993. let map = {};
  994. map[ID] = true;
  995. await this.updateMaterialCalcTasks(pgljID,map,"delete","price");
  996. };
  997. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  998. let map = {};
  999. map[ID] = true;
  1000. await this.updateMaterialCalcTasks(pgljID,map,"delete","freight");
  1001. };
  1002. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  1003. let me = this;
  1004. let projectGljs = this.datas.gljList;
  1005. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  1006. let glj = _.find(projectGljs, {'id': pgljID});
  1007. if (glj) {
  1008. if(glj.unit_price[updateField] == newval){
  1009. return;
  1010. }
  1011. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  1012. 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};
  1013. if(updateField == 'market_price' && (this.datas.mixRatioConnectData[gljUtil.getIndex(glj)] || glj.name == "电网电")){//计算是否有受影响的综合电价
  1014. let uobj = {};
  1015. uobj[glj.id] = {marketPrice:newval};
  1016. let ext =electrovalenceObj.clacNewElecPrice(uobj);
  1017. if(ext) data.ext = ext;
  1018. }
  1019. let callback = function (result) {
  1020. if (updateField == 'base_price') {
  1021. glj.unit_price.base_price = newval;
  1022. me.setAdjustPrice(glj);
  1023. } else {
  1024. glj.unit_price.market_price = newval;
  1025. }
  1026. let elec_glj = null;
  1027. if(data.ext){
  1028. elec_glj = _.find(projectGljs, {'id': data.ext.projectGLJID});
  1029. if(elec_glj) elec_glj.unit_price.market_price = data.ext.doc.market_price;
  1030. }
  1031. //更新回传的父节点项目工料机价格
  1032. let gljs = me.getProjectGLJs(result);
  1033. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  1034. projectGljObject.refreshDataSheet();//更新工料机汇总缓存和显示
  1035. //projectObj.project.projectGLJ.loadCacheData();
  1036. gljOprObj.showRationGLJSheetData();
  1037. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  1038. gljs.push(glj);
  1039. if(elec_glj) gljs.push(elec_glj);
  1040. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1041. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1042. projectGljObject.onUnitFileChange(result);
  1043. if(cb){
  1044. cb(gljs);
  1045. }
  1046. $.bootstrapLoading.end();
  1047. }
  1048. $.bootstrapLoading.start();
  1049. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  1050. $.bootstrapLoading.end();
  1051. });
  1052. } else {
  1053. gljOprObj.showRationGLJSheetData();
  1054. }
  1055. };
  1056. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  1057. let me = this;
  1058. //更新是否暂估和供货方式时,要做特殊处理
  1059. $.bootstrapLoading.start();
  1060. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  1061. $.bootstrapLoading.end();
  1062. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  1063. for(let idKey in updateMap){
  1064. let gljID = parseInt(idKey);
  1065. let glj = me.getByID(gljID);
  1066. let doc = updateMap[idKey];
  1067. for(let property in doc){
  1068. glj[property] = doc[property];
  1069. }
  1070. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  1071. supplyChangeIDs.push(gljID);
  1072. }
  1073. if(doc.hasOwnProperty("is_evaluate")){
  1074. evaluate_gljs.push(glj);
  1075. }
  1076. }
  1077. if(supplyChangeIDs.length>0){
  1078. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  1079. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  1080. }
  1081. if(evaluate_gljs.length > 0){
  1082. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  1083. rationNodes = rationNodes.concat(impactRationNodes);
  1084. }
  1085. if(rationNodes.length > 0){
  1086. rationNodes = _.uniq(rationNodes,'data');
  1087. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  1088. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1089. });
  1090. }
  1091. if(callback){
  1092. callback();
  1093. }
  1094. })
  1095. };
  1096. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  1097. let me = this;
  1098. let projectGljs = me.datas.gljList;
  1099. let updateData = [];
  1100. let newValueMap = {};
  1101. let gljs=[];
  1102. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  1103. if(changeInfo.length<=0){
  1104. callback?callback():'';
  1105. return
  1106. }
  1107. for(let ci of changeInfo){
  1108. let dataCode = setting.header[ci.col].dataCode;
  1109. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  1110. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  1111. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  1112. let glj = _.find(projectGljs, {'id': recode.id});
  1113. let newValue = ci.value;
  1114. if(glj&&glj.unit_price[editField]!=newValue){
  1115. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  1116. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  1117. newValueMap[glj.id]={field:editField,value:newValue};
  1118. gljs.push(glj);
  1119. }
  1120. }
  1121. }
  1122. if(updateData.length > 0){
  1123. $.bootstrapLoading.start();
  1124. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  1125. let parentData = [];
  1126. //更新缓存
  1127. for(let g of gljs){
  1128. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  1129. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  1130. }
  1131. //更新父工料机价格
  1132. for(let r of result){
  1133. let pdata = r.updateOne.filter;
  1134. let set = r.updateOne.update.$set;
  1135. for(let skey in set){
  1136. pdata[skey] = set[skey];
  1137. }
  1138. parentData.push(pdata);
  1139. }
  1140. let pgljs = me.getProjectGLJs(parentData);
  1141. gljs = gljs.concat(pgljs);
  1142. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1143. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1144. gljOprObj.showRationGLJSheetData();
  1145. projectGljObject.onUnitFileChange(gljs);
  1146. if(callback){
  1147. callback(gljs);
  1148. }
  1149. $.bootstrapLoading.end();
  1150. }, function (err) {
  1151. $.bootstrapLoading.end();
  1152. });
  1153. }
  1154. };
  1155. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  1156. let me = this;
  1157. $.bootstrapLoading.start();
  1158. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  1159. let unitPriceMap = {}, mu=null, parentID = null;
  1160. for(let u of updateData){
  1161. if(u.type == 'mix_ratio'){
  1162. mu = u;
  1163. }else if(u.type == 'unitPrice'){
  1164. unitPriceMap[u.projectGLJID] = u.doc;
  1165. if(u.isParent) parentID = u.projectGLJID;
  1166. }
  1167. }
  1168. if(!_.isEmpty(unitPriceMap)){
  1169. for(let g of me.datas.gljList) {
  1170. if(unitPriceMap[g.id]){
  1171. gljUtil.setProperty(g.unit_price,unitPriceMap[g.id]);
  1172. }
  1173. if(parentID == g.id) updateMixRatio(g,mu,me);
  1174. }
  1175. }
  1176. me.calcQuantity();
  1177. if(callback){
  1178. callback();
  1179. }
  1180. $.bootstrapLoading.end();
  1181. },function () {
  1182. $.bootstrapLoading.end();
  1183. })
  1184. function updateMixRatio(parent,u,me) {
  1185. let tem = updateMap[u.query.id];
  1186. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  1187. let subData = _.find(parent.ratio_data,{"id":u.query.id});
  1188. if(subData){
  1189. subData.consumption = u.doc.consumption;
  1190. }
  1191. let m_list = me.datas.mixRatioMap[gljUtil.getIndex(parent)];
  1192. let m_ratioData = _.find(m_list,{"id":u.query.id});
  1193. if(m_ratioData){
  1194. m_ratioData.consumption = u.doc.consumption;
  1195. }
  1196. }
  1197. };
  1198. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  1199. let me = this;
  1200. $.bootstrapLoading.start();
  1201. CommonAjax.specialPost( '/glj/update',data,function (result) {
  1202. let glj = me.getByID(data.id);//更新缓存
  1203. let impactList = [];
  1204. glj[data.field] = data.value;
  1205. if(data.extend&&data.extend!=""){
  1206. let extend = JSON.parse(data.extend);
  1207. for (let key in extend) {
  1208. glj[key] = extend[key];
  1209. }
  1210. }
  1211. if(data.field == 'is_evaluate'){
  1212. impactList = me.changeIsEvaluate(data.id);
  1213. }
  1214. if(callback){
  1215. callback(impactList);
  1216. }
  1217. $.bootstrapLoading.end();
  1218. });
  1219. };
  1220. ProjectGLJ.prototype.getRatioData=function(id,callback){
  1221. this.getRatioId = id;
  1222. if(id){
  1223. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  1224. let ratios = JSON.parse(response.data);
  1225. if(callback){
  1226. callback(ratios);
  1227. }
  1228. },function () {//取不到组成物的情况
  1229. callback([]);
  1230. })
  1231. }else {
  1232. if(callback){
  1233. callback([]);
  1234. }
  1235. }
  1236. };
  1237. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  1238. $.bootstrapLoading.start();
  1239. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  1240. projectObj.project.property.unitPriceFile = response.unitFile;
  1241. projectObj.project.projectGLJ.loadData(function () {
  1242. if(callback){
  1243. callback();
  1244. }
  1245. $.bootstrapLoading.end();
  1246. });
  1247. }, function (err) {
  1248. if($.bootstrapLoading.isLoading()){
  1249. $.bootstrapLoading.end();
  1250. }
  1251. alert(err.msg);
  1252. });
  1253. };
  1254. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  1255. $.bootstrapLoading.start();
  1256. try {
  1257. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  1258. await this.synLoadData();
  1259. projectGljObject.refreshDataSheet();
  1260. gljOprObj.refreshView();
  1261. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  1262. projectGljObject.onUnitFileChange();
  1263. }catch (err){
  1264. console.log(err);
  1265. }finally {
  1266. $.bootstrapLoading.end();
  1267. }
  1268. };
  1269. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  1270. let gljList = [],allGLJ = gljOprObj.AllRecode;
  1271. if(selections.length == 0) {
  1272. return;
  1273. }
  1274. for(let glj of allGLJ){
  1275. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  1276. if(_.includes(selections,i_key)){
  1277. let pglj = {
  1278. project_id: projectObj.project.ID(),
  1279. glj_id: glj.ID,
  1280. name: glj.name,
  1281. code: glj.code,
  1282. original_code: glj.code,
  1283. unit: glj.unit,
  1284. specs: glj.specs,
  1285. base_price: glj.basePrice,
  1286. market_price: glj.basePrice,
  1287. shortName: glj.shortName,
  1288. type: glj.gljType,
  1289. model:glj.model,
  1290. adjCoe: glj.adjCoe,
  1291. from:'std',
  1292. repositoryId:glj.repositoryId,
  1293. materialType:glj.materialType,
  1294. materialCoe:glj.materialCoe,
  1295. grossWeightCoe:glj.grossWeightCoe,
  1296. purchaseStorageRate:glj.purchaseStorageRate,
  1297. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  1298. handlingLossRate:glj.handlingLossRate
  1299. };
  1300. if (glj.hasOwnProperty("compilationId")) {
  1301. pglj.from = "cpt";
  1302. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  1303. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  1304. }
  1305. }
  1306. gljList.push(pglj);
  1307. }
  1308. }
  1309. gljList = _.sortByAll(gljList, ['type', 'code']);
  1310. if(gljList.length == 0) return;
  1311. let praentInfo = {
  1312. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  1313. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  1314. };
  1315. $.bootstrapLoading.start();
  1316. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  1317. $.bootstrapLoading.end();
  1318. if(callback){
  1319. callback(data);
  1320. }
  1321. }, function () {
  1322. $.bootstrapLoading.end();
  1323. });
  1324. }
  1325. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  1326. let property = projectObj.project.projectInfo.property;
  1327. let data = {
  1328. name:newVal,
  1329. rootProjectID:property.rootProjectID
  1330. }
  1331. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  1332. callback(data);
  1333. });
  1334. };
  1335. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  1336. $.bootstrapLoading.start();
  1337. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  1338. projectObj.project.projectGLJ.loadData(function () {
  1339. if(callback){
  1340. callback();
  1341. }
  1342. $.bootstrapLoading.end();
  1343. });
  1344. },function (response) {
  1345. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  1346. $("#save-as-tips").text(msg).show();
  1347. $.bootstrapLoading.end();
  1348. });
  1349. };
  1350. //更新是否暂估
  1351. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  1352. let projectGLJ = projectObj.project.projectGLJ;
  1353. let datas = projectGLJ.datas;
  1354. let gljList = datas.gljList;
  1355. let glj = _.find(gljList, {'id': id});
  1356. if(glj){//与批量更新调用相同的方法
  1357. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1358. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  1359. let conditions = [];
  1360. if(pratioM&&pratioM.length>0){
  1361. for(let p_key of pratioM ){
  1362. conditions.push(gljOprObj.getConditionByKey(p_key));
  1363. }
  1364. }
  1365. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  1366. gljs.push(glj);
  1367. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1368. //更新对应的工料机类型的定额
  1369. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  1370. let ration_nodes = [];
  1371. for(r of rations){
  1372. if(r){
  1373. r.isEstimate =glj.is_evaluate?1:0;
  1374. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  1375. ration_node?ration_nodes.push(ration_node):'';
  1376. }
  1377. }
  1378. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  1379. for(rg of ration_glj_nodes){
  1380. rg.data.isEstimate =glj.is_evaluate?1:0;
  1381. ration_nodes.push(rg);
  1382. }
  1383. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  1384. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  1385. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1386. return gljs;
  1387. }
  1388. };
  1389. /**
  1390. * 批量更新是否暂估
  1391. *传入项目工料机数组
  1392. */
  1393. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  1394. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  1395. for(let glj of gljs){
  1396. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1397. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  1398. let conditions = [];
  1399. if(pratioM&&pratioM.length>0){
  1400. for(let p_key of pratioM ){
  1401. conditions.push(gljOprObj.getConditionByKey(p_key));
  1402. }
  1403. }
  1404. let tem_gljs = this.getProjectGLJs(conditions,false);
  1405. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  1406. }
  1407. impactGLJs = impactGLJs.concat(gljs);
  1408. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  1409. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  1410. let neeRefreshNode = [];
  1411. //更新对应的工料机类型的定额
  1412. for(let item of projectObj.project.Ration.datas){
  1413. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  1414. let tem_g = changeMap[item.projectGLJID];
  1415. item.isEstimate =tem_g.is_evaluate?1:0;
  1416. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  1417. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  1418. }
  1419. }
  1420. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1421. for(let rg of ration_glj_nodes){
  1422. let tem_g = changeMap[rg.data.projectGLJID];
  1423. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1424. neeRefreshNode.push(rg);
  1425. }
  1426. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1427. return [impactRationNodes,impactGLJs];
  1428. };
  1429. ProjectGLJ.prototype.getByID = function (ID) {
  1430. return _.find(this.datas.gljList,{'id':ID});
  1431. };
  1432. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1433. return _.find(this.datas.gljList,function (item) {
  1434. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1435. return tem_key == conkey
  1436. })
  1437. };
  1438. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1439. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1440. let me = this;
  1441. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1442. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1443. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1444. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1445. return true;
  1446. }
  1447. })
  1448. projectObj.mainController.refreshTreeNode(nodes);
  1449. }
  1450. }
  1451. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1452. let nodes = [];
  1453. let ids = [];
  1454. if(Array.isArray(id)){
  1455. ids = id;
  1456. }else {
  1457. ids = [id];
  1458. }
  1459. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1460. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1461. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1462. })
  1463. }
  1464. return nodes;
  1465. };
  1466. //根据工料机,取得所有受影响的定额节点
  1467. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1468. let nodes = [];
  1469. let rationMap = {};
  1470. let idArray = _.map(gljs,'id');
  1471. let gljMap = _.indexBy(gljs,'id');
  1472. //先根据项目工料机ID,找到受影响定额的ID
  1473. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1474. for (let rg of ration_glj_list) {
  1475. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1476. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1477. }
  1478. }
  1479. for (let item of projectObj.project.mainTree.items) {
  1480. if (item.sourceType == ModuleNames.ration) {
  1481. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1482. let tem_g = gljMap[item.data.projectGLJID];
  1483. if(tem_g){
  1484. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1485. item.data.marketPrice = this.getMarketPrice(tem_g);
  1486. nodes.push(item);
  1487. }
  1488. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1489. nodes.push(item)
  1490. }
  1491. }
  1492. }
  1493. return nodes;
  1494. };
  1495. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1496. for (let ration_glj of gljOprObj.sheetData) {
  1497. if (ration_glj.projectGLJID == glj.id) {
  1498. ration_glj.basePrice = this.getBasePrice(glj);
  1499. ration_glj.marketPrice = this.getMarketPrice(glj);
  1500. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1501. }
  1502. }
  1503. }
  1504. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1505. }
  1506. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1507. let parentGlj = [];
  1508. //
  1509. let projectGljs = this.datas.gljList;
  1510. let indexList = gljKeyArray;
  1511. for (let d of data) {
  1512. if (d) {
  1513. let glj = _.find(projectGljs, function (item) {
  1514. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1515. });
  1516. if (glj) {
  1517. if(refreshPrice==true){
  1518. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1519. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1520. this.setAdjustPrice(glj);
  1521. this.refreshRationGLJPrice(glj);
  1522. this.refreshTreeNodePriceIfNeed(glj);
  1523. }
  1524. parentGlj.push(glj);
  1525. }
  1526. }
  1527. }
  1528. return parentGlj;
  1529. }
  1530. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1531. switch (glj.unit_price.type + '') {
  1532. // 人工: 调整基价=基价单价*调整系数
  1533. case GLJTypeConst.LABOUR:
  1534. case GLJTypeConst.MACHINE_LABOUR:
  1535. glj.adjust_price = this.getAdjustPrice(glj);
  1536. break;
  1537. // 机械类型的算法
  1538. case GLJTypeConst.MACHINE:
  1539. console.log('机械');
  1540. break;
  1541. // 材料、主材、设备
  1542. default:
  1543. glj.adjust_price = glj.unit_price.base_price;
  1544. }
  1545. }
  1546. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1547. let proGLJ = projectObj.project.projectGLJ;
  1548. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1549. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1550. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1551. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1552. };
  1553. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1554. let proGLJ = projectObj.project.projectGLJ;
  1555. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1556. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1557. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1558. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1559. };
  1560. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1561. let proGLJ = projectObj.project.projectGLJ;
  1562. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1563. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1564. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1565. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1566. };
  1567. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1568. let proGLJ = projectObj.project.projectGLJ;
  1569. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1570. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1571. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1572. let tenderCoe = 1;
  1573. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1574. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1575. }
  1576. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1577. };
  1578. ProjectGLJ.prototype.isEstimateType = function(type){
  1579. let typeString = type + "";
  1580. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1581. return type;
  1582. }
  1583. return false;
  1584. };
  1585. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1586. let gljTypeMap = this.datas.constData.gljTypeMap;
  1587. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1588. };
  1589. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1590. let project_gljs = this.datas.gljList;
  1591. let changeArray=[];
  1592. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1593. let rationDatas = projectObj.project.Ration.datas;
  1594. let billsDatas = projectObj.project.Bills.datas;
  1595. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1596. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1597. this.quantityChangeMap = {};
  1598. for(let pglj of project_gljs){
  1599. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1600. }
  1601. }else if(this.quantityChangeMap != null){
  1602. for(let pglj of project_gljs){
  1603. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1604. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1605. changeArray.push(pglj);
  1606. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1607. }
  1608. }else { //映射表没有,说明是新添加的项目工料机
  1609. changeArray.push(pglj);
  1610. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1611. }
  1612. }
  1613. }
  1614. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1615. };
  1616. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1617. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1618. let rationDatas = projectObj.project.Ration.datas;
  1619. let billsDatas = projectObj.project.Bills.datas;
  1620. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1621. };
  1622. ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
  1623. if(!datas) return;
  1624. let gljIDMap = {};
  1625. for (let d of datas){
  1626. if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
  1627. }
  1628. if(datas.length > 0 && calquantity) this.calcQuantity();
  1629. };
  1630. ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新插入的项目工料机数据增加至缓存中
  1631. if(!data) return;
  1632. let project_gljs = this.datas.gljList;
  1633. let unitPriceMap = this.datas.unitPriceMap;
  1634. let mixRatioMap = this.datas.mixRatioMap;
  1635. let mixRatioConnectData = this.datas.mixRatioConnectData;
  1636. let IDMap = !_.isEmpty(tIDMap)?tIDMap:_.indexBy(project_gljs,'id');
  1637. let tem = IDMap[data.id];
  1638. if(tem) return tem; //判断该工料机是否已经存在,是的话不用再次添加
  1639. //查看是否有组成物,有组成物的话先添加组成物信息
  1640. data.ratio_data=[];
  1641. if(data.subList && data.subList.length){
  1642. for(let s of data.subList){
  1643. let ratio = s.ratio_data;
  1644. data.ratio_data.push(ratio);
  1645. mixRatioMap[ratio.connect_key]?mixRatioMap[ratio.connect_key].push(ratio):mixRatioMap[ratio.connect_key] = [ratio];
  1646. let rIndex = gljUtil.getIndex(ratio);
  1647. mixRatioConnectData[rIndex]?mixRatioConnectData[rIndex].push(ratio.connect_key):mixRatioConnectData[rIndex] = [ratio.connect_key];
  1648. this.loadNewProjectGLJToCache(s,IDMap);
  1649. }
  1650. delete data.subList;
  1651. }
  1652. //添加unitPriceMap
  1653. let uIndex = gljUtil.getIndex(data.unit_price);
  1654. if(!unitPriceMap[uIndex]) unitPriceMap[uIndex] = data.unit_price;
  1655. this.datas.gljList.push(data);
  1656. IDMap[data.id] = data;
  1657. return data;
  1658. };