project_glj.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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) {
  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. },
  34. beforeSend: function () {
  35. self.isLoading = true;
  36. },
  37. success: function (response) {
  38. self.isLoading = false;
  39. if (response.err === 1) {
  40. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取人材机数据失败!';
  41. alert(msg);
  42. return false;
  43. }
  44. self.refreshByDatas(response.data);
  45. // 回调函数
  46. if (callback !== null) {
  47. callback(response.data);
  48. }
  49. // 存入缓存
  50. projectObj.project.projectGLJ = self;
  51. }
  52. });
  53. };
  54. ProjectGLJ.prototype.loadDataSync = async function () {
  55. if (this.isLoading) {
  56. return false;
  57. }
  58. this.isLoading = true;
  59. const project_id = projectObj.project.ID();
  60. try {
  61. const rst = await ajaxPost('/glj/getData', { project_id }, true);
  62. this.isLoading = false;
  63. this.refreshByDatas(rst);
  64. projectObj.project.projectGLJ = this;
  65. } catch (err) {
  66. this.isLoading = false;
  67. throw new Error('获取项目人材机数据错误');
  68. }
  69. }
  70. //更新项目工料机数据和缓存
  71. ProjectGLJ.prototype.refreshByDatas = function(datas){
  72. this.datas = datas;
  73. this.calcQuantity();
  74. };
  75. ProjectGLJ.prototype.loadToCache = function (data) {
  76. this.datas = data;
  77. }
  78. /**
  79. * 获取对应工料机数据
  80. *
  81. * @param {String} code
  82. * @return {Object}
  83. */
  84. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  85. return _.find(this.datas.gljList, {'id': ID});
  86. };
  87. // CSL, 2018-02-08 甲供、甲定。
  88. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  89. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  90. // 所以这里要合并处理。
  91. let mixSupply = [];
  92. for (let s of supplyTypeArr){
  93. switch (s) {
  94. case 1:
  95. mixSupply.push('部分甲供');
  96. break;
  97. case 2:
  98. mixSupply.push('完全甲供');
  99. break;
  100. case 3:
  101. mixSupply.push('甲定乙供');
  102. break;
  103. default:
  104. mixSupply.push('自行采购');
  105. }
  106. };
  107. mixSupply = mixSupply.concat(supplyTypeArr);
  108. return _.filter(this.datas.gljList, function (glj) {
  109. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  110. });
  111. };
  112. ProjectGLJ.prototype.testGLJs = function () {
  113. let gljs = [];
  114. for (let glj of this.datas.gljList){
  115. let o = new Object();
  116. o.name = glj.name;
  117. o.supply = glj.supply;
  118. o.quantity = glj.quantity;
  119. o.supply_quantity = glj.supply_quantity;
  120. gljs.push(o);
  121. };
  122. return gljs;
  123. };
  124. /**
  125. * 修改工料机数据
  126. *
  127. * @param {Number} id
  128. * @param {Object} data
  129. * @return {boolean}
  130. */
  131. ProjectGLJ.prototype.updateData = function (id, data) {
  132. let result = false;
  133. if (this.datas === null) {
  134. return result;
  135. }
  136. let gljList = this.datas.gljList;
  137. if (gljList === undefined) {
  138. return result;
  139. }
  140. // 查找对应的index
  141. let index = -1;
  142. for (let tmp in gljList) {
  143. if (gljList[tmp].id === id) {
  144. index = tmp;
  145. break;
  146. }
  147. }
  148. if (index < 0) {
  149. return result;
  150. }
  151. // 修改数据
  152. for (let tmpIndex in data) {
  153. if (tmpIndex.indexOf('_price') >= 0) {
  154. // 修改unit_price中的对象
  155. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  156. } else {
  157. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  158. }
  159. }
  160. };
  161. /**
  162. * 加载缓存数据到spread
  163. *
  164. * @return {void}
  165. */
  166. ProjectGLJ.prototype.loadCacheData = function (resort) {
  167. // 加载工料机数据
  168. let data = this.datas === null ? null : this.datas;
  169. if (data === null) {
  170. return;
  171. }
  172. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  173. console.log("filter start");
  174. jsonData = filterProjectGLJ(jsonData);
  175. console.log("filter end");
  176. jsonData = sortProjectGLJ(jsonData);
  177. console.log("sort end");
  178. if(projectGLJSheet&&projectGLJSpread){
  179. setTimeout(spreadInit, 1);
  180. /*projectGLJSheet.setData(jsonData);
  181. projectGLJSpread.specialColumn(jsonData);*/
  182. }
  183. };
  184. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval,callback) {
  185. if (updateField == 'marketPrice') {
  186. this.updatePrice(recode, "market_price", newval,"rg",null,callback);
  187. }
  188. if (updateField == 'basePrice') {
  189. this.updatePrice(recode, "base_price", newval,"rg",null,callback);
  190. }
  191. };
  192. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  193. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  194. projectObj.project.Ration.updateContain(newval,node);
  195. }if(updateField == "quantity"){
  196. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  197. } else {
  198. this.updateGLJProperty(node, updateField, newval);
  199. }
  200. };
  201. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  202. let rationTypeGLJ = node.data;
  203. let postData = {};
  204. if (rationTypeGLJ[updateField] == newval) {
  205. projectObj.mainController.refreshTreeNode([node]);
  206. return;
  207. }
  208. let data = {
  209. glj_id: rationTypeGLJ.GLJID,
  210. project_id: rationTypeGLJ.projectID,
  211. code: rationTypeGLJ.code,
  212. original_code: rationTypeGLJ.original_code,
  213. name: rationTypeGLJ.name,
  214. shortName: rationTypeGLJ.shortName,
  215. specs: rationTypeGLJ.specs,
  216. unit: rationTypeGLJ.unit,
  217. type: rationTypeGLJ.subType,
  218. type_of_work: rationTypeGLJ.subType,
  219. base_price: rationTypeGLJ.basePrice,
  220. market_price: rationTypeGLJ.basePrice,
  221. repositoryId: rationTypeGLJ.repositoryId,
  222. adjCoe: rationTypeGLJ.adjCoe,
  223. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  224. };
  225. if (updateField == 'subType') {
  226. data.type = newval;
  227. data.type_of_work = newval;
  228. data.shortName = this.getShortNameByID(newval);
  229. } else {
  230. data[updateField] = newval;
  231. }
  232. postData.ration = {
  233. ID: rationTypeGLJ.ID,
  234. projectID: rationTypeGLJ.projectID
  235. };
  236. postData.updateData = data;
  237. $.bootstrapLoading.start();
  238. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  239. console.log(result); //更新节点信息
  240. rationTypeGLJ[updateField] = newval;
  241. rationTypeGLJ.projectGLJID = result.id;
  242. rationTypeGLJ.code = result.code;
  243. rationTypeGLJ.basePrice = result.unit_price.base_price;
  244. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  245. rationTypeGLJ.isAdd = result.unit_price.is_add;
  246. rationTypeGLJ.isEstimate = result.is_evaluate;
  247. rationTypeGLJ.shortName = result.unit_price.short_name;
  248. //触发计算并更新节点信息
  249. node.changed = true;
  250. projectObj.project.projectGLJ.loadData(function () {
  251. projectObj.project.calcProgram.calcAndSave(node);
  252. $.bootstrapLoading.end();
  253. });//重新加载项目工料机数据
  254. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  255. }, function (err) {
  256. $.bootstrapLoading.end();
  257. });
  258. }
  259. ProjectGLJ.prototype.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  260. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  261. return getDecimal("glj.unitPriceHasMix");
  262. }else {
  263. return getDecimal('glj.unitPrice');
  264. }
  265. };
  266. ProjectGLJ.prototype.doAfterPriceChange=function(gljs){
  267. //更新回传的父节点项目工料机价格
  268. projectGljObject.refreshDataSheet(true);//更新工料机汇总缓存和显示
  269. gljOprObj.showRationGLJSheetData();
  270. let nodes = this.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  271. projectObj.project.calcProgram.calcNodesAndSave(nodes, async function () {
  272. await OVER_HEIGHT.reCalcOverHeightFee();
  273. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(nodes);
  274. });//触发计算程序
  275. projectGljObject.onUnitFileChange(gljs);
  276. }
  277. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,tdoc,cb) {
  278. let me = this;
  279. let projectGljs = this.datas.gljList;
  280. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  281. let glj = _.find(projectGljs, {'id': pgljID});
  282. let udoc = tdoc?tdoc:{"priceFrom":""};//20200728 新增价格来源,默认为空
  283. if (glj) {
  284. if(glj.unit_price[updateField] == newval){
  285. return;
  286. }
  287. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  288. 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};
  289. if(updateField == 'market_price') data.udoc=udoc;
  290. let callback = function (data) {
  291. if (updateField == 'base_price') {
  292. glj.unit_price.base_price = newval;
  293. me.setAdjustPrice(glj);
  294. } else {
  295. glj.unit_price.market_price = newval;
  296. gljUtil.setProperty(glj.unit_price,udoc);
  297. }
  298. //更新回传的父节点项目工料机价格
  299. let gljs = me.getProjectGLJs(data);
  300. gljs.push(glj);
  301. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  302. projectObj.project.projectGLJ.doAfterPriceChange(gljs);//更新工料机汇总缓存和显示
  303. if(cb){
  304. cb(gljs);
  305. }
  306. $.bootstrapLoading.end();
  307. }
  308. $.bootstrapLoading.start();
  309. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  310. $.bootstrapLoading.end();
  311. });
  312. } else {
  313. gljOprObj.showRationGLJSheetData();
  314. }
  315. };
  316. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  317. let me = this;
  318. //更新是否暂估和供货方式时,要做特殊处理
  319. $.bootstrapLoading.start();
  320. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  321. $.bootstrapLoading.end();
  322. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  323. console.log(updateMap);
  324. let needCalcQuantity = false;
  325. for(let idKey in updateMap){
  326. let gljID = parseInt(idKey);
  327. let glj = me.getByID(gljID);
  328. let doc = updateMap[idKey];
  329. for(let property in doc){
  330. glj[property] = doc[property];
  331. }
  332. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  333. supplyChangeIDs.push(gljID);
  334. }
  335. if(doc.hasOwnProperty("is_evaluate")) evaluate_gljs.push(glj);
  336. if(doc.hasOwnProperty("is_adjust_price")) needCalcQuantity = true;
  337. }
  338. if(supplyChangeIDs.length>0){
  339. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  340. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  341. }
  342. if(evaluate_gljs.length > 0){
  343. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  344. rationNodes = rationNodes.concat(impactRationNodes);
  345. }
  346. if(rationNodes.length > 0){
  347. rationNodes = _.uniq(rationNodes,'data');
  348. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  349. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  350. });
  351. }
  352. if(needCalcQuantity) me.calcQuantity();
  353. if(callback){
  354. callback();
  355. }
  356. })
  357. };
  358. ProjectGLJ.prototype.mutiApplyInfoPrice = async function(pgljMap,condition,priceFrom) {
  359. try {
  360. $.bootstrapLoading.start();
  361. let taxType = projectObj.project.property.taxType;
  362. let projectGLJMap = await ajaxPost("/infoPrice/mutiApplyInfoPrice",{pgljMap:pgljMap,condition:condition,taxType:taxType,decimal:getDecimal('glj.unitPrice'),priceFrom:priceFrom});
  363. let parentKeyMap = {};
  364. let gljs = [];
  365. if(!_.isEmpty(projectGLJMap)){
  366. for(let id in projectGLJMap){//先整理出受影响的父工料机
  367. let mixRatioKey = projectGLJMap[id].index;
  368. let parentArray = this.datas.mixRatioConnectData[mixRatioKey];
  369. if(!parentArray) continue;
  370. for(pk of parentArray){
  371. parentKeyMap[pk] = true;
  372. }
  373. }
  374. for(let glj of this.datas.gljList){
  375. if(projectGLJMap[glj.id]){
  376. gljUtil.setProperty(glj.unit_price,projectGLJMap[glj.id].doc);
  377. gljs.push(glj);
  378. }else if(parentKeyMap[gljUtil.getIndex(glj)]){
  379. gljs.push(glj);
  380. }
  381. }
  382. this.doAfterPriceChange(gljs);
  383. }
  384. } catch (error) {
  385. console.log(error);
  386. }
  387. $.bootstrapLoading.end();
  388. }
  389. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  390. let me = this;
  391. let projectGljs = me.datas.gljList;
  392. let updateData = [];
  393. let newValueMap = {};
  394. let gljs=[];
  395. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  396. if(changeInfo.length<=0){
  397. callback?callback():'';
  398. return
  399. }
  400. for(let ci of changeInfo){
  401. let dataCode = setting.header[ci.col].dataCode;
  402. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  403. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  404. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  405. let glj = _.find(projectGljs, {'id': recode.id});
  406. let newValue = ci.value;
  407. if(glj&&glj.unit_price[editField]!=newValue){
  408. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  409. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  410. newValueMap[glj.id]={field:editField,value:newValue};
  411. gljs.push(glj);
  412. }
  413. }
  414. }
  415. if(updateData.length > 0){
  416. $.bootstrapLoading.start();
  417. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  418. let parentData = [];
  419. //更新缓存
  420. for(let g of gljs){
  421. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  422. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  423. }
  424. //更新父工料机价格
  425. for(let r of result){
  426. let pdata = r.updateOne.filter;
  427. let set = r.updateOne.update.$set;
  428. for(let skey in set){
  429. pdata[skey] = set[skey];
  430. }
  431. parentData.push(pdata);
  432. }
  433. let pgljs = me.getProjectGLJs(parentData);
  434. gljs = gljs.concat(pgljs);
  435. me.doAfterPriceChange(gljs);
  436. if(callback){
  437. callback(gljs);
  438. }
  439. $.bootstrapLoading.end();
  440. }, function (err) {
  441. $.bootstrapLoading.end();
  442. });
  443. }
  444. };
  445. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  446. let me = this;
  447. $.bootstrapLoading.start();
  448. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  449. let parent = updateData[updateData.length - 1];
  450. let parentGlj = me.getByConKey(parent.connect_key);
  451. for(let u of updateData){
  452. if(u.type == 'mix_ratio'){
  453. let tem = updateMap[u.query.id];
  454. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  455. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  456. if(subData){
  457. subData.consumption = u.doc.consumption;
  458. }
  459. let m_list = me.datas.mixRatioMap[parent.connect_key];
  460. let m_ratioData = _.find(m_list,{"id":u.query.id});
  461. if(m_ratioData){
  462. m_ratioData.consumption = u.doc.consumption;
  463. }
  464. }
  465. }
  466. parentGlj.unit_price.market_price = parent.market_price;
  467. parentGlj.unit_price.base_price = parent.base_price;
  468. me.calcQuantity();
  469. if(callback){
  470. callback();
  471. }
  472. $.bootstrapLoading.end();
  473. },function () {
  474. $.bootstrapLoading.end();
  475. })
  476. };
  477. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  478. let me = this;
  479. let glj = me.getByID(data.id);
  480. if(data.field == 'taxRate'){
  481. data.field = "unit_price.taxRate";
  482. data.id = glj.unit_price.id;
  483. }
  484. $.bootstrapLoading.start();
  485. CommonAjax.specialPost( '/glj/update',data,function (result) {
  486. let impactList = [];
  487. _.set(glj,data.field,data.value);//更新缓存
  488. // glj[data.field] = data.value;
  489. if(data.extend&&data.extend!=""){
  490. let extend = JSON.parse(data.extend);
  491. for (let key in extend) {
  492. glj[key] = extend[key];
  493. }
  494. }
  495. if(data.field == 'is_evaluate'){
  496. impactList = me.changeIsEvaluate(data.id);
  497. }
  498. if(data.field == "is_adjust_price") me.calcQuantity();
  499. if(callback){
  500. callback(impactList);
  501. }
  502. $.bootstrapLoading.end();
  503. });
  504. };
  505. ProjectGLJ.prototype.getRatioData=function(id,callback){
  506. this.getRatioId = id;
  507. if(id){
  508. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  509. let ratios = JSON.parse(response.data);
  510. if(callback){
  511. callback(ratios);
  512. }
  513. },function () {//取不到组成物的情况
  514. callback([]);
  515. })
  516. }else {
  517. if(callback){
  518. callback([]);
  519. }
  520. }
  521. };
  522. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  523. $.bootstrapLoading.start();
  524. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  525. projectObj.project.property.unitPriceFile = response.unitFile;
  526. projectObj.project.projectGLJ.loadData(function () {
  527. if(callback){
  528. callback();
  529. }
  530. $.bootstrapLoading.end();
  531. });
  532. }, function (err) {
  533. if($.bootstrapLoading.isLoading()){
  534. $.bootstrapLoading.end();
  535. }
  536. alert(err.msg);
  537. });
  538. };
  539. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  540. let gljList = [],allGLJ = gljOprObj.AllRecode;
  541. $("#glj_tree_div").modal('hide');
  542. if(selections.length == 0) {
  543. return;
  544. }
  545. for(let glj of allGLJ){
  546. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  547. if(_.includes(selections,i_key)){
  548. let pglj = {
  549. project_id: projectObj.project.ID(),
  550. glj_id: glj.ID,
  551. name: glj.name,
  552. code: glj.code,
  553. original_code: glj.code,
  554. unit: glj.unit,
  555. specs: glj.specs,
  556. base_price: glj.basePrice,
  557. market_price: glj.basePrice,
  558. shortName: glj.shortName,
  559. type: glj.gljType,
  560. model:glj.model,
  561. adjCoe: glj.adjCoe,
  562. from:'std',
  563. repositoryId:glj.repositoryId,
  564. materialType:glj.materialType,
  565. materialCoe:glj.materialCoe,
  566. materialIndexType:glj.materialIndexType,
  567. materialIndexUnit:glj.materialIndexUnit,
  568. materialIndexCoe:glj.materialIndexCoe
  569. };
  570. if (glj.hasOwnProperty("compilationId")) {
  571. pglj.from = "cpt";
  572. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  573. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  574. }
  575. }
  576. gljList.push(pglj);
  577. }
  578. }
  579. gljList = _.sortByAll(gljList, ['type', 'code']);
  580. if(gljList.length == 0) return;
  581. let praentInfo = {
  582. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  583. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  584. };
  585. $.bootstrapLoading.start();
  586. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  587. $.bootstrapLoading.end();
  588. if(callback){
  589. callback(data);
  590. }
  591. }, function () {
  592. $.bootstrapLoading.end();
  593. });
  594. }
  595. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  596. let property = projectObj.project.projectInfo.property;
  597. let data = {
  598. name:newVal,
  599. rootProjectID:property.rootProjectID
  600. }
  601. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  602. callback(data);
  603. });
  604. };
  605. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  606. $.bootstrapLoading.start();
  607. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  608. projectObj.project.projectGLJ.loadData(function () {
  609. if(callback){
  610. callback();
  611. }
  612. $.bootstrapLoading.end();
  613. });
  614. },function (response) {
  615. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  616. $("#save-as-tips").text(msg).show();
  617. $.bootstrapLoading.end();
  618. });
  619. };
  620. //更新是否暂估
  621. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  622. let projectGLJ = projectObj.project.projectGLJ;
  623. let datas = projectGLJ.datas;
  624. let gljList = datas.gljList;
  625. let glj = _.find(gljList, {'id': id});
  626. if(glj){//与批量更新调用相同的方法
  627. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  628. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  629. let conditions = [];
  630. if(pratioM&&pratioM.length>0){
  631. for(let p_key of pratioM ){
  632. conditions.push(gljOprObj.getConditionByKey(p_key));
  633. }
  634. }
  635. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  636. gljs.push(glj);
  637. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  638. //更新对应的工料机类型的定额
  639. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  640. let ration_nodes = [];
  641. for(r of rations){
  642. if(r){
  643. r.isEstimate =glj.is_evaluate?1:0;
  644. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  645. ration_node?ration_nodes.push(ration_node):'';
  646. }
  647. }
  648. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  649. for(rg of ration_glj_nodes){
  650. rg.data.isEstimate =glj.is_evaluate?1:0;
  651. ration_nodes.push(rg);
  652. }
  653. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  654. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  655. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  656. return gljs;
  657. }
  658. };
  659. /**
  660. * 批量更新是否暂估
  661. *传入项目工料机数组
  662. */
  663. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  664. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  665. for(let glj of gljs){
  666. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  667. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  668. let conditions = [];
  669. if(pratioM&&pratioM.length>0){
  670. for(let p_key of pratioM ){
  671. conditions.push(gljOprObj.getConditionByKey(p_key));
  672. }
  673. }
  674. let tem_gljs = this.getProjectGLJs(conditions,false);
  675. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  676. }
  677. impactGLJs = impactGLJs.concat(gljs);
  678. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  679. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  680. let neeRefreshNode = [];
  681. //更新对应的工料机类型的定额
  682. for(let item of projectObj.project.Ration.datas){
  683. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  684. let tem_g = changeMap[item.projectGLJID];
  685. item.isEstimate =tem_g.is_evaluate?1:0;
  686. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  687. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  688. }
  689. }
  690. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  691. for(let rg of ration_glj_nodes){
  692. let tem_g = changeMap[rg.data.projectGLJID];
  693. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  694. neeRefreshNode.push(rg);
  695. }
  696. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  697. return [impactRationNodes,impactGLJs];
  698. };
  699. ProjectGLJ.prototype.getByID = function (ID) {
  700. return _.find(this.datas.gljList,{'id':ID});
  701. };
  702. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  703. return _.find(this.datas.gljList,function (item) {
  704. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  705. return tem_key == conkey
  706. })
  707. };
  708. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  709. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  710. let me = this;
  711. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  712. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  713. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  714. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  715. return true;
  716. }
  717. })
  718. projectObj.mainController.refreshTreeNode(nodes);
  719. }
  720. }
  721. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  722. let nodes = [];
  723. let ids = [];
  724. if(Array.isArray(id)){
  725. ids = id;
  726. }else {
  727. ids = [id];
  728. }
  729. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  730. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  731. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  732. })
  733. }
  734. return nodes;
  735. };
  736. //根据工料机,取得所有受影响的定额节点
  737. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  738. let nodes = [];
  739. let rationMap = {};
  740. let idArray = _.map(gljs,'id');
  741. let gljMap = _.indexBy(gljs,'id');
  742. //先根据项目工料机ID,找到受影响定额的ID
  743. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  744. for (let rg of ration_glj_list) {
  745. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  746. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  747. }
  748. }
  749. for (let item of projectObj.project.mainTree.items) {
  750. if (item.sourceType == ModuleNames.ration) {
  751. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  752. let tem_g = gljMap[item.data.projectGLJID];
  753. if(tem_g){
  754. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  755. item.data.marketPrice = this.getMarketPrice(tem_g);
  756. nodes.push(item);
  757. }
  758. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  759. nodes.push(item)
  760. }
  761. }
  762. }
  763. return nodes;
  764. };
  765. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  766. for (let ration_glj of gljOprObj.sheetData) {
  767. if (ration_glj.projectGLJID == glj.id) {
  768. ration_glj.basePrice = this.getBasePrice(glj);
  769. ration_glj.marketPrice = this.getMarketPrice(glj);
  770. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  771. }
  772. }
  773. }
  774. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  775. }
  776. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  777. let parentGlj = [];
  778. //
  779. let projectGljs = this.datas.gljList;
  780. let indexList = gljKeyArray;
  781. for (let d of data) {
  782. if (d) {
  783. let glj = _.find(projectGljs, function (item) {
  784. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  785. });
  786. if (glj) {
  787. if(refreshPrice==true){
  788. d.base_price?glj.unit_price.base_price = d.base_price:'';
  789. d.market_price?glj.unit_price.market_price = d.market_price:'';
  790. this.setAdjustPrice(glj);
  791. this.refreshRationGLJPrice(glj);
  792. this.refreshTreeNodePriceIfNeed(glj);
  793. }
  794. parentGlj.push(glj);
  795. }
  796. }
  797. }
  798. return parentGlj;
  799. }
  800. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  801. switch (glj.unit_price.type + '') {
  802. // 人工: 调整基价=基价单价*调整系数
  803. case GLJTypeConst.LABOUR:
  804. case GLJTypeConst.MACHINE_LABOUR:
  805. glj.adjust_price = this.getAdjustPrice(glj);
  806. break;
  807. // 机械类型的算法
  808. case GLJTypeConst.MACHINE:
  809. console.log('机械');
  810. break;
  811. // 材料、主材、设备
  812. default:
  813. glj.adjust_price = glj.unit_price.base_price;
  814. }
  815. }
  816. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  817. let proGLJ = projectObj.project.projectGLJ;
  818. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  819. let decimalObj = projectObj.project.projectInfo.property.decimal;
  820. let labourCoeDatas = projectObj.project.labourCoe.datas;
  821. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  822. };
  823. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  824. let proGLJ = projectObj.project.projectGLJ;
  825. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  826. let decimalObj = projectObj.project.projectInfo.property.decimal;
  827. let labourCoeDatas = projectObj.project.labourCoe.datas;
  828. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  829. };
  830. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  831. let proGLJ = projectObj.project.projectGLJ;
  832. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  833. let decimalObj = projectObj.project.projectInfo.property.decimal;
  834. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,decimalObj,isRadio,_,scMathUtil);
  835. };
  836. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  837. let proGLJ = projectObj.project.projectGLJ;
  838. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  839. let decimalObj = projectObj.project.projectInfo.property.decimal;
  840. let tenderCoe = this.getTenderPriceCoe(glj);
  841. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  842. };
  843. ProjectGLJ.prototype.getTenderPriceCoe = function(glj,tproperty){
  844. return gljUtil.getTenderPriceCoe(glj,tproperty);
  845. };
  846. ProjectGLJ.prototype.isEstimateType = function(type){
  847. let typeString = type + "";
  848. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  849. return type;
  850. }
  851. return false;
  852. };
  853. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  854. let gljTypeMap = this.datas.constData.gljTypeMap;
  855. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  856. };
  857. ProjectGLJ.prototype.calcQuantity = function (init=false){
  858. let project_gljs = this.datas.gljList;
  859. let changeArray=[];
  860. let rationGLJDatas = projectObj.project.ration_glj.datas;
  861. let rationDatas = projectObj.project.Ration.datas;
  862. let billsDatas = projectObj.project.Bills.datas;
  863. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  864. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  865. this.quantityChangeMap = {};
  866. for(let pglj of project_gljs){
  867. this.quantityChangeMap[pglj.id] = pglj.quantity;
  868. }
  869. }else if(this.quantityChangeMap != null){
  870. for(let pglj of project_gljs){
  871. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  872. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  873. changeArray.push(pglj);
  874. this.quantityChangeMap[pglj.id] = pglj.quantity;
  875. }
  876. }else { //映射表没有,说明是新添加的项目工料机
  877. changeArray.push(pglj);
  878. this.quantityChangeMap[pglj.id] = pglj.quantity;
  879. }
  880. }
  881. }
  882. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  883. };
  884. ProjectGLJ.prototype.calcTenderQuantity = function (){
  885. let rationGLJDatas = projectObj.project.ration_glj.datas;
  886. let rationDatas = projectObj.project.Ration.datas;
  887. let billsDatas = projectObj.project.Bills.datas;
  888. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  889. };
  890. ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
  891. if(!datas) return;
  892. let gljIDMap = {};
  893. for (let d of datas){
  894. if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
  895. }
  896. if(datas.length > 0 && calquantity) this.calcQuantity();
  897. };
  898. ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新插入的项目工料机数据增加至缓存中
  899. if(!data) return;
  900. let project_gljs = this.datas.gljList;
  901. let unitPriceMap = this.datas.unitPriceMap;
  902. let mixRatioMap = this.datas.mixRatioMap;
  903. let mixRatioConnectData = this.datas.mixRatioConnectData;
  904. let IDMap = !_.isEmpty(tIDMap)?tIDMap:_.indexBy(project_gljs,'id');
  905. let tem = IDMap[data.id];
  906. if(tem) return; //判断该工料机是否已经存在,是的话不用再次添加
  907. //查看是否有组成物,有组成物的话先添加组成物信息
  908. data.ratio_data=[];
  909. if(data.subList && data.subList.length){
  910. for(let s of data.subList){
  911. let ratio = s.ratio_data;
  912. data.ratio_data.push(ratio);
  913. mixRatioMap[ratio.connect_key]?mixRatioMap[ratio.connect_key].push(ratio):mixRatioMap[ratio.connect_key] = [ratio];
  914. let rIndex = gljUtil.getIndex(ratio);
  915. mixRatioConnectData[rIndex]?mixRatioConnectData[rIndex].push(ratio.connect_key):mixRatioConnectData[rIndex] = [ratio.connect_key];
  916. this.loadNewProjectGLJToCache(s,IDMap);
  917. }
  918. delete data.subList;
  919. }
  920. //添加unitPriceMap
  921. let uIndex = gljUtil.getIndex(data.unit_price);
  922. if(!unitPriceMap[uIndex]) unitPriceMap[uIndex] = data.unit_price;
  923. this.datas.gljList.push(data);
  924. IDMap[data.id] = data;
  925. return data;
  926. };
  927. class EvaluateList {
  928. constructor (project) {
  929. this.project = project;
  930. this.datas = [];
  931. project.registerModule(ModuleNames.evaluate_list, this);
  932. };
  933. loadData (datas) {
  934. this.datas = datas;
  935. };
  936. }
  937. class BidEvaluationList {
  938. constructor (project) {
  939. this.project = project;
  940. this.datas = [];
  941. project.registerModule(ModuleNames.bid_evaluation_list, this);
  942. };
  943. loadData (datas) {
  944. this.datas = datas;
  945. };
  946. }
  947. class ContractorList {
  948. constructor (project) {
  949. this.project = project;
  950. this.datas = [];
  951. project.registerModule(ModuleNames.contractor_list, this);
  952. };
  953. loadData (datas) {
  954. this.datas = datas;
  955. };
  956. }