project_glj.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  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) {//当材料发生改变时重算所有计算材料的价格
  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);
  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. return [unitPriecs,sumUpdateMap];
  368. function ifNeedReCalc(obj,IDMap) {
  369. let calcf = false;
  370. if(obj.ration_gljs){
  371. for(let rg of obj.ration_gljs){
  372. if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
  373. calcf = true;
  374. break;
  375. }
  376. }
  377. }
  378. return calcf;
  379. }
  380. };
  381. ProjectGLJ.prototype.materialCal = function (id,dataMap,tglj,tfreightList,tpriceList) {
  382. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  383. let unitPirceDecimal = getDecimal("glj.unitPrice");
  384. let process = getDecimal("process");
  385. let glj = tglj?tglj: _.find(this.datas.gljList,{'id':id});
  386. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  387. if(!glj) return;
  388. let unitPrice = {projectGLJID:glj.id,id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  389. //先计算原价
  390. let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap,tpriceList);
  391. doc['originalPrice'] = originalPrice+'';
  392. doc['supplyLocation'] = supplyLocation;
  393. //再计算运费
  394. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  395. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  396. let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap,tfreightList);
  397. doc['unitFreight'] = unitFreight+'';
  398. //计算场外运输损耗
  399. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  400. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  401. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  402. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  403. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  404. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  405. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  406. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  407. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  408. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  409. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  410. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  411. //计算采购及保管费
  412. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  413. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  414. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  415. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  416. doc['purchaseStorage'] = purchaseStorage+'';
  417. //再计算预算价
  418. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  419. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  420. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  421. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  422. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  423. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  424. let o_unit = glj.unit_price;
  425. for(let key in doc){
  426. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  427. unitPrice.doc[key] = doc[key];
  428. }
  429. return unitPrice
  430. };
  431. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreightList) {
  432. let process = getDecimal("process");
  433. let unitPirce = getDecimal("glj.unitPrice");
  434. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  435. let sum = 0;
  436. let freightList = tfreightList?tfreightList:_.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  437. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  438. for(let f of freightList){
  439. 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;
  440. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  441. let t = dataMap["freight"]["update"][f.ID];
  442. if(t){
  443. if(t['unitFreight']) unitFreight = t['unitFreight'];
  444. if(t['kmDistance']) kmDistance = t['kmDistance'];
  445. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  446. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  447. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  448. if(t['otherFee']) otherFee = t['otherFee'];
  449. if(t['weightCoe']) weightCoe = t['weightCoe'];
  450. if(t['conveyance']) conveyance = t['conveyance'];
  451. if(t['calcType']) calcType = t['calcType'];
  452. if(t['materialType']) materialType = t['materialType'];
  453. }
  454. }
  455. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  456. if(dataMap["freight"]["delete"][f.ID]) continue;
  457. }
  458. //开始计算
  459. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  460. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  461. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  462. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  463. let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
  464. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  465. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  466. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  467. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  468. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  469. if(calcType == "内蒙古") t = scMathUtil.roundForObj(t/1.09,process); //内蒙古要除以税率1.09;
  470. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  471. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  472. t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  473. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  474. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  475. sum = scMathUtil.roundForObj(sum + t,process);
  476. }
  477. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  478. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  479. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  480. }
  481. return scMathUtil.roundForObj(sum,unitPirce);
  482. function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
  483. if(calcType =="内蒙古") return materialCalcObj.calNeiMengTotalFreight(kmDistance,materialType);
  484. //如果运输方式为自办运输,则直接返回单位运价即可;
  485. let price = conveyance == "自办运输" ? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  486. return price
  487. }
  488. };
  489. ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
  490. let process = getDecimal("process");
  491. let unitPirce = getDecimal("glj.unitPrice");
  492. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  493. let original_price = 0;
  494. let supplyList = [];
  495. let supplyLocation = "";
  496. let priceList = tpriceList?tpriceList:_.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  497. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  498. for(let p of priceList){
  499. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  500. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  501. let t = dataMap["price"]["update"][p.ID];
  502. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  503. if(t && t["coe"]) coe =t["coe"];
  504. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  505. }
  506. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  507. if(dataMap["price"]["delete"][p.ID]) continue;
  508. }
  509. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  510. coe = scMathUtil.roundForObj(coe,unitPirce);
  511. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  512. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  513. supplyList.push(supplyLocation);
  514. }
  515. supplyLocation = supplyList.join(',');
  516. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  517. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  518. original_price = doc['originalPrice']?doc['originalPrice']:glj.unit_price.originalPrice;
  519. supplyLocation = doc['supplyLocation']?doc['supplyLocation']:glj.unit_price.supplyLocation;
  520. }
  521. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation];
  522. };
  523. ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
  524. let me = this;
  525. let gljList = [];
  526. for(let d of datas){
  527. let g = updateUnit(d.projectGLJID,d);
  528. if(g) gljList.push(g);
  529. }
  530. this.calcQuantity();
  531. //刷新项目工料机表显示
  532. projectGljObject.refreshDataSheet();
  533. //重新计算相关节点
  534. /* 2019-10-29 这里改成修改材料计算后先不自动计算,先在项目属性上做标记,切换到其它标签页时才做自动计算
  535. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  536. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  537. */
  538. //刷新定额工料机
  539. gljOprObj.refreshView();
  540. //项目单价文件修改标记
  541. projectObj.project.projectInfo.changeMark = 'unitFile';
  542. //socket推送更新信息
  543. projectGljObject.onUnitFileChange(true);
  544. function updateUnit(id,unitPrice) {
  545. let glj = _.find(me.datas.gljList,{'id':id});
  546. if(glj && !_.isEmpty(unitPrice.doc)){
  547. for(let key in unitPrice.doc){
  548. glj.unit_price[key] = unitPrice.doc[key];
  549. }
  550. }
  551. return glj;
  552. }
  553. };
  554. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  555. this.m_updateUnitPrice([unitPrice]);
  556. };
  557. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  558. await this.updateMaterialCalcTasks(pgljID,datas,"add","price");
  559. };
  560. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  561. let updateDatas=[];
  562. try {
  563. for(let d of datas){
  564. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  565. if(_.isEmpty(unitPrice.doc)) continue;
  566. updateDatas.push(unitPrice);
  567. }
  568. if(updateDatas.length ==0 ) return;
  569. let [unitPrices,sumMap] = this.calcAllMaterial(updateDatas);
  570. sumMap = {"unitPrice":unitPrices};
  571. $.bootstrapLoading.start();
  572. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  573. this.refreshMaterialCalcCache(sumMap);
  574. materialCalcObj.showDatas();
  575. }catch (e){
  576. console.log(e)
  577. }finally {
  578. $.bootstrapLoading.end();
  579. }
  580. };
  581. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  582. let updateMap = {};
  583. for(let d of datas){
  584. updateMap[d.ID] = d.doc;
  585. }
  586. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
  587. };
  588. ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
  589. //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表;
  590. try {
  591. let actionMap={};
  592. let calMap = {};
  593. actionMap[actionType] = dataMap;
  594. calMap[model] = actionMap;//{freight:{update:updateMap}
  595. let unitPrice = this.materialCal(pgljID,calMap);//计算当前这一条材料
  596. let [unitPrices,sumMap] = this.calcAllMaterial([unitPrice]);//计算完一条材料后,还要计算因为这条材料而受影响的其它所有材料
  597. if(actionType == "update") {//更新情况
  598. if (sumMap[model] && sumMap[model][actionType]) {//这一步,合并需要提交后台修改的数据
  599. let tt = sumMap[model][actionType];
  600. for (let d of datas) {
  601. tt[d.ID] = d.doc;
  602. }
  603. } else {
  604. sumMap[model] = actionMap;
  605. }
  606. }else {
  607. sumMap[model] = actionMap;
  608. }
  609. sumMap["unitPrice"] = unitPrices;
  610. $.bootstrapLoading.start();
  611. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  612. this.refreshMaterialCalcCache(sumMap);
  613. materialCalcObj.showDatas();
  614. }catch (e){
  615. console.log(e)
  616. }finally {
  617. $.bootstrapLoading.end();
  618. }
  619. };
  620. ProjectGLJ.prototype.updateUserFreight =async function (data) {
  621. try {
  622. $.bootstrapLoading.start();
  623. let result = await ajaxPost('/glj/updateUserFreight',data);
  624. if(data.action == "add"){
  625. for(let f of data.freights){
  626. materialCalcObj.userFreightList.push(f);
  627. }
  628. }
  629. if(data.action == "update"){
  630. for(let u of materialCalcObj.userFreightList){
  631. if(u.ID == data.ID){
  632. gljUtil.updateProperty(u,data.doc);
  633. }
  634. }
  635. }
  636. materialCalcObj.showFreightDatas();
  637. }catch (e){
  638. console.log(e)
  639. }finally {
  640. $.bootstrapLoading.end();
  641. }
  642. };
  643. ProjectGLJ.prototype.getUserFreights = async function () {//初始化车船税选择
  644. try {
  645. let result = await ajaxGet("/glj/getUserFreights");
  646. console.log(result);
  647. return result;
  648. }catch (e){
  649. console.log(e)
  650. }
  651. };
  652. ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap){
  653. if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
  654. if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
  655. if(updateMap["unitPrice"]) {
  656. if(Array.isArray(updateMap["unitPrice"])){
  657. this.m_updateUnitPrice(updateMap["unitPrice"]);
  658. }else {
  659. this.m_updateUnitPrice([updateMap["unitPrice"]]);
  660. }
  661. }
  662. function updateList(list,updateMap) {
  663. if(updateMap["update"]){
  664. let map = updateMap["update"];
  665. for(let o of list){
  666. if(map[o.ID]){
  667. gljUtil.updateProperty(o,map[o.ID]);
  668. }
  669. }
  670. }
  671. if(updateMap["add"]){
  672. for(let a of updateMap["add"]){
  673. list.push(a);
  674. }
  675. }
  676. if(updateMap["delete"]){
  677. for(let ID in updateMap["delete"]){
  678. _.remove(list,{'ID':ID});
  679. }
  680. }
  681. }
  682. };
  683. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  684. let updateMap = {};
  685. for(let d of datas){
  686. updateMap[d.ID] = d.doc;
  687. }
  688. await this.updateMaterialCalcTasks(pgljID,updateMap,"update","price");
  689. };
  690. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  691. await this.updateMaterialCalcTasks(pgljID,datas,"add","freight");
  692. };
  693. ProjectGLJ.prototype.addMaterialRation = async function (code,type,parentID,connect_key){
  694. let libIDs = rationLibObj.getStdRationLibIDs();
  695. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  696. let selectedLib = sessionStorage.getItem("stdRationLib");
  697. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  698. 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()};
  699. datas.actionType="add";
  700. await this.updateMaterialRation(datas);
  701. };
  702. ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate) {
  703. $.bootstrapLoading.start();
  704. try {
  705. await ajaxPost("/glj/changeAssistProductionFeeRate",{unitFileID:projectObj.project.property.unitPriceFile.id,assistProductionFeeRate:newFeeRate});
  706. this.datas.constData.assistProductionFeeRate = newFeeRate;
  707. //todo 调用材料计算方法,所有材料重算一遍
  708. let [unitPrices,sumMap] = this.calcAllMaterial([]);
  709. sumMap["unitPrice"] = unitPrices;
  710. let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
  711. this.refreshMaterialCalcCache(sumMap);
  712. materialCalcObj.showDatas();
  713. }catch (err){
  714. console.log(err);
  715. }finally {
  716. $.bootstrapLoading.end();
  717. }
  718. };
  719. ProjectGLJ.prototype.updateMaterialRation = async function (datas){
  720. try {
  721. let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
  722. $.bootstrapLoading.start();
  723. let result = await ajaxPost('/ration/updateMaterialRation',datas);
  724. if(datas.actionType=="add" && result.projectGLJDatas) this.refreshByDatas(result.projectGLJDatas);//这一步已经更新了运费和原价数据
  725. if(datas.actionType == "delete"){
  726. let parent = _.find(lists,{ID:datas.parentID}) ;
  727. if(parent){
  728. _.remove(parent.rations,{ID:datas.rationID});
  729. _.remove(parent.ration_gljs,{rationID:datas.rationID});
  730. }
  731. }
  732. if(datas.actionType == "update"){
  733. let parent = _.find(lists,{ID:datas.parentID}) ;
  734. let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
  735. if(ration){
  736. if(datas.field == "code" && result.projectGLJDatas){
  737. this.refreshByDatas(result.projectGLJDatas);
  738. }else {
  739. ration[datas.field] = datas.value;
  740. if(datas.ext){
  741. for(let key in datas.ext){
  742. ration[key] = datas.ext[key];
  743. }
  744. }
  745. }
  746. if(datas.ration_gljs){//更新定额工料机数量
  747. let gljMap = _.indexBy(parent.ration_gljs,"ID");
  748. for(let g of datas.ration_gljs){
  749. if(gljMap[g.ID]) gljMap[g.ID].quantity = g.quantity;
  750. }
  751. }
  752. }
  753. }
  754. }catch (e){
  755. console.log(e)
  756. }finally {
  757. //materialCalcObj.showDatas();
  758. this.calcMaterialRation(datas.parentID,datas.type);
  759. $.bootstrapLoading.end();
  760. }
  761. };
  762. ProjectGLJ.prototype.getHighlandFee = function (feeType) {
  763. let rates = projectObj.project.FeeRate.getActivateFeeRate().rates;
  764. let matchType = false;
  765. let rate = 0;
  766. //获取高原取费类别,是先按feeType取顶层的费率,然后取子项中的“高原地区施工增加费”
  767. if(!feeType||feeType=="") return 0;//空时为0
  768. let hightlandRate = null;
  769. let topParentID = null;
  770. for(let r of rates){//费率是按顺序排的,所以先取到顶层,之后的就是目标了。
  771. if(matchType && r.ParentID == topParentID) break; //如果feeType已经匹配过了,又经过了下一个顶层节点,那说明该feeType下没有高原费率
  772. if(r.name == feeType){
  773. matchType = true;
  774. topParentID = r.ParentID;
  775. }
  776. if(matchType && r.name == "高原地区施工增加费"){
  777. //顶层先匹配上了,第一个就是要找的费率
  778. hightlandRate = r;
  779. break;
  780. }
  781. }
  782. if(hightlandRate){
  783. rate = scMathUtil.roundForObj(hightlandRate.rate,getDecimal("feeRate"));
  784. }
  785. return rate*0.01
  786. };
  787. ProjectGLJ.prototype.calcEachFreightOrPrice = function (temp,type,priceMap) {//
  788. if(temp){
  789. if(type == "freight" && temp.conveyance !="自办运输") return null;
  790. let sum =0;
  791. let gljMap = {};
  792. let pgljMap =_.indexBy(this.datas.gljList, 'id');
  793. for(let g of temp.ration_gljs){
  794. gljMap[g.rationID]?gljMap[g.rationID].push(g):gljMap[g.rationID]=[g];
  795. }
  796. for(let r of temp.rations){
  797. sum = scMathUtil.roundForObj(sum + calcRation(r,gljMap[r.ID],pgljMap,priceMap),6);
  798. }
  799. sum = scMathUtil.roundForObj(sum,getDecimal("glj.unitPrice"))+"";
  800. if(type == "freight" && temp.unitFreight!= sum) return {ID:temp.ID,doc:{unitFreight:sum}};
  801. if(type == "price" && temp.supplyPrice !=sum) return {ID:temp.ID,doc:{supplyPrice:sum}};
  802. }
  803. return null;
  804. function calcRation(ration,gljs,pMap,priceMap){
  805. let result = 0;
  806. if(gljs){
  807. //to do 计算有辅助定额的情况
  808. let processDecimal = getDecimal("process");
  809. let hightFeeRate = projectObj.project.projectGLJ.getHighlandFee(ration.feeType);//高原取费类别费率
  810. let assFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")) * 0.01;//辅助生产间接费费率
  811. let laberSum = 0;
  812. let machineSum = 0;
  813. let rationQuantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
  814. for(let g of gljs){
  815. gljOprObj.setGLJPrice(g,pMap[g.projectGLJID]);
  816. if(priceMap && priceMap[g.projectGLJID]) g.marketPrice = scMathUtil.roundForObj(priceMap[g.projectGLJID]);
  817. let quantity = scMathUtil.roundForObj(g.quantity,getDecimal("glj.quantity"));
  818. let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity,processDecimal);//市场价
  819. let rt = scMathUtil.roundForObj(quantity * g.basePrice * rationQuantity,processDecimal);//定额价
  820. if(g.type == gljUtil.gljType.LABOUR) laberSum = scMathUtil.roundForObj(laberSum+rt,processDecimal);
  821. if(gljUtil.getMainType(g.type) == 3) machineSum = scMathUtil.roundForObj(machineSum+rt,processDecimal);
  822. result = scMathUtil.roundForObj(result + t,processDecimal);
  823. }
  824. let as = scMathUtil.roundForObj(laberSum * assFeeRate,processDecimal);//人工消耗量*定额价*定额工程量*辅助生产间接费费率
  825. let tt = scMathUtil.roundForObj(laberSum + machineSum,processDecimal);//人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量
  826. let hs = scMathUtil.roundForObj(tt*hightFeeRate,processDecimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
  827. result = scMathUtil.roundForObj(as + result,processDecimal);
  828. result = scMathUtil.roundForObj(hs + result,processDecimal);
  829. }
  830. return result;
  831. }
  832. };
  833. ProjectGLJ.prototype.calcMaterialAssQuantity = function (parent,ration,newAssList) {
  834. let updateList = [];
  835. let assList = calcAssList(newAssList);
  836. for(let glj of parent.ration_gljs){
  837. if(glj.rationID == ration.ID){
  838. updateList.push(calcAssGljQuantity(glj,assList));
  839. }
  840. }
  841. return updateList;
  842. function calcAssGljQuantity(g,assList) {
  843. g.quantity = scMathUtil.roundForObj(g.rationItemQuantity,getDecimal("glj.quantity"));
  844. for(let a of assList){
  845. let ass = a.ass;
  846. let matchGlj = null;
  847. for(let aglj of ass.rationGljList){
  848. if(aglj.gljId == g.GLJID){
  849. matchGlj = aglj;
  850. break;
  851. }
  852. }
  853. if(matchGlj){
  854. let calQuantity =scMathUtil.roundForObj(matchGlj.consumeAmt*a.times,6);
  855. g.quantity = scMathUtil.roundForObj(calQuantity + g.quantity,getDecimal("glj.quantity"))+"";
  856. }
  857. }
  858. return {ID:g.ID,quantity:g.quantity}
  859. }
  860. function calcAssList(rationAssList){
  861. let calAss = [];
  862. for(let ass of rationAssList){
  863. let times = calculateTimes(ass);
  864. if(times!=0){
  865. calAss.push({ass:ass.assRation,times:times});
  866. }
  867. }
  868. return calAss;
  869. }
  870. function calculateTimes(ass){
  871. if(ass.name.indexOf("运距") == -1) return 0;//只计算运距;
  872. let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
  873. let r = false;
  874. if(times<0){
  875. r=true;
  876. times=times*-1;
  877. }
  878. if(ass.carryBit=='四舍五入'){
  879. times = _.round(times,ass.decimal);
  880. }else if (ass.carryBit=='进一'){
  881. times =_.ceil(times,ass.decimal);
  882. }else if(ass.carryBit == '舍一'){
  883. times = _.floor(times,ass.decimal);
  884. }
  885. if(r){
  886. times=times*-1;
  887. }
  888. return scMathUtil.roundTo(times,-6);
  889. }
  890. };
  891. ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的运费或者原价
  892. let lists = type == "freight"?this.datas.freightList:this.datas.originalList;
  893. let temp = _.find(lists,{ID:ID});
  894. if(temp){
  895. let task = this.calcEachFreightOrPrice(temp,type);
  896. let material = materialCalcObj.getMaterialSelected();
  897. if(task && material){
  898. if(type == "freight") projectObj.project.projectGLJ.updateFreightCalc([task],material.id);
  899. if(type == "price") projectObj.project.projectGLJ.updatePriceCalc([task],material.id);
  900. }
  901. }
  902. };
  903. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  904. let map = {};
  905. map[ID] = true;
  906. await this.updateMaterialCalcTasks(pgljID,ID,"delete","price");
  907. };
  908. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  909. let map = {};
  910. map[ID] = true;
  911. await this.updateMaterialCalcTasks(pgljID,map,"delete","freight");
  912. };
  913. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  914. let me = this;
  915. let projectGljs = this.datas.gljList;
  916. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  917. let glj = _.find(projectGljs, {'id': pgljID});
  918. if (glj) {
  919. if(glj.unit_price[updateField] == newval){
  920. return;
  921. }
  922. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  923. 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};
  924. let callback = function (data) {
  925. if (updateField == 'base_price') {
  926. glj.unit_price.base_price = newval;
  927. me.setAdjustPrice(glj);
  928. } else {
  929. glj.unit_price.market_price = newval;
  930. }
  931. //更新回传的父节点项目工料机价格
  932. let gljs = me.getProjectGLJs(data);
  933. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  934. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  935. gljOprObj.showRationGLJSheetData();
  936. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  937. gljs.push(glj);
  938. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  939. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  940. projectGljObject.onUnitFileChange(data);
  941. if(cb){
  942. cb(gljs);
  943. }
  944. $.bootstrapLoading.end();
  945. }
  946. $.bootstrapLoading.start();
  947. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  948. $.bootstrapLoading.end();
  949. });
  950. } else {
  951. gljOprObj.showRationGLJSheetData();
  952. }
  953. };
  954. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  955. let me = this;
  956. //更新是否暂估和供货方式时,要做特殊处理
  957. $.bootstrapLoading.start();
  958. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  959. $.bootstrapLoading.end();
  960. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  961. for(let idKey in updateMap){
  962. let gljID = parseInt(idKey);
  963. let glj = me.getByID(gljID);
  964. let doc = updateMap[idKey];
  965. for(let property in doc){
  966. glj[property] = doc[property];
  967. }
  968. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  969. supplyChangeIDs.push(gljID);
  970. }
  971. if(doc.hasOwnProperty("is_evaluate")){
  972. evaluate_gljs.push(glj);
  973. }
  974. }
  975. if(supplyChangeIDs.length>0){
  976. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  977. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  978. }
  979. if(evaluate_gljs.length > 0){
  980. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  981. rationNodes = rationNodes.concat(impactRationNodes);
  982. }
  983. if(rationNodes.length > 0){
  984. rationNodes = _.uniq(rationNodes,'data');
  985. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  986. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  987. });
  988. }
  989. if(callback){
  990. callback();
  991. }
  992. })
  993. };
  994. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  995. let me = this;
  996. let projectGljs = me.datas.gljList;
  997. let updateData = [];
  998. let newValueMap = {};
  999. let gljs=[];
  1000. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  1001. if(changeInfo.length<=0){
  1002. callback?callback():'';
  1003. return
  1004. }
  1005. for(let ci of changeInfo){
  1006. let dataCode = setting.header[ci.col].dataCode;
  1007. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  1008. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  1009. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  1010. let glj = _.find(projectGljs, {'id': recode.id});
  1011. let newValue = ci.value;
  1012. if(glj&&glj.unit_price[editField]!=newValue){
  1013. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  1014. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  1015. newValueMap[glj.id]={field:editField,value:newValue};
  1016. gljs.push(glj);
  1017. }
  1018. }
  1019. }
  1020. if(updateData.length > 0){
  1021. $.bootstrapLoading.start();
  1022. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  1023. let parentData = [];
  1024. //更新缓存
  1025. for(let g of gljs){
  1026. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  1027. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  1028. }
  1029. //更新父工料机价格
  1030. for(let r of result){
  1031. let pdata = r.updateOne.filter;
  1032. let set = r.updateOne.update.$set;
  1033. for(let skey in set){
  1034. pdata[skey] = set[skey];
  1035. }
  1036. parentData.push(pdata);
  1037. }
  1038. let pgljs = me.getProjectGLJs(parentData);
  1039. gljs = gljs.concat(pgljs);
  1040. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1041. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1042. gljOprObj.showRationGLJSheetData();
  1043. projectGljObject.onUnitFileChange(gljs);
  1044. if(callback){
  1045. callback(gljs);
  1046. }
  1047. $.bootstrapLoading.end();
  1048. }, function (err) {
  1049. $.bootstrapLoading.end();
  1050. });
  1051. }
  1052. };
  1053. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  1054. let me = this;
  1055. $.bootstrapLoading.start();
  1056. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  1057. let parent = updateData[updateData.length - 1];
  1058. let parentGlj = me.getByConKey(parent.connect_key);
  1059. for(let u of updateData){
  1060. if(u.type == 'mix_ratio'){
  1061. let tem = updateMap[u.query.id];
  1062. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  1063. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  1064. if(subData){
  1065. subData.consumption = u.doc.consumption;
  1066. }
  1067. let m_list = me.datas.mixRatioMap[parent.connect_key];
  1068. let m_ratioData = _.find(m_list,{"id":u.query.id});
  1069. if(m_ratioData){
  1070. m_ratioData.consumption = u.doc.consumption;
  1071. }
  1072. }
  1073. }
  1074. parentGlj.unit_price.market_price = parent.market_price;
  1075. parentGlj.unit_price.base_price = parent.base_price;
  1076. me.calcQuantity();
  1077. if(callback){
  1078. callback();
  1079. }
  1080. $.bootstrapLoading.end();
  1081. },function () {
  1082. $.bootstrapLoading.end();
  1083. })
  1084. };
  1085. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  1086. let me = this;
  1087. $.bootstrapLoading.start();
  1088. CommonAjax.specialPost( '/glj/update',data,function (result) {
  1089. let glj = me.getByID(data.id);//更新缓存
  1090. let impactList = [];
  1091. glj[data.field] = data.value;
  1092. if(data.extend&&data.extend!=""){
  1093. let extend = JSON.parse(data.extend);
  1094. for (let key in extend) {
  1095. glj[key] = extend[key];
  1096. }
  1097. }
  1098. if(data.field == 'is_evaluate'){
  1099. impactList = me.changeIsEvaluate(data.id);
  1100. }
  1101. if(callback){
  1102. callback(impactList);
  1103. }
  1104. $.bootstrapLoading.end();
  1105. });
  1106. };
  1107. ProjectGLJ.prototype.getRatioData=function(id,callback){
  1108. this.getRatioId = id;
  1109. if(id){
  1110. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  1111. let ratios = JSON.parse(response.data);
  1112. if(callback){
  1113. callback(ratios);
  1114. }
  1115. },function () {//取不到组成物的情况
  1116. callback([]);
  1117. })
  1118. }else {
  1119. if(callback){
  1120. callback([]);
  1121. }
  1122. }
  1123. };
  1124. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  1125. $.bootstrapLoading.start();
  1126. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  1127. projectObj.project.property.unitPriceFile = response.unitFile;
  1128. projectObj.project.projectGLJ.loadData(function () {
  1129. if(callback){
  1130. callback();
  1131. }
  1132. $.bootstrapLoading.end();
  1133. });
  1134. }, function (err) {
  1135. if($.bootstrapLoading.isLoading()){
  1136. $.bootstrapLoading.end();
  1137. }
  1138. alert(err.msg);
  1139. });
  1140. };
  1141. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  1142. $.bootstrapLoading.start();
  1143. try {
  1144. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  1145. await this.synLoadData();
  1146. projectGljObject.refreshDataSheet();
  1147. gljOprObj.refreshView();
  1148. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  1149. projectGljObject.onUnitFileChange();
  1150. }catch (err){
  1151. console.log(err);
  1152. }finally {
  1153. $.bootstrapLoading.end();
  1154. }
  1155. };
  1156. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  1157. let gljList = [],allGLJ = gljOprObj.AllRecode;
  1158. if(selections.length == 0) {
  1159. return;
  1160. }
  1161. for(let glj of allGLJ){
  1162. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  1163. if(_.includes(selections,i_key)){
  1164. let pglj = {
  1165. project_id: projectObj.project.ID(),
  1166. glj_id: glj.ID,
  1167. name: glj.name,
  1168. code: glj.code,
  1169. original_code: glj.code,
  1170. unit: glj.unit,
  1171. specs: glj.specs,
  1172. base_price: glj.basePrice,
  1173. market_price: glj.basePrice,
  1174. shortName: glj.shortName,
  1175. type: glj.gljType,
  1176. model:glj.model,
  1177. adjCoe: glj.adjCoe,
  1178. from:'std',
  1179. repositoryId:glj.repositoryId,
  1180. materialType:glj.materialType,
  1181. materialCoe:glj.materialCoe,
  1182. grossWeightCoe:glj.grossWeightCoe,
  1183. purchaseStorageRate:glj.purchaseStorageRate,
  1184. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  1185. handlingLossRate:glj.handlingLossRate
  1186. };
  1187. if (glj.hasOwnProperty("compilationId")) {
  1188. pglj.from = "cpt";
  1189. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  1190. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  1191. }
  1192. }
  1193. gljList.push(pglj);
  1194. }
  1195. }
  1196. gljList = _.sortByAll(gljList, ['type', 'code']);
  1197. if(gljList.length == 0) return;
  1198. let praentInfo = {
  1199. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  1200. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  1201. };
  1202. $.bootstrapLoading.start();
  1203. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  1204. $.bootstrapLoading.end();
  1205. if(callback){
  1206. callback(data);
  1207. }
  1208. }, function () {
  1209. $.bootstrapLoading.end();
  1210. });
  1211. }
  1212. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  1213. let property = projectObj.project.projectInfo.property;
  1214. let data = {
  1215. name:newVal,
  1216. rootProjectID:property.rootProjectID
  1217. }
  1218. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  1219. callback(data);
  1220. });
  1221. };
  1222. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  1223. $.bootstrapLoading.start();
  1224. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  1225. projectObj.project.projectGLJ.loadData(function () {
  1226. if(callback){
  1227. callback();
  1228. }
  1229. $.bootstrapLoading.end();
  1230. });
  1231. },function (response) {
  1232. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  1233. $("#save-as-tips").text(msg).show();
  1234. $.bootstrapLoading.end();
  1235. });
  1236. };
  1237. //更新是否暂估
  1238. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  1239. let projectGLJ = projectObj.project.projectGLJ;
  1240. let datas = projectGLJ.datas;
  1241. let gljList = datas.gljList;
  1242. let glj = _.find(gljList, {'id': id});
  1243. if(glj){//与批量更新调用相同的方法
  1244. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1245. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  1246. let conditions = [];
  1247. if(pratioM&&pratioM.length>0){
  1248. for(let p_key of pratioM ){
  1249. conditions.push(gljOprObj.getConditionByKey(p_key));
  1250. }
  1251. }
  1252. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  1253. gljs.push(glj);
  1254. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  1255. //更新对应的工料机类型的定额
  1256. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  1257. let ration_nodes = [];
  1258. for(r of rations){
  1259. if(r){
  1260. r.isEstimate =glj.is_evaluate?1:0;
  1261. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  1262. ration_node?ration_nodes.push(ration_node):'';
  1263. }
  1264. }
  1265. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  1266. for(rg of ration_glj_nodes){
  1267. rg.data.isEstimate =glj.is_evaluate?1:0;
  1268. ration_nodes.push(rg);
  1269. }
  1270. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  1271. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  1272. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  1273. return gljs;
  1274. }
  1275. };
  1276. /**
  1277. * 批量更新是否暂估
  1278. *传入项目工料机数组
  1279. */
  1280. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  1281. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  1282. for(let glj of gljs){
  1283. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  1284. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  1285. let conditions = [];
  1286. if(pratioM&&pratioM.length>0){
  1287. for(let p_key of pratioM ){
  1288. conditions.push(gljOprObj.getConditionByKey(p_key));
  1289. }
  1290. }
  1291. let tem_gljs = this.getProjectGLJs(conditions,false);
  1292. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  1293. }
  1294. impactGLJs = impactGLJs.concat(gljs);
  1295. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  1296. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  1297. let neeRefreshNode = [];
  1298. //更新对应的工料机类型的定额
  1299. for(let item of projectObj.project.Ration.datas){
  1300. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  1301. let tem_g = changeMap[item.projectGLJID];
  1302. item.isEstimate =tem_g.is_evaluate?1:0;
  1303. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  1304. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  1305. }
  1306. }
  1307. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1308. for(let rg of ration_glj_nodes){
  1309. let tem_g = changeMap[rg.data.projectGLJID];
  1310. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1311. neeRefreshNode.push(rg);
  1312. }
  1313. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1314. return [impactRationNodes,impactGLJs];
  1315. };
  1316. ProjectGLJ.prototype.getByID = function (ID) {
  1317. return _.find(this.datas.gljList,{'id':ID});
  1318. };
  1319. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1320. return _.find(this.datas.gljList,function (item) {
  1321. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1322. return tem_key == conkey
  1323. })
  1324. };
  1325. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1326. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1327. let me = this;
  1328. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1329. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1330. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1331. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1332. return true;
  1333. }
  1334. })
  1335. projectObj.mainController.refreshTreeNode(nodes);
  1336. }
  1337. }
  1338. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1339. let nodes = [];
  1340. let ids = [];
  1341. if(Array.isArray(id)){
  1342. ids = id;
  1343. }else {
  1344. ids = [id];
  1345. }
  1346. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1347. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1348. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1349. })
  1350. }
  1351. return nodes;
  1352. };
  1353. //根据工料机,取得所有受影响的定额节点
  1354. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1355. let nodes = [];
  1356. let rationMap = {};
  1357. let idArray = _.map(gljs,'id');
  1358. let gljMap = _.indexBy(gljs,'id');
  1359. //先根据项目工料机ID,找到受影响定额的ID
  1360. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1361. for (let rg of ration_glj_list) {
  1362. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1363. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1364. }
  1365. }
  1366. for (let item of projectObj.project.mainTree.items) {
  1367. if (item.sourceType == ModuleNames.ration) {
  1368. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1369. let tem_g = gljMap[item.data.projectGLJID];
  1370. if(tem_g){
  1371. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1372. item.data.marketPrice = this.getMarketPrice(tem_g);
  1373. nodes.push(item);
  1374. }
  1375. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1376. nodes.push(item)
  1377. }
  1378. }
  1379. }
  1380. return nodes;
  1381. };
  1382. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1383. for (let ration_glj of gljOprObj.sheetData) {
  1384. if (ration_glj.projectGLJID == glj.id) {
  1385. ration_glj.basePrice = this.getBasePrice(glj);
  1386. ration_glj.marketPrice = this.getMarketPrice(glj);
  1387. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1388. }
  1389. }
  1390. }
  1391. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1392. }
  1393. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1394. let parentGlj = [];
  1395. //
  1396. let projectGljs = this.datas.gljList;
  1397. let indexList = gljKeyArray;
  1398. for (let d of data) {
  1399. if (d) {
  1400. let glj = _.find(projectGljs, function (item) {
  1401. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1402. });
  1403. if (glj) {
  1404. if(refreshPrice==true){
  1405. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1406. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1407. this.setAdjustPrice(glj);
  1408. this.refreshRationGLJPrice(glj);
  1409. this.refreshTreeNodePriceIfNeed(glj);
  1410. }
  1411. parentGlj.push(glj);
  1412. }
  1413. }
  1414. }
  1415. return parentGlj;
  1416. }
  1417. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1418. switch (glj.unit_price.type + '') {
  1419. // 人工: 调整基价=基价单价*调整系数
  1420. case GLJTypeConst.LABOUR:
  1421. case GLJTypeConst.MACHINE_LABOUR:
  1422. glj.adjust_price = this.getAdjustPrice(glj);
  1423. break;
  1424. // 机械类型的算法
  1425. case GLJTypeConst.MACHINE:
  1426. console.log('机械');
  1427. break;
  1428. // 材料、主材、设备
  1429. default:
  1430. glj.adjust_price = glj.unit_price.base_price;
  1431. }
  1432. }
  1433. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1434. let proGLJ = projectObj.project.projectGLJ;
  1435. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1436. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1437. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1438. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1439. };
  1440. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1441. let proGLJ = projectObj.project.projectGLJ;
  1442. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1443. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1444. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1445. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1446. };
  1447. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1448. let proGLJ = projectObj.project.projectGLJ;
  1449. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1450. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1451. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1452. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1453. };
  1454. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1455. let proGLJ = projectObj.project.projectGLJ;
  1456. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1457. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1458. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1459. let tenderCoe = 1;
  1460. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1461. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1462. }
  1463. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1464. };
  1465. ProjectGLJ.prototype.isEstimateType = function(type){
  1466. let typeString = type + "";
  1467. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1468. return type;
  1469. }
  1470. return false;
  1471. };
  1472. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1473. let gljTypeMap = this.datas.constData.gljTypeMap;
  1474. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1475. };
  1476. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1477. let project_gljs = this.datas.gljList;
  1478. let changeArray=[];
  1479. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1480. let rationDatas = projectObj.project.Ration.datas;
  1481. let billsDatas = projectObj.project.Bills.datas;
  1482. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1483. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1484. this.quantityChangeMap = {};
  1485. for(let pglj of project_gljs){
  1486. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1487. }
  1488. }else if(this.quantityChangeMap != null){
  1489. for(let pglj of project_gljs){
  1490. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1491. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1492. changeArray.push(pglj);
  1493. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1494. }
  1495. }else { //映射表没有,说明是新添加的项目工料机
  1496. changeArray.push(pglj);
  1497. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1498. }
  1499. }
  1500. }
  1501. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1502. };
  1503. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1504. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1505. let rationDatas = projectObj.project.Ration.datas;
  1506. let billsDatas = projectObj.project.Bills.datas;
  1507. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1508. };