project_glj.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. /**
  2. * 工料机汇总相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/14
  6. * @version
  7. */
  8. function ProjectGLJ() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. this.quantityChangeMap=null;
  12. this.getRatioId = null;
  13. }
  14. /**
  15. * 加载数据
  16. *
  17. * @param {function} callback
  18. * @return {boolean}
  19. */
  20. ProjectGLJ.prototype.loadData = function (callback = null,error=null) {
  21. let self = this;
  22. if (self.isLoading) {
  23. return false;
  24. }
  25. // 加载工料机数据
  26. $.ajax({
  27. url: '/glj/getData',
  28. type: 'post',
  29. dataType: 'json',
  30. data: {project_id: scUrlUtil.GetQueryString('project')},
  31. error: function () {
  32. // alert('数据传输错误');
  33. if(error) error();
  34. },
  35. beforeSend: function () {
  36. self.isLoading = true;
  37. },
  38. success: function (response) {
  39. self.isLoading = false;
  40. if (response.err === 1) {
  41. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取人材机数据失败!';
  42. alert(msg);
  43. if(error) error();
  44. return false;
  45. }
  46. self.datas = response.data;
  47. self.calcQuantity();
  48. // 回调函数
  49. if (callback !== null) {
  50. callback(response.data);
  51. }
  52. // 存入缓存
  53. projectObj.project.projectGLJ = self;
  54. }
  55. });
  56. };
  57. ProjectGLJ.prototype.synLoadData = function () {
  58. return new Promise(function (resolve, reject) {
  59. projectObj.project.projectGLJ.loadData(function (data) {
  60. resolve(data)
  61. },function () {
  62. reject("获取工料机数据失败")
  63. })
  64. })
  65. }
  66. ProjectGLJ.prototype.loadToCache = function (data) {
  67. this.datas = data;
  68. projectObj.project.projectGLJ = this;
  69. }
  70. /**
  71. * 获取对应工料机数据
  72. *
  73. * @param {String} code
  74. * @return {Object}
  75. */
  76. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  77. return _.find(this.datas.gljList, {'id': ID});
  78. };
  79. // CSL, 2018-02-08 甲供、甲定。
  80. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  81. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  82. // 所以这里要合并处理。
  83. let mixSupply = [];
  84. for (let s of supplyTypeArr){
  85. switch (s) {
  86. case 1:
  87. mixSupply.push('部分甲供');
  88. break;
  89. case 2:
  90. mixSupply.push('完全甲供');
  91. break;
  92. case 3:
  93. mixSupply.push('甲定乙供');
  94. break;
  95. default:
  96. mixSupply.push('自行采购');
  97. }
  98. };
  99. mixSupply = mixSupply.concat(supplyTypeArr);
  100. return _.filter(this.datas.gljList, function (glj) {
  101. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  102. });
  103. };
  104. ProjectGLJ.prototype.testGLJs = function () {
  105. let gljs = [];
  106. for (let glj of this.datas.gljList){
  107. let o = new Object();
  108. o.name = glj.name;
  109. o.supply = glj.supply;
  110. o.quantity = glj.quantity;
  111. o.supply_quantity = glj.supply_quantity;
  112. gljs.push(o);
  113. };
  114. return gljs;
  115. };
  116. /**
  117. * 修改工料机数据
  118. *
  119. * @param {Number} id
  120. * @param {Object} data
  121. * @return {boolean}
  122. */
  123. ProjectGLJ.prototype.updateData = function (id, data) {
  124. let result = false;
  125. if (this.datas === null) {
  126. return result;
  127. }
  128. let gljList = this.datas.gljList;
  129. if (gljList === undefined) {
  130. return result;
  131. }
  132. // 查找对应的index
  133. let index = -1;
  134. for (let tmp in gljList) {
  135. if (gljList[tmp].id === id) {
  136. index = tmp;
  137. break;
  138. }
  139. }
  140. if (index < 0) {
  141. return result;
  142. }
  143. // 修改数据
  144. for (let tmpIndex in data) {
  145. if (tmpIndex.indexOf('_price') >= 0) {
  146. // 修改unit_price中的对象
  147. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  148. } else {
  149. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  150. }
  151. }
  152. };
  153. /**
  154. * 加载缓存数据到spread
  155. *
  156. * @return {void}
  157. */
  158. ProjectGLJ.prototype.loadCacheData = function (resort) {
  159. // 加载工料机数据
  160. let data = this.datas === null ? null : this.datas;
  161. if (data === null) {
  162. return;
  163. }
  164. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  165. console.log("filter start");
  166. jsonData = filterProjectGLJ(jsonData);
  167. console.log("filter end");
  168. jsonData = sortProjectGLJ(jsonData);
  169. console.log("sort end");
  170. if(projectGLJSheet&&projectGLJSpread){
  171. setTimeout(spreadInit, 1);
  172. /*projectGLJSheet.setData(jsonData);
  173. projectGLJSpread.specialColumn(jsonData);*/
  174. }
  175. };
  176. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval,callback) {
  177. if (updateField == 'marketPrice') {
  178. this.updatePrice(recode, "market_price", newval,"rg",callback);
  179. }
  180. if (updateField == 'basePrice') {
  181. this.updatePrice(recode, "base_price", newval,"rg",callback);
  182. }
  183. };
  184. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  185. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  186. projectObj.project.Ration.updateContain(newval,node);
  187. }if(updateField == "quantity"){
  188. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  189. } else {
  190. this.updateGLJProperty(node, updateField, newval);
  191. }
  192. };
  193. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  194. let rationTypeGLJ = node.data;
  195. let postData = {};
  196. if (rationTypeGLJ[updateField] == newval) {
  197. projectObj.mainController.refreshTreeNode([node]);
  198. return;
  199. }
  200. let data = {
  201. glj_id: rationTypeGLJ.GLJID,
  202. project_id: rationTypeGLJ.projectID,
  203. code: rationTypeGLJ.code,
  204. original_code: rationTypeGLJ.original_code,
  205. name: rationTypeGLJ.name,
  206. shortName: rationTypeGLJ.shortName,
  207. specs: rationTypeGLJ.specs,
  208. unit: rationTypeGLJ.unit,
  209. type: rationTypeGLJ.subType,
  210. type_of_work: rationTypeGLJ.subType,
  211. base_price: rationTypeGLJ.basePrice,
  212. market_price: rationTypeGLJ.basePrice,
  213. repositoryId: rationTypeGLJ.repositoryId,
  214. adjCoe: rationTypeGLJ.adjCoe,
  215. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  216. };
  217. if (updateField == 'subType') {
  218. data.type = newval;
  219. data.type_of_work = newval;
  220. data.shortName = this.getShortNameByID(newval);
  221. } else {
  222. data[updateField] = newval;
  223. }
  224. postData.ration = {
  225. ID: rationTypeGLJ.ID,
  226. projectID: rationTypeGLJ.projectID
  227. };
  228. postData.updateData = data;
  229. $.bootstrapLoading.start();
  230. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  231. console.log(result); //更新节点信息
  232. node.updateData[updateField] = newval;
  233. node.updateData.projectGLJID = result.id;
  234. node.updateData.code = result.code;
  235. node.updateData.basePrice = result.unit_price.base_price;
  236. node.updateData.marketUnitFee = result.unit_price.market_price;
  237. node.updateData.isAdd = result.unit_price.is_add;
  238. node.updateData.isEstimate = result.is_evaluate;
  239. node.updateData.shortName = result.unit_price.short_name;
  240. //触发计算并更新节点信息
  241. node.changed = true;
  242. projectObj.project.projectGLJ.loadData(function () {
  243. projectObj.project.calcProgram.calcAndSave(node);
  244. $.bootstrapLoading.end();
  245. });//重新加载项目工料机数据
  246. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  247. }, function (err) {
  248. $.bootstrapLoading.end();
  249. });
  250. }
  251. ProjectGLJ.prototype.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  252. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  253. return getDecimal("glj.unitPriceHasMix");
  254. }else {
  255. return getDecimal('glj.unitPrice');
  256. }
  257. };
  258. ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,value,ext) {//只有添加、删除走这个方法
  259. let glj = _.find(this.datas.gljList,{'id':projectGLJ.id});
  260. if (glj) {
  261. if(glj.unit_price[updateField] == value){
  262. return;
  263. }
  264. if(updateField == 'calcMaterial'){
  265. ext=ext?ext:{};
  266. if(value == 1){//添加材料计算操作,把单位毛重/采购保管费率等数据复制一份
  267. ext['grossWeightCoe_n'] = glj.unit_price.grossWeightCoe;
  268. ext['purchaseStorageRate_n'] = glj.unit_price.purchaseStorageRate;
  269. ext['offSiteTransportLossRate_n'] = glj.unit_price.offSiteTransportLossRate;
  270. ext['handlingLossRate_n'] = glj.unit_price.handlingLossRate;
  271. }else if(value == 0){//删除操作,恢复单位毛重/采购保管费率等数据
  272. ext['supplyLocation'] = '';
  273. ext['originalPrice'] = '0';
  274. ext['unitFreight']='0';
  275. ext['totalLoadingTimes']='0';
  276. ext['offSiteTransportLoss']='0';
  277. ext['purchaseStorage']='0';
  278. ext['packageRecoverValue']='0';
  279. }
  280. }
  281. let data = {id: glj.unit_price.id,updateField:updateField ,value: value,unit_price_file_id:glj.unit_price.unit_price_file_id,ext:ext};
  282. $.bootstrapLoading.start();
  283. try {
  284. let result = await ajaxPost('/glj/updateCalcMaterial',data);
  285. glj.unit_price[updateField] = value;
  286. if(ext){
  287. for(let key in ext){
  288. glj.unit_price[key] = ext[key];
  289. }
  290. }
  291. if(updateField == 'calcMaterial' && value ==0){///标记为0即删除材料计算标记,要删除其下挂的原价计算,运费计算,定额计算,消耗量重新计算
  292. let connect_key = gljUtil.getIndex(glj);
  293. _.remove(this.datas.originalList,{'connect_key':connect_key});
  294. _.remove(this.datas.freightList,{'connect_key':connect_key});
  295. this.calcQuantity();
  296. // to do 删除定额计算
  297. }
  298. projectGljObject.refreshDataSheet();
  299. materialCalcObj.showDatas();
  300. }catch (e){
  301. console.log(e)
  302. }finally {
  303. $.bootstrapLoading.end();
  304. }
  305. }
  306. };
  307. ProjectGLJ.prototype.materialCal = function (id,dataMap) {
  308. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  309. let unitPirceDecimal = getDecimal("glj.unitPrice");
  310. let process = getDecimal("process");
  311. let glj = _.find(this.datas.gljList,{'id':id});
  312. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
  313. if(!glj) return;
  314. let unitPrice = {id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
  315. //先计算原价
  316. let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap);
  317. doc['originalPrice'] = originalPrice+'';
  318. doc['supplyLocation'] = supplyLocation;
  319. //再计算运费
  320. let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
  321. grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
  322. let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap);
  323. doc['unitFreight'] = unitFreight+'';
  324. //计算场外运输损耗
  325. let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
  326. let totalLoadingTimes = doc["totalLoadingTimes"]?doc["totalLoadingTimes"]:glj.unit_price.totalLoadingTimes;//装卸总次数
  327. let handlingLossRate_n = doc["handlingLossRate_n"]?doc["handlingLossRate_n"]:glj.unit_price.handlingLossRate_n;//每增加一次装卸损耗率%
  328. let offSiteTransportLossRate_n = doc["offSiteTransportLossRate_n"]?doc["offSiteTransportLossRate_n"]:glj.unit_price.offSiteTransportLossRate_n;//场外运输损耗率
  329. handlingLossRate_n = scMathUtil.roundForObj(handlingLossRate_n,unitPirceDecimal)/100;
  330. offSiteTransportLossRate_n = scMathUtil.roundForObj(offSiteTransportLossRate_n,unitPirceDecimal)/100;
  331. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes,unitPirceDecimal) - 1;//(装卸总次数-1)
  332. totalLoadingTimes = totalLoadingTimes < 0 ?0:totalLoadingTimes;//(装卸总次数-1) 结果小于0的时候,值设为0
  333. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes * handlingLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%
  334. totalLoadingTimes = scMathUtil.roundForObj(totalLoadingTimes + offSiteTransportLossRate_n,process);//(装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%
  335. let offSiteTransportLoss = scMathUtil.roundForObj(sum_o_f*totalLoadingTimes,unitPirceDecimal); //场外运输损耗=(原价+单位运费)*((装卸总次数-1)*每增加一次装卸损耗率%+场外运输损耗率%)。
  336. doc['offSiteTransportLoss'] = offSiteTransportLoss+'';
  337. //计算采购及保管费
  338. let purchaseStorageRate_n = doc["purchaseStorageRate_n"]?doc["purchaseStorageRate_n"]:glj.unit_price.purchaseStorageRate_n;//采购及保管费率%
  339. purchaseStorageRate_n = scMathUtil.roundForObj(purchaseStorageRate_n,unitPirceDecimal)/100;
  340. let purchaseStorage = scMathUtil.roundForObj(sum_o_f + offSiteTransportLoss,process)//(原价+单位运费+场外运输损耗)
  341. purchaseStorage = scMathUtil.roundForObj(purchaseStorage*purchaseStorageRate_n,unitPirceDecimal)//采购及保管费=(原价+单位运费+场外运输损耗)* 采购及保管费率%。
  342. doc['purchaseStorage'] = purchaseStorage+'';
  343. //再计算预算价
  344. let packageRecoverValue = doc['packageRecoverValue']?doc['packageRecoverValue']:glj.unit_price.packageRecoverValue;//包装品回收价值。
  345. packageRecoverValue = scMathUtil.roundForObj(packageRecoverValue,unitPirceDecimal);
  346. let market_price = scMathUtil.roundForObj(sum_o_f+offSiteTransportLoss,process);//原价+单位运费+场外运输损耗
  347. market_price = scMathUtil.roundForObj(market_price+purchaseStorage,process);//原价+单位运费+场外运输损耗+采购及保管费
  348. market_price = scMathUtil.roundForObj(market_price - packageRecoverValue,unitPriceHasMix)//预算价=原价+单位运费+场外运输损耗+采购及保管费-包装品回收价值。
  349. if(market_price>0) doc['market_price'] = market_price+'';//单机版预算价小于等于0的时候不更新
  350. let o_unit = glj.unit_price;
  351. for(let key in doc){
  352. if(o_unit[key] == doc[key]) continue; //忽略一样的值
  353. unitPrice.doc[key] = doc[key];
  354. }
  355. return unitPrice
  356. };
  357. ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap) {
  358. let process = getDecimal("process");
  359. let unitPirce = getDecimal("glj.unitPrice");
  360. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
  361. let sum = 0;
  362. let freightList = _.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
  363. if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
  364. for(let f of freightList){
  365. let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe;
  366. if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
  367. let t = dataMap["freight"]["update"][f.ID];
  368. if(t){
  369. if(t['unitFreight']) unitFreight = t['unitFreight'];
  370. if(t['kmDistance']) kmDistance = t['kmDistance'];
  371. if(t['freightIncreaseRate']) freightIncreaseRate = t['freightIncreaseRate'];
  372. if(t['unitLoadingFee']) unitLoadingFee = t['unitLoadingFee'];
  373. if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
  374. if(t['otherFee']) otherFee = t['otherFee'];
  375. if(t['weightCoe']) weightCoe = t['weightCoe'];
  376. }
  377. }
  378. if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
  379. if(f.ID ==dataMap["freight"]["delete"]) continue;
  380. }
  381. //开始计算
  382. freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
  383. freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
  384. unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
  385. kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
  386. let t = scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
  387. t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
  388. unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
  389. loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
  390. let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
  391. t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
  392. otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
  393. t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
  394. t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
  395. weightCoe = scMathUtil.roundForObj(weightCoe,unitPirce);
  396. t = scMathUtil.roundForObj(t*weightCoe,process);//(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  397. sum = scMathUtil.roundForObj(sum + t,process);
  398. }
  399. if(freightList.length == 0){//如果运费计算表没有数据,则读取输入的或单价文件的值
  400. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  401. sum = doc['unitFreight']?doc['unitFreight']:glj.unit_price.unitFreight;
  402. }
  403. return scMathUtil.roundForObj(sum,unitPirce);
  404. };
  405. ProjectGLJ.prototype.priceCalc = function (glj,dataMap) {
  406. let process = getDecimal("process");
  407. let unitPirce = getDecimal("glj.unitPrice");
  408. let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
  409. let original_price = 0;
  410. let supplyList = [];
  411. let supplyLocation = "";
  412. let priceList = _.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
  413. if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
  414. for(let p of priceList){
  415. let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
  416. if(dataMap["price"] && dataMap["price"]["update"]){//覆盖更新的数据
  417. let t = dataMap["price"]["update"][p.ID];
  418. if(t && t["supplyPrice"]) supplyPrice =t["supplyPrice"];
  419. if(t && t["coe"]) coe =t["coe"];
  420. if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
  421. }
  422. if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
  423. if(p.ID ==dataMap["price"]["delete"]) continue;
  424. }
  425. supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
  426. coe = scMathUtil.roundForObj(coe,unitPirce);
  427. let t_p = scMathUtil.roundForObj(supplyPrice * coe,process);
  428. original_price=scMathUtil.roundForObj(original_price+t_p,process);
  429. supplyList.push(supplyLocation);
  430. }
  431. supplyLocation = supplyList.join(',');
  432. if(priceList.length == 0){//如果原价计算表没有数据,则读取输入的或单价文件的值
  433. let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};
  434. original_price = doc['originalPrice']?doc['originalPrice']:glj.unit_price.originalPrice;
  435. supplyLocation = doc['supplyLocation']?doc['supplyLocation']:glj.unit_price.supplyLocation;
  436. }
  437. return [scMathUtil.roundForObj(original_price,unitPriceHasMix),supplyLocation];
  438. };
  439. ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
  440. let me = this;
  441. let calQ = false;
  442. let gljList = [];
  443. for(let d of datas){
  444. let g = updateUnit(d.id,d.unitPrice);
  445. if(g) gljList.push(g);
  446. }
  447. if(calQ == true) this.calcQuantity();
  448. //刷新项目工料机表显示
  449. projectGljObject.refreshDataSheet();
  450. //重新计算相关节点
  451. let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
  452. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  453. //刷新定额工料机
  454. gljOprObj.refreshView();
  455. //socket推送更新信息
  456. projectGljObject.onUnitFileChange();
  457. function updateUnit(id,unitPrice) {
  458. let glj = _.find(me.datas.gljList,{'id':id});
  459. if(glj && !_.isEmpty(unitPrice.doc)){
  460. for(let key in unitPrice.doc){
  461. if(key == "offSiteTransportLossRate_n") calQ = true;
  462. glj.unit_price[key] = unitPrice.doc[key];
  463. }
  464. }
  465. return glj;
  466. }
  467. };
  468. ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
  469. this.m_updateUnitPrice([{id:id,unitPrice:unitPrice}]);
  470. };
  471. ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
  472. try {
  473. let unitPrice = this.materialCal(pgljID,{price:{add:datas}});
  474. $.bootstrapLoading.start();
  475. let result = await ajaxPost('/glj/addOriginalCalc',{datas:datas,unitPrice:unitPrice});
  476. this.datas.originalList = this.datas.originalList.concat(result);
  477. this.updateUnitPrice(pgljID,unitPrice);
  478. materialCalcObj.showDatas();
  479. }catch (e){
  480. console.log(e)
  481. }finally {
  482. $.bootstrapLoading.end();
  483. }
  484. };
  485. ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
  486. let tasks = [];
  487. let updateDatas=[];
  488. try {
  489. for(let d of datas){
  490. let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
  491. if(_.isEmpty(unitPrice.doc)) continue;
  492. tasks.push({updateOne: {filter: {id: unitPrice.id,unit_price_file_id:unitPrice.unit_price_file_id}, update: unitPrice.doc}})
  493. updateDatas.push({id:d.id,unitPrice:unitPrice})
  494. }
  495. $.bootstrapLoading.start();
  496. let result = await ajaxPost('/glj/updateMaterialCalc',{tasks:tasks});
  497. this.m_updateUnitPrice(updateDatas);
  498. materialCalcObj.showDatas();
  499. }catch (e){
  500. console.log(e)
  501. }finally {
  502. $.bootstrapLoading.end();
  503. }
  504. };
  505. ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
  506. try {
  507. let updateMap = {};
  508. let tasks = [];
  509. for(let d of datas){
  510. updateMap[d.ID] = d.doc;
  511. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  512. }
  513. let unitPrice = this.materialCal(pgljID,{freight:{update:updateMap}});
  514. $.bootstrapLoading.start();
  515. let result = await ajaxPost('/glj/updateFreightCalc',{tasks:tasks,unitPrice:unitPrice});
  516. for(let o of this.datas.freightList){
  517. if(updateMap[o.ID]){
  518. gljUtil.updateProperty(o,updateMap[o.ID]);
  519. }
  520. }
  521. this.updateUnitPrice(pgljID,unitPrice);
  522. materialCalcObj.showDatas();
  523. }catch (e){
  524. console.log(e)
  525. }finally {
  526. $.bootstrapLoading.end();
  527. }
  528. };
  529. ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
  530. try {
  531. let updateMap = {};
  532. let tasks = [];
  533. for(let d of datas){
  534. updateMap[d.ID] = d.doc;
  535. tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
  536. }
  537. let unitPrice = this.materialCal(pgljID,{price:{update:updateMap}});
  538. $.bootstrapLoading.start();
  539. let result = await ajaxPost('/glj/updateOriginalCalc',{tasks:tasks,unitPrice:unitPrice});
  540. for(let o of this.datas.originalList){
  541. if(updateMap[o.ID]){
  542. gljUtil.updateProperty(o,updateMap[o.ID]);
  543. }
  544. }
  545. this.updateUnitPrice(pgljID,unitPrice);
  546. materialCalcObj.showDatas();
  547. }catch (e){
  548. console.log(e)
  549. }finally {
  550. $.bootstrapLoading.end();
  551. }
  552. };
  553. ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
  554. try {
  555. let unitPrice = this.materialCal(pgljID,{freight:{add:datas}});
  556. $.bootstrapLoading.start();
  557. let result = await ajaxPost('/glj/addFreightCalc',{datas:datas,unitPrice:unitPrice});
  558. this.datas.freightList = this.datas.freightList.concat(result);
  559. this.updateUnitPrice(pgljID,unitPrice);
  560. materialCalcObj.showDatas();
  561. }catch (e){
  562. console.log(e)
  563. }finally {
  564. $.bootstrapLoading.end();
  565. }
  566. };
  567. ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
  568. try {
  569. let data={ID:ID};
  570. // 计算预算价
  571. let unitPrice = this.materialCal(pgljID,{price:{'delete':ID}});
  572. data.unitPrice = unitPrice;
  573. $.bootstrapLoading.start();
  574. await ajaxPost('/glj/deletePriceCalc',data);
  575. _.remove(this.datas.originalList,{'ID':data.ID});
  576. //更新单价文件的值
  577. this.updateUnitPrice(pgljID,unitPrice);
  578. materialCalcObj.showDatas();
  579. }catch (e){
  580. console.log(e)
  581. }finally {
  582. $.bootstrapLoading.end();
  583. }
  584. };
  585. ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
  586. try {
  587. let data={ID:ID};
  588. // 计算预算价
  589. let unitPrice = this.materialCal(pgljID,{freight:{'delete':ID}});
  590. data.unitPrice = unitPrice;
  591. $.bootstrapLoading.start();
  592. let result = await ajaxPost('/glj/deleteFreightCalc',data);
  593. console.log(result);
  594. _.remove(this.datas.freightList,{'ID':data.ID});
  595. // 更新单价文件的值
  596. this.updateUnitPrice(pgljID,unitPrice);
  597. materialCalcObj.showDatas();
  598. }catch (e){
  599. console.log(e)
  600. }finally {
  601. $.bootstrapLoading.end();
  602. }
  603. };
  604. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  605. let me = this;
  606. let projectGljs = this.datas.gljList;
  607. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  608. let glj = _.find(projectGljs, {'id': pgljID});
  609. if (glj) {
  610. if(glj.unit_price[updateField] == newval){
  611. return;
  612. }
  613. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  614. 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};
  615. let callback = function (data) {
  616. if (updateField == 'base_price') {
  617. glj.unit_price.base_price = newval;
  618. me.setAdjustPrice(glj);
  619. } else {
  620. glj.unit_price.market_price = newval;
  621. }
  622. //更新回传的父节点项目工料机价格
  623. let gljs = me.getProjectGLJs(data);
  624. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  625. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  626. gljOprObj.showRationGLJSheetData();
  627. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  628. gljs.push(glj);
  629. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  630. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  631. projectGljObject.onUnitFileChange(data);
  632. if(cb){
  633. cb(gljs);
  634. }
  635. $.bootstrapLoading.end();
  636. }
  637. $.bootstrapLoading.start();
  638. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  639. $.bootstrapLoading.end();
  640. });
  641. } else {
  642. gljOprObj.showRationGLJSheetData();
  643. }
  644. };
  645. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  646. let me = this;
  647. //更新是否暂估和供货方式时,要做特殊处理
  648. $.bootstrapLoading.start();
  649. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  650. $.bootstrapLoading.end();
  651. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  652. console.log(updateMap);
  653. for(let idKey in updateMap){
  654. let gljID = parseInt(idKey);
  655. let glj = me.getByID(gljID);
  656. let doc = updateMap[idKey];
  657. for(let property in doc){
  658. glj[property] = doc[property];
  659. }
  660. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  661. supplyChangeIDs.push(gljID);
  662. }
  663. if(doc.hasOwnProperty("is_evaluate")){
  664. evaluate_gljs.push(glj);
  665. }
  666. }
  667. if(supplyChangeIDs.length>0){
  668. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  669. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  670. }
  671. if(evaluate_gljs.length > 0){
  672. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  673. rationNodes = rationNodes.concat(impactRationNodes);
  674. }
  675. if(rationNodes.length > 0){
  676. rationNodes = _.uniq(rationNodes,'data');
  677. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  678. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  679. });
  680. }
  681. if(callback){
  682. callback();
  683. }
  684. })
  685. };
  686. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  687. let me = this;
  688. let projectGljs = me.datas.gljList;
  689. let updateData = [];
  690. let newValueMap = {};
  691. let gljs=[];
  692. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  693. if(changeInfo.length<=0){
  694. callback?callback():'';
  695. return
  696. }
  697. for(let ci of changeInfo){
  698. let dataCode = setting.header[ci.col].dataCode;
  699. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  700. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  701. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  702. let glj = _.find(projectGljs, {'id': recode.id});
  703. let newValue = ci.value;
  704. if(glj&&glj.unit_price[editField]!=newValue){
  705. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  706. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  707. newValueMap[glj.id]={field:editField,value:newValue};
  708. gljs.push(glj);
  709. }
  710. }
  711. }
  712. console.log(updateData);
  713. if(updateData.length > 0){
  714. $.bootstrapLoading.start();
  715. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  716. let parentData = [];
  717. //更新缓存
  718. for(let g of gljs){
  719. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  720. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  721. }
  722. //更新父工料机价格
  723. for(let r of result){
  724. let pdata = r.updateOne.filter;
  725. let set = r.updateOne.update.$set;
  726. for(let skey in set){
  727. pdata[skey] = set[skey];
  728. }
  729. parentData.push(pdata);
  730. }
  731. let pgljs = me.getProjectGLJs(parentData);
  732. gljs = gljs.concat(pgljs);
  733. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  734. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  735. gljOprObj.showRationGLJSheetData();
  736. projectGljObject.onUnitFileChange(gljs);
  737. if(callback){
  738. callback(gljs);
  739. }
  740. $.bootstrapLoading.end();
  741. }, function (err) {
  742. $.bootstrapLoading.end();
  743. });
  744. }
  745. };
  746. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  747. let me = this;
  748. $.bootstrapLoading.start();
  749. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  750. let parent = updateData[updateData.length - 1];
  751. let parentGlj = me.getByConKey(parent.connect_key);
  752. for(let u of updateData){
  753. if(u.type == 'mix_ratio'){
  754. let tem = updateMap[u.query.id];
  755. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  756. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  757. if(subData){
  758. subData.consumption = u.doc.consumption;
  759. }
  760. let m_list = me.datas.mixRatioMap[parent.connect_key];
  761. let m_ratioData = _.find(m_list,{"id":u.query.id});
  762. if(m_ratioData){
  763. m_ratioData.consumption = u.doc.consumption;
  764. }
  765. }
  766. }
  767. parentGlj.unit_price.market_price = parent.market_price;
  768. parentGlj.unit_price.base_price = parent.base_price;
  769. me.calcQuantity();
  770. if(callback){
  771. callback();
  772. }
  773. $.bootstrapLoading.end();
  774. },function () {
  775. $.bootstrapLoading.end();
  776. })
  777. };
  778. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  779. let me = this;
  780. $.bootstrapLoading.start();
  781. CommonAjax.specialPost( '/glj/update',data,function (result) {
  782. let glj = me.getByID(data.id);//更新缓存
  783. let impactList = [];
  784. glj[data.field] = data.value;
  785. if(data.extend&&data.extend!=""){
  786. let extend = JSON.parse(data.extend);
  787. for (let key in extend) {
  788. glj[key] = extend[key];
  789. }
  790. }
  791. if(data.field == 'is_evaluate'){
  792. impactList = me.changeIsEvaluate(data.id);
  793. }
  794. if(callback){
  795. callback(impactList);
  796. }
  797. $.bootstrapLoading.end();
  798. });
  799. };
  800. ProjectGLJ.prototype.getRatioData=function(id,callback){
  801. this.getRatioId = id;
  802. if(id){
  803. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  804. let ratios = JSON.parse(response.data);
  805. if(callback){
  806. callback(ratios);
  807. }
  808. },function () {//取不到组成物的情况
  809. callback([]);
  810. })
  811. }else {
  812. if(callback){
  813. callback([]);
  814. }
  815. }
  816. };
  817. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  818. $.bootstrapLoading.start();
  819. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  820. projectObj.project.property.unitPriceFile = response.unitFile;
  821. projectObj.project.projectGLJ.loadData(function () {
  822. if(callback){
  823. callback();
  824. }
  825. $.bootstrapLoading.end();
  826. });
  827. }, function (err) {
  828. if($.bootstrapLoading.isLoading()){
  829. $.bootstrapLoading.end();
  830. }
  831. alert(err.msg);
  832. });
  833. };
  834. ProjectGLJ.prototype.changeVvTaxFile = async function (newVvTaxFileID,callback) {
  835. $.bootstrapLoading.start();
  836. try {
  837. await ajaxPost("/glj/changeVvTaxFile",{unitFileID:projectObj.project.property.unitPriceFile.id,newVvTaxFileID:newVvTaxFileID});
  838. await this.synLoadData();
  839. projectGljObject.refreshDataSheet();
  840. gljOprObj.refreshView();
  841. projectObj.project.ration_glj.reCalcWhenVvTaxChange();
  842. projectGljObject.onUnitFileChange();
  843. }catch (err){
  844. console.log(err);
  845. }finally {
  846. $.bootstrapLoading.end();
  847. }
  848. };
  849. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  850. let gljList = [],allGLJ = gljOprObj.AllRecode;
  851. if(selections.length == 0) {
  852. return;
  853. }
  854. for(let glj of allGLJ){
  855. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  856. if(_.includes(selections,i_key)){
  857. let pglj = {
  858. project_id: projectObj.project.ID(),
  859. glj_id: glj.ID,
  860. name: glj.name,
  861. code: glj.code,
  862. original_code: glj.code,
  863. unit: glj.unit,
  864. specs: glj.specs,
  865. base_price: glj.basePrice,
  866. market_price: glj.basePrice,
  867. shortName: glj.shortName,
  868. type: glj.gljType,
  869. model:glj.model,
  870. adjCoe: glj.adjCoe,
  871. from:'std',
  872. repositoryId:glj.repositoryId,
  873. materialType:glj.materialType,
  874. materialCoe:glj.materialCoe,
  875. grossWeightCoe:glj.grossWeightCoe,
  876. purchaseStorageRate:glj.purchaseStorageRate,
  877. offSiteTransportLossRate:glj.offSiteTransportLossRate,
  878. handlingLossRate:glj.handlingLossRate
  879. };
  880. if (glj.hasOwnProperty("compilationId")) {
  881. pglj.from = "cpt";
  882. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  883. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  884. }
  885. }
  886. gljList.push(pglj);
  887. }
  888. }
  889. gljList = _.sortByAll(gljList, ['type', 'code']);
  890. if(gljList.length == 0) return;
  891. let praentInfo = {
  892. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  893. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  894. };
  895. $.bootstrapLoading.start();
  896. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  897. $.bootstrapLoading.end();
  898. if(callback){
  899. callback(data);
  900. }
  901. }, function () {
  902. $.bootstrapLoading.end();
  903. });
  904. }
  905. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  906. let property = projectObj.project.projectInfo.property;
  907. let data = {
  908. name:newVal,
  909. rootProjectID:property.rootProjectID
  910. }
  911. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  912. callback(data);
  913. });
  914. };
  915. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  916. $.bootstrapLoading.start();
  917. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  918. projectObj.project.projectGLJ.loadData(function () {
  919. if(callback){
  920. callback();
  921. }
  922. $.bootstrapLoading.end();
  923. });
  924. },function (response) {
  925. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  926. $("#save-as-tips").text(msg).show();
  927. $.bootstrapLoading.end();
  928. });
  929. };
  930. //更新是否暂估
  931. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  932. let projectGLJ = projectObj.project.projectGLJ;
  933. let datas = projectGLJ.datas;
  934. let gljList = datas.gljList;
  935. let glj = _.find(gljList, {'id': id});
  936. if(glj){//与批量更新调用相同的方法
  937. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  938. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  939. let conditions = [];
  940. if(pratioM&&pratioM.length>0){
  941. for(let p_key of pratioM ){
  942. conditions.push(gljOprObj.getConditionByKey(p_key));
  943. }
  944. }
  945. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  946. gljs.push(glj);
  947. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  948. //更新对应的工料机类型的定额
  949. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  950. let ration_nodes = [];
  951. for(r of rations){
  952. if(r){
  953. r.isEstimate =glj.is_evaluate?1:0;
  954. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  955. ration_node?ration_nodes.push(ration_node):'';
  956. }
  957. }
  958. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  959. for(rg of ration_glj_nodes){
  960. rg.data.isEstimate =glj.is_evaluate?1:0;
  961. ration_nodes.push(rg);
  962. }
  963. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  964. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  965. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  966. return gljs;
  967. }
  968. };
  969. /**
  970. * 批量更新是否暂估
  971. *传入项目工料机数组
  972. */
  973. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  974. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  975. for(let glj of gljs){
  976. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  977. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  978. let conditions = [];
  979. if(pratioM&&pratioM.length>0){
  980. for(let p_key of pratioM ){
  981. conditions.push(gljOprObj.getConditionByKey(p_key));
  982. }
  983. }
  984. let tem_gljs = this.getProjectGLJs(conditions,false);
  985. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  986. }
  987. impactGLJs = impactGLJs.concat(gljs);
  988. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  989. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  990. let neeRefreshNode = [];
  991. //更新对应的工料机类型的定额
  992. for(let item of projectObj.project.Ration.datas){
  993. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  994. let tem_g = changeMap[item.projectGLJID];
  995. item.isEstimate =tem_g.is_evaluate?1:0;
  996. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  997. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  998. }
  999. }
  1000. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  1001. for(let rg of ration_glj_nodes){
  1002. let tem_g = changeMap[rg.data.projectGLJID];
  1003. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  1004. neeRefreshNode.push(rg);
  1005. }
  1006. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  1007. return [impactRationNodes,impactGLJs];
  1008. };
  1009. ProjectGLJ.prototype.getByID = function (ID) {
  1010. return _.find(this.datas.gljList,{'id':ID});
  1011. };
  1012. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  1013. return _.find(this.datas.gljList,function (item) {
  1014. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  1015. return tem_key == conkey
  1016. })
  1017. };
  1018. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  1019. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  1020. let me = this;
  1021. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1022. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  1023. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  1024. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  1025. return true;
  1026. }
  1027. })
  1028. projectObj.mainController.refreshTreeNode(nodes);
  1029. }
  1030. }
  1031. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  1032. let nodes = [];
  1033. let ids = [];
  1034. if(Array.isArray(id)){
  1035. ids = id;
  1036. }else {
  1037. ids = [id];
  1038. }
  1039. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  1040. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  1041. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  1042. })
  1043. }
  1044. return nodes;
  1045. };
  1046. //根据工料机,取得所有受影响的定额节点
  1047. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  1048. let nodes = [];
  1049. let rationMap = {};
  1050. let idArray = _.map(gljs,'id');
  1051. let gljMap = _.indexBy(gljs,'id');
  1052. //先根据项目工料机ID,找到受影响定额的ID
  1053. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  1054. for (let rg of ration_glj_list) {
  1055. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  1056. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  1057. }
  1058. }
  1059. for (let item of projectObj.project.mainTree.items) {
  1060. if (item.sourceType == ModuleNames.ration) {
  1061. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  1062. let tem_g = gljMap[item.data.projectGLJID];
  1063. if(tem_g){
  1064. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  1065. item.data.marketPrice = this.getMarketPrice(tem_g);
  1066. nodes.push(item);
  1067. }
  1068. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  1069. nodes.push(item)
  1070. }
  1071. }
  1072. }
  1073. return nodes;
  1074. };
  1075. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  1076. for (let ration_glj of gljOprObj.sheetData) {
  1077. if (ration_glj.projectGLJID == glj.id) {
  1078. ration_glj.basePrice = this.getBasePrice(glj);
  1079. ration_glj.marketPrice = this.getMarketPrice(glj);
  1080. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  1081. }
  1082. }
  1083. }
  1084. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  1085. }
  1086. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  1087. let parentGlj = [];
  1088. //
  1089. let projectGljs = this.datas.gljList;
  1090. let indexList = gljKeyArray;
  1091. for (let d of data) {
  1092. if (d) {
  1093. let glj = _.find(projectGljs, function (item) {
  1094. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  1095. });
  1096. if (glj) {
  1097. if(refreshPrice==true){
  1098. d.base_price?glj.unit_price.base_price = d.base_price:'';
  1099. d.market_price?glj.unit_price.market_price = d.market_price:'';
  1100. this.setAdjustPrice(glj);
  1101. this.refreshRationGLJPrice(glj);
  1102. this.refreshTreeNodePriceIfNeed(glj);
  1103. }
  1104. parentGlj.push(glj);
  1105. }
  1106. }
  1107. }
  1108. return parentGlj;
  1109. }
  1110. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  1111. switch (glj.unit_price.type + '') {
  1112. // 人工: 调整基价=基价单价*调整系数
  1113. case GLJTypeConst.LABOUR:
  1114. case GLJTypeConst.MACHINE_LABOUR:
  1115. glj.adjust_price = this.getAdjustPrice(glj);
  1116. break;
  1117. // 机械类型的算法
  1118. case GLJTypeConst.MACHINE:
  1119. console.log('机械');
  1120. break;
  1121. // 材料、主材、设备
  1122. default:
  1123. glj.adjust_price = glj.unit_price.base_price;
  1124. }
  1125. }
  1126. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  1127. let proGLJ = projectObj.project.projectGLJ;
  1128. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1129. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1130. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1131. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1132. };
  1133. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  1134. let proGLJ = projectObj.project.projectGLJ;
  1135. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1136. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1137. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1138. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1139. };
  1140. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  1141. let proGLJ = projectObj.project.projectGLJ;
  1142. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1143. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1144. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1145. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  1146. };
  1147. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  1148. let proGLJ = projectObj.project.projectGLJ;
  1149. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  1150. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1151. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1152. let tenderCoe = 1;
  1153. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  1154. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  1155. }
  1156. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  1157. };
  1158. ProjectGLJ.prototype.isEstimateType = function(type){
  1159. let typeString = type + "";
  1160. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  1161. return type;
  1162. }
  1163. return false;
  1164. };
  1165. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  1166. let gljTypeMap = this.datas.constData.gljTypeMap;
  1167. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  1168. };
  1169. ProjectGLJ.prototype.calcQuantity = function (init=false){
  1170. let project_gljs = this.datas.gljList;
  1171. let changeArray=[];
  1172. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1173. let rationDatas = projectObj.project.Ration.datas;
  1174. let billsDatas = projectObj.project.Bills.datas;
  1175. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  1176. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  1177. this.quantityChangeMap = {};
  1178. for(let pglj of project_gljs){
  1179. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1180. }
  1181. }else if(this.quantityChangeMap != null){
  1182. for(let pglj of project_gljs){
  1183. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  1184. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  1185. changeArray.push(pglj);
  1186. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1187. }
  1188. }else { //映射表没有,说明是新添加的项目工料机
  1189. changeArray.push(pglj);
  1190. this.quantityChangeMap[pglj.id] = pglj.quantity;
  1191. }
  1192. }
  1193. }
  1194. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  1195. };
  1196. ProjectGLJ.prototype.calcTenderQuantity = function (){
  1197. let rationGLJDatas = projectObj.project.ration_glj.datas;
  1198. let rationDatas = projectObj.project.Ration.datas;
  1199. let billsDatas = projectObj.project.Bills.datas;
  1200. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  1201. };