project_glj.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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.datas = response.data;
  45. self.calcQuantity();
  46. // 回调函数
  47. if (callback !== null) {
  48. callback(response.data);
  49. }
  50. // 存入缓存
  51. projectObj.project.projectGLJ = self;
  52. }
  53. });
  54. };
  55. ProjectGLJ.prototype.loadToCache = function (data) {
  56. this.datas = data;
  57. projectObj.project.projectGLJ = this;
  58. }
  59. /**
  60. * 获取对应工料机数据
  61. *
  62. * @param {String} code
  63. * @return {Object}
  64. */
  65. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  66. return _.find(this.datas.gljList, {'id': ID});
  67. };
  68. // CSL, 2018-02-08 甲供、甲定。
  69. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  70. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  71. // 所以这里要合并处理。
  72. let mixSupply = [];
  73. for (let s of supplyTypeArr){
  74. switch (s) {
  75. case 1:
  76. mixSupply.push('部分甲供');
  77. break;
  78. case 2:
  79. mixSupply.push('完全甲供');
  80. break;
  81. case 3:
  82. mixSupply.push('甲定乙供');
  83. break;
  84. default:
  85. mixSupply.push('自行采购');
  86. }
  87. };
  88. mixSupply = mixSupply.concat(supplyTypeArr);
  89. return _.filter(this.datas.gljList, function (glj) {
  90. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  91. });
  92. };
  93. ProjectGLJ.prototype.testGLJs = function () {
  94. let gljs = [];
  95. for (let glj of this.datas.gljList){
  96. let o = new Object();
  97. o.name = glj.name;
  98. o.supply = glj.supply;
  99. o.quantity = glj.quantity;
  100. o.supply_quantity = glj.supply_quantity;
  101. gljs.push(o);
  102. };
  103. return gljs;
  104. };
  105. /**
  106. * 修改工料机数据
  107. *
  108. * @param {Number} id
  109. * @param {Object} data
  110. * @return {boolean}
  111. */
  112. ProjectGLJ.prototype.updateData = function (id, data) {
  113. let result = false;
  114. if (this.datas === null) {
  115. return result;
  116. }
  117. let gljList = this.datas.gljList;
  118. if (gljList === undefined) {
  119. return result;
  120. }
  121. // 查找对应的index
  122. let index = -1;
  123. for (let tmp in gljList) {
  124. if (gljList[tmp].id === id) {
  125. index = tmp;
  126. break;
  127. }
  128. }
  129. if (index < 0) {
  130. return result;
  131. }
  132. // 修改数据
  133. for (let tmpIndex in data) {
  134. if (tmpIndex.indexOf('_price') >= 0) {
  135. // 修改unit_price中的对象
  136. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  137. } else {
  138. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  139. }
  140. }
  141. };
  142. /**
  143. * 加载缓存数据到spread
  144. *
  145. * @return {void}
  146. */
  147. ProjectGLJ.prototype.loadCacheData = function (resort) {
  148. // 加载工料机数据
  149. let data = this.datas === null ? null : this.datas;
  150. if (data === null) {
  151. return;
  152. }
  153. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  154. console.log("filter start");
  155. jsonData = filterProjectGLJ(jsonData);
  156. console.log("filter end");
  157. jsonData = sortProjectGLJ(jsonData);
  158. console.log("sort end");
  159. if(projectGLJSheet&&projectGLJSpread){
  160. setTimeout(spreadInit, 1);
  161. /*projectGLJSheet.setData(jsonData);
  162. projectGLJSpread.specialColumn(jsonData);*/
  163. }
  164. };
  165. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval) {
  166. if (updateField == 'marketPrice') {
  167. this.updatePrice(recode, "market_price", newval,"rg");
  168. }
  169. if (updateField == 'basePrice') {
  170. this.updatePrice(recode, "base_price", newval,"rg");
  171. }
  172. };
  173. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  174. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  175. projectObj.project.Ration.updateContain(newval,node);
  176. }if(updateField == "quantity"){
  177. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  178. } else {
  179. this.updateGLJProperty(node, updateField, newval);
  180. }
  181. };
  182. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  183. let rationTypeGLJ = node.data;
  184. let postData = {};
  185. if (rationTypeGLJ[updateField] == newval) {
  186. projectObj.mainController.refreshTreeNode([node]);
  187. return;
  188. }
  189. let data = {
  190. glj_id: rationTypeGLJ.GLJID,
  191. project_id: rationTypeGLJ.projectID,
  192. code: rationTypeGLJ.code,
  193. original_code: rationTypeGLJ.original_code,
  194. name: rationTypeGLJ.name,
  195. shortName: rationTypeGLJ.shortName,
  196. specs: rationTypeGLJ.specs,
  197. unit: rationTypeGLJ.unit,
  198. type: rationTypeGLJ.subType,
  199. type_of_work: rationTypeGLJ.subType,
  200. base_price: rationTypeGLJ.basePrice,
  201. market_price: rationTypeGLJ.basePrice,
  202. repositoryId: rationTypeGLJ.repositoryId,
  203. adjCoe: rationTypeGLJ.adjCoe,
  204. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  205. };
  206. if (updateField == 'subType') {
  207. data.type = newval;
  208. data.type_of_work = newval;
  209. data.shortName = this.getShortNameByID(newval);
  210. } else {
  211. data[updateField] = newval;
  212. }
  213. postData.ration = {
  214. ID: rationTypeGLJ.ID,
  215. projectID: rationTypeGLJ.projectID
  216. };
  217. postData.updateData = data;
  218. $.bootstrapLoading.start();
  219. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  220. console.log(result); //更新节点信息
  221. rationTypeGLJ[updateField] = newval;
  222. rationTypeGLJ.projectGLJID = result.id;
  223. rationTypeGLJ.code = result.code;
  224. rationTypeGLJ.basePrice = result.unit_price.base_price;
  225. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  226. rationTypeGLJ.isAdd = result.unit_price.is_add;
  227. rationTypeGLJ.isEstimate = result.is_evaluate;
  228. rationTypeGLJ.shortName = result.unit_price.short_name;
  229. //触发计算并更新节点信息
  230. node.changed = true;
  231. projectObj.project.projectGLJ.loadData(function () {
  232. projectObj.project.calcProgram.calcAndSave(node);
  233. $.bootstrapLoading.end();
  234. });//重新加载项目工料机数据
  235. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  236. }, function (err) {
  237. $.bootstrapLoading.end();
  238. });
  239. }
  240. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  241. let me = this;
  242. let projectGljs = this.datas.gljList;
  243. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  244. let glj = _.find(projectGljs, {'id': pgljID});
  245. if (glj) {
  246. if(glj.unit_price[updateField] == newval){
  247. return;
  248. }
  249. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id};
  250. let callback = function (data) {
  251. if (updateField == 'base_price') {
  252. glj.unit_price.base_price = newval;
  253. me.setAdjustPrice(glj);
  254. } else {
  255. glj.unit_price.market_price = newval;
  256. }
  257. //更新回传的父节点项目工料机价格
  258. let gljs = me.getProjectGLJs(data);
  259. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  260. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  261. gljOprObj.showRationGLJSheetData();
  262. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  263. gljs.push(glj);
  264. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  265. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  266. projectGljObject.onUnitFileChange(data);
  267. if(cb){
  268. cb(gljs);
  269. }
  270. $.bootstrapLoading.end();
  271. }
  272. $.bootstrapLoading.start();
  273. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  274. $.bootstrapLoading.end();
  275. });
  276. } else {
  277. gljOprObj.showRationGLJSheetData();
  278. }
  279. };
  280. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) {
  281. let me = this;
  282. let projectGljs = me.datas.gljList;
  283. let decimal = getDecimal('glj.unitPrice');
  284. let updateData = [];
  285. let newValueMap = {};
  286. let gljs=[];
  287. for(let ci of changeInfo){
  288. let dataCode = projectGljObject.projectGljSetting.header[ci.col].dataCode;
  289. let recode = projectGljObject.projectGljSheetData[ci.row];
  290. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  291. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  292. let newValue= scMathUtil.roundForObj(ci.value,decimal);
  293. let glj = _.find(projectGljs, {'id': recode.id});
  294. if(glj&&glj.unit_price[editField]!=newValue){
  295. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  296. newValueMap[glj.id]={field:editField,value:newValue};
  297. gljs.push(glj);
  298. }
  299. }
  300. }
  301. console.log(updateData);
  302. if(updateData.length > 0){
  303. $.bootstrapLoading.start();
  304. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  305. let parentData = [];
  306. //更新缓存
  307. for(let g of gljs){
  308. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  309. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  310. }
  311. //更新父工料机价格
  312. for(let r of result){
  313. let pdata = r.updateOne.filter;
  314. let set = r.updateOne.update.$set;
  315. for(let skey in set){
  316. pdata[skey] = set[skey];
  317. }
  318. parentData.push(pdata);
  319. }
  320. let pgljs = me.getProjectGLJs(parentData);
  321. gljs = gljs.concat(pgljs);
  322. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  323. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  324. gljOprObj.showRationGLJSheetData();
  325. projectGljObject.onUnitFileChange(gljs);
  326. if(callback){
  327. callback(gljs);
  328. }
  329. $.bootstrapLoading.end();
  330. }, function (err) {
  331. $.bootstrapLoading.end();
  332. });
  333. }
  334. };
  335. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  336. let me = this;
  337. $.bootstrapLoading.start();
  338. CommonAjax.specialPost( '/glj/update',data,function (result) {
  339. let glj = me.getByID(data.id);//更新缓存
  340. let impactList = [];
  341. glj[data.field] = data.value;
  342. if(data.extend&&data.extend!=""){
  343. let extend = JSON.parse(data.extend);
  344. for (let key in extend) {
  345. glj[key] = extend[key];
  346. }
  347. }
  348. if(data.field == 'is_evaluate'){
  349. impactList = me.changeIsEvaluate(data.id);
  350. }
  351. if(callback){
  352. callback(impactList);
  353. }
  354. $.bootstrapLoading.end();
  355. });
  356. };
  357. ProjectGLJ.prototype.getRatioData=function(id,callback){
  358. this.getRatioId = id;
  359. if(id){
  360. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  361. let ratios = JSON.parse(response.data);
  362. if(callback){
  363. callback(ratios);
  364. }
  365. },function () {//取不到组成物的情况
  366. callback([]);
  367. })
  368. }else {
  369. if(callback){
  370. callback([]);
  371. }
  372. }
  373. };
  374. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  375. $.bootstrapLoading.start();
  376. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  377. projectObj.project.projectGLJ.loadData(function () {
  378. if(callback){
  379. callback();
  380. }
  381. $.bootstrapLoading.end();
  382. });
  383. });
  384. };
  385. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  386. let gljList = [],allGLJ = gljOprObj.AllRecode;
  387. $("#glj_tree_div").modal('hide');
  388. if(selections.length == 0) {
  389. return;
  390. }
  391. for(let glj of allGLJ){
  392. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  393. if(_.includes(selections,i_key)){
  394. let pglj = {
  395. project_id: projectObj.project.ID(),
  396. glj_id: glj.ID,
  397. name: glj.name,
  398. code: glj.code,
  399. original_code: glj.code,
  400. unit: glj.unit,
  401. specs: glj.specs,
  402. base_price: glj.basePrice,
  403. market_price: glj.basePrice,
  404. shortName: glj.shortName,
  405. type: glj.gljType,
  406. adjCoe: glj.adjCoe,
  407. from:'std',
  408. repositoryId:glj.repositoryId,
  409. materialType:glj.materialType,
  410. materialCoe:glj.materialCoe,
  411. };
  412. if (glj.hasOwnProperty("compilationId")) {
  413. pglj.from = "cpt";
  414. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  415. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  416. }
  417. }
  418. gljList.push(pglj);
  419. }
  420. }
  421. gljList = _.sortByAll(gljList, ['type', 'code']);
  422. if(gljList.length == 0) return;
  423. let praentInfo = {
  424. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  425. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  426. };
  427. $.bootstrapLoading.start();
  428. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  429. $.bootstrapLoading.end();
  430. if(callback){
  431. callback(data);
  432. }
  433. }, function () {
  434. $.bootstrapLoading.end();
  435. });
  436. }
  437. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  438. let property = projectInfoObj.projectInfo.property;
  439. let data = {
  440. name:newVal,
  441. rootProjectID:property.rootProjectID
  442. }
  443. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  444. callback(data);
  445. });
  446. };
  447. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  448. $.bootstrapLoading.start();
  449. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  450. projectObj.project.projectGLJ.loadData(function () {
  451. if(callback){
  452. callback();
  453. }
  454. $.bootstrapLoading.end();
  455. });
  456. },function (response) {
  457. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  458. $("#save-as-tips").text(msg).show();
  459. $.bootstrapLoading.end();
  460. });
  461. };
  462. //更新是否暂估
  463. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  464. let projectGLJ = projectObj.project.projectGLJ;
  465. let datas = projectGLJ.datas;
  466. let gljList = datas.gljList;
  467. let glj = _.find(gljList, {'id': id});
  468. if(glj){
  469. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  470. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  471. let conditions = [];
  472. if(pratioM&&pratioM.length>0){
  473. for(let p_key of pratioM ){
  474. conditions.push(gljOprObj.getConditionByKey(p_key));
  475. }
  476. }
  477. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  478. gljs.push(glj);
  479. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  480. //更新对应的工料机类型的定额
  481. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  482. let ration_nodes = [];
  483. for(r of rations){
  484. if(r){
  485. r.isEstimate =glj.is_evaluate?1:0;
  486. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  487. ration_node?ration_nodes.push(ration_node):'';
  488. }
  489. }
  490. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  491. for(rg of ration_glj_nodes){
  492. rg.data.isEstimate =glj.is_evaluate?1:0;
  493. ration_nodes.push(rg);
  494. }
  495. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";
  496. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  497. return gljs;
  498. }
  499. }
  500. ProjectGLJ.prototype.getByID = function (ID) {
  501. return _.find(this.datas.gljList,{'id':ID});
  502. };
  503. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  504. return _.find(this.datas.gljList,function (item) {
  505. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  506. return tem_key == conkey
  507. })
  508. };
  509. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  510. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  511. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  512. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  513. tem.data.marketUnitFee = data.unit_price.market_price;
  514. return true;
  515. }
  516. })
  517. projectObj.mainController.refreshTreeNode(nodes);
  518. }
  519. }
  520. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  521. let nodes = [];
  522. if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  523. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  524. return tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == id
  525. })
  526. }
  527. return nodes;
  528. };
  529. //根据工料机,取得所有受影响的定额节点
  530. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  531. let nodes = [];
  532. let rationMap = {};
  533. let idArray = _.map(gljs,'id');
  534. let gljMap = _.indexBy(gljs,'id');
  535. //先根据项目工料机ID,找到受影响定额的ID
  536. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  537. for (let rg of ration_glj_list) {
  538. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  539. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  540. }
  541. }
  542. for (let item of projectObj.project.mainTree.items) {
  543. if (item.sourceType == ModuleNames.ration) {
  544. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  545. let tem_g = gljMap[item.data.projectGLJID];
  546. if(tem_g){
  547. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  548. nodes.push(item);
  549. }
  550. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  551. nodes.push(item)
  552. }
  553. }
  554. }
  555. return nodes;
  556. };
  557. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  558. for (let ration_glj of gljOprObj.sheetData) {
  559. if (ration_glj.projectGLJID == glj.id) {
  560. ration_glj.basePrice = glj.unit_price.base_price;
  561. ration_glj.marketPrice = glj.unit_price.market_price;
  562. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  563. }
  564. }
  565. }
  566. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  567. }
  568. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  569. let parentGlj = [];
  570. //
  571. let projectGljs = this.datas.gljList;
  572. let indexList = gljKeyArray;
  573. for (let d of data) {
  574. if (d) {
  575. let condition = {};
  576. for (let index of indexList) {
  577. if (d[index] != null && d[index] != undefined && d[index] != '') {
  578. condition[index] = d[index]
  579. }
  580. }
  581. let glj = _.find(projectGljs, condition);
  582. if (glj) {
  583. if(refreshPrice==true){
  584. d.base_price?glj.unit_price.base_price = d.base_price:'';
  585. d.market_price?glj.unit_price.market_price = d.market_price:'';
  586. this.setAdjustPrice(glj);
  587. this.refreshRationGLJPrice(glj);
  588. this.refreshTreeNodePriceIfNeed(glj);
  589. }
  590. parentGlj.push(glj);
  591. }
  592. }
  593. }
  594. return parentGlj;
  595. }
  596. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  597. switch (glj.unit_price.type + '') {
  598. // 人工: 调整基价=基价单价*调整系数
  599. case GLJTypeConst.LABOUR:
  600. case GLJTypeConst.MACHINE_LABOUR:
  601. glj.adjust_price = this.getAdjustPrice(glj);
  602. break;
  603. // 机械类型的算法
  604. case GLJTypeConst.MACHINE:
  605. console.log('机械');
  606. break;
  607. // 材料、主材、设备
  608. default:
  609. glj.adjust_price = glj.unit_price.base_price;
  610. }
  611. }
  612. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  613. let proGLJ = projectObj.project.projectGLJ;
  614. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  615. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  616. let labourCoeDatas = projectObj.project.labourCoe.datas;
  617. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  618. };
  619. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  620. let proGLJ = projectObj.project.projectGLJ;
  621. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  622. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  623. let labourCoeDatas = projectObj.project.labourCoe.datas;
  624. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  625. };
  626. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  627. let proGLJ = projectObj.project.projectGLJ;
  628. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  629. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  630. let labourCoeDatas = projectObj.project.labourCoe.datas;
  631. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  632. };
  633. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  634. let proGLJ = projectObj.project.projectGLJ;
  635. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  636. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  637. let labourCoeDatas = projectObj.project.labourCoe.datas;
  638. let tenderCoe = 1;
  639. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  640. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  641. }
  642. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  643. };
  644. ProjectGLJ.prototype.isEstimateType = function(type){
  645. let typeString = type + "";
  646. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  647. return type;
  648. }
  649. return false;
  650. };
  651. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  652. let gljTypeMap = this.datas.constData.gljTypeMap;
  653. return gljTypeMap["typeId" + ID].shortName;
  654. };
  655. ProjectGLJ.prototype.calcQuantity = function (init=false){
  656. let project_gljs = this.datas.gljList;
  657. let changeArray=[];
  658. let rationGLJDatas = projectObj.project.ration_glj.datas;
  659. let rationDatas = projectObj.project.Ration.datas;
  660. let billsDatas = projectObj.project.Bills.datas;
  661. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  662. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  663. this.quantityChangeMap = {};
  664. for(let pglj of project_gljs){
  665. this.quantityChangeMap[pglj.id] = pglj.quantity;
  666. }
  667. }else if(this.quantityChangeMap != null){
  668. for(let pglj of project_gljs){
  669. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  670. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  671. changeArray.push(pglj);
  672. this.quantityChangeMap[pglj.id] = pglj.quantity;
  673. }
  674. }else { //映射表没有,说明是新添加的项目工料机
  675. changeArray.push(pglj);
  676. this.quantityChangeMap[pglj.id] = pglj.quantity;
  677. }
  678. }
  679. }
  680. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  681. };
  682. ProjectGLJ.prototype.calcTenderQuantity = function (){
  683. let rationGLJDatas = projectObj.project.ration_glj.datas;
  684. let rationDatas = projectObj.project.Ration.datas;
  685. let billsDatas = projectObj.project.Bills.datas;
  686. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  687. };