project_glj.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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,callback) {
  166. if (updateField == 'marketPrice') {
  167. this.updatePrice(recode, "market_price", newval,"rg",callback);
  168. }
  169. if (updateField == 'basePrice') {
  170. this.updatePrice(recode, "base_price", newval,"rg",callback);
  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.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  241. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  242. return getDecimal("glj.unitPriceHasMix");
  243. }else {
  244. return getDecimal('glj.unitPrice');
  245. }
  246. };
  247. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
  248. let me = this;
  249. let projectGljs = this.datas.gljList;
  250. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  251. let glj = _.find(projectGljs, {'id': pgljID});
  252. if (glj) {
  253. if(glj.unit_price[updateField] == newval){
  254. return;
  255. }
  256. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  257. 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};
  258. let callback = function (data) {
  259. if (updateField == 'base_price') {
  260. glj.unit_price.base_price = newval;
  261. me.setAdjustPrice(glj);
  262. } else {
  263. glj.unit_price.market_price = newval;
  264. }
  265. //更新回传的父节点项目工料机价格
  266. let gljs = me.getProjectGLJs(data);
  267. // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
  268. projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
  269. gljOprObj.showRationGLJSheetData();
  270. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  271. gljs.push(glj);
  272. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  273. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  274. projectGljObject.onUnitFileChange(data);
  275. if(cb){
  276. cb(gljs);
  277. }
  278. $.bootstrapLoading.end();
  279. }
  280. $.bootstrapLoading.start();
  281. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  282. $.bootstrapLoading.end();
  283. });
  284. } else {
  285. gljOprObj.showRationGLJSheetData();
  286. }
  287. };
  288. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  289. let me = this;
  290. //更新是否暂估和供货方式时,要做特殊处理
  291. $.bootstrapLoading.start();
  292. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  293. $.bootstrapLoading.end();
  294. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  295. console.log(updateMap);
  296. for(let idKey in updateMap){
  297. let gljID = parseInt(idKey);
  298. let glj = me.getByID(gljID);
  299. let doc = updateMap[idKey];
  300. for(let property in doc){
  301. glj[property] = doc[property];
  302. }
  303. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  304. supplyChangeIDs.push(gljID);
  305. }
  306. if(doc.hasOwnProperty("is_evaluate")){
  307. evaluate_gljs.push(glj);
  308. }
  309. }
  310. if(supplyChangeIDs.length>0){
  311. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  312. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  313. }
  314. if(evaluate_gljs.length > 0){
  315. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  316. rationNodes = rationNodes.concat(impactRationNodes);
  317. }
  318. if(rationNodes.length > 0){
  319. rationNodes = _.uniq(rationNodes,'data');
  320. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  321. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  322. });
  323. }
  324. if(callback){
  325. callback();
  326. }
  327. })
  328. };
  329. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  330. let me = this;
  331. let projectGljs = me.datas.gljList;
  332. let updateData = [];
  333. let newValueMap = {};
  334. let gljs=[];
  335. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  336. if(changeInfo.length<=0){
  337. callback?callback():'';
  338. return
  339. }
  340. for(let ci of changeInfo){
  341. let dataCode = setting.header[ci.col].dataCode;
  342. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  343. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  344. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  345. let glj = _.find(projectGljs, {'id': recode.id});
  346. let newValue = ci.value;
  347. if(glj&&glj.unit_price[editField]!=newValue){
  348. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  349. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  350. newValueMap[glj.id]={field:editField,value:newValue};
  351. gljs.push(glj);
  352. }
  353. }
  354. }
  355. console.log(updateData);
  356. if(updateData.length > 0){
  357. $.bootstrapLoading.start();
  358. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  359. let parentData = [];
  360. //更新缓存
  361. for(let g of gljs){
  362. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  363. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  364. }
  365. //更新父工料机价格
  366. for(let r of result){
  367. let pdata = r.updateOne.filter;
  368. let set = r.updateOne.update.$set;
  369. for(let skey in set){
  370. pdata[skey] = set[skey];
  371. }
  372. parentData.push(pdata);
  373. }
  374. let pgljs = me.getProjectGLJs(parentData);
  375. gljs = gljs.concat(pgljs);
  376. let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  377. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  378. gljOprObj.showRationGLJSheetData();
  379. projectGljObject.onUnitFileChange(gljs);
  380. if(callback){
  381. callback(gljs);
  382. }
  383. $.bootstrapLoading.end();
  384. }, function (err) {
  385. $.bootstrapLoading.end();
  386. });
  387. }
  388. };
  389. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  390. let me = this;
  391. $.bootstrapLoading.start();
  392. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  393. let parent = updateData[updateData.length - 1];
  394. let parentGlj = me.getByConKey(parent.connect_key);
  395. for(let u of updateData){
  396. if(u.type == 'mix_ratio'){
  397. let tem = updateMap[u.query.id];
  398. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  399. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  400. if(subData){
  401. subData.consumption = u.doc.consumption;
  402. }
  403. let m_list = me.datas.mixRatioMap[parent.connect_key];
  404. let m_ratioData = _.find(m_list,{"id":u.query.id});
  405. if(m_ratioData){
  406. m_ratioData.consumption = u.doc.consumption;
  407. }
  408. }
  409. }
  410. parentGlj.unit_price.market_price = parent.market_price;
  411. parentGlj.unit_price.base_price = parent.base_price;
  412. me.calcQuantity();
  413. if(callback){
  414. callback();
  415. }
  416. $.bootstrapLoading.end();
  417. },function () {
  418. $.bootstrapLoading.end();
  419. })
  420. };
  421. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  422. let me = this;
  423. $.bootstrapLoading.start();
  424. CommonAjax.specialPost( '/glj/update',data,function (result) {
  425. let glj = me.getByID(data.id);//更新缓存
  426. let impactList = [];
  427. glj[data.field] = data.value;
  428. if(data.extend&&data.extend!=""){
  429. let extend = JSON.parse(data.extend);
  430. for (let key in extend) {
  431. glj[key] = extend[key];
  432. }
  433. }
  434. if(data.field == 'is_evaluate'){
  435. impactList = me.changeIsEvaluate(data.id);
  436. }
  437. if(callback){
  438. callback(impactList);
  439. }
  440. $.bootstrapLoading.end();
  441. });
  442. };
  443. ProjectGLJ.prototype.getRatioData=function(id,callback){
  444. this.getRatioId = id;
  445. if(id){
  446. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  447. let ratios = JSON.parse(response.data);
  448. if(callback){
  449. callback(ratios);
  450. }
  451. },function () {//取不到组成物的情况
  452. callback([]);
  453. })
  454. }else {
  455. if(callback){
  456. callback([]);
  457. }
  458. }
  459. };
  460. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  461. $.bootstrapLoading.start();
  462. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  463. projectObj.project.projectGLJ.loadData(function () {
  464. if(callback){
  465. callback();
  466. }
  467. $.bootstrapLoading.end();
  468. });
  469. }, function (err) {
  470. if($.bootstrapLoading.isLoading()){
  471. $.bootstrapLoading.end();
  472. }
  473. alert(err.msg);
  474. });
  475. };
  476. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  477. let gljList = [],allGLJ = gljOprObj.AllRecode;
  478. $("#glj_tree_div").modal('hide');
  479. if(selections.length == 0) {
  480. return;
  481. }
  482. for(let glj of allGLJ){
  483. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  484. if(_.includes(selections,i_key)){
  485. let pglj = {
  486. project_id: projectObj.project.ID(),
  487. glj_id: glj.ID,
  488. name: glj.name,
  489. code: glj.code,
  490. original_code: glj.code,
  491. unit: glj.unit,
  492. specs: glj.specs,
  493. base_price: glj.basePrice,
  494. market_price: glj.basePrice,
  495. shortName: glj.shortName,
  496. type: glj.gljType,
  497. model:glj.model,
  498. adjCoe: glj.adjCoe,
  499. from:'std',
  500. repositoryId:glj.repositoryId,
  501. materialType:glj.materialType,
  502. materialCoe:glj.materialCoe,
  503. };
  504. if (glj.hasOwnProperty("compilationId")) {
  505. pglj.from = "cpt";
  506. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  507. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  508. }
  509. }
  510. gljList.push(pglj);
  511. }
  512. }
  513. gljList = _.sortByAll(gljList, ['type', 'code']);
  514. if(gljList.length == 0) return;
  515. let praentInfo = {
  516. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  517. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  518. };
  519. $.bootstrapLoading.start();
  520. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  521. $.bootstrapLoading.end();
  522. if(callback){
  523. callback(data);
  524. }
  525. }, function () {
  526. $.bootstrapLoading.end();
  527. });
  528. }
  529. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  530. let property = projectInfoObj.projectInfo.property;
  531. let data = {
  532. name:newVal,
  533. rootProjectID:property.rootProjectID
  534. }
  535. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  536. callback(data);
  537. });
  538. };
  539. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  540. $.bootstrapLoading.start();
  541. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  542. projectObj.project.projectGLJ.loadData(function () {
  543. if(callback){
  544. callback();
  545. }
  546. $.bootstrapLoading.end();
  547. });
  548. },function (response) {
  549. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  550. $("#save-as-tips").text(msg).show();
  551. $.bootstrapLoading.end();
  552. });
  553. };
  554. //更新是否暂估
  555. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  556. let projectGLJ = projectObj.project.projectGLJ;
  557. let datas = projectGLJ.datas;
  558. let gljList = datas.gljList;
  559. let glj = _.find(gljList, {'id': id});
  560. if(glj){//与批量更新调用相同的方法
  561. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  562. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  563. let conditions = [];
  564. if(pratioM&&pratioM.length>0){
  565. for(let p_key of pratioM ){
  566. conditions.push(gljOprObj.getConditionByKey(p_key));
  567. }
  568. }
  569. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  570. gljs.push(glj);
  571. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  572. //更新对应的工料机类型的定额
  573. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  574. let ration_nodes = [];
  575. for(r of rations){
  576. if(r){
  577. r.isEstimate =glj.is_evaluate?1:0;
  578. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  579. ration_node?ration_nodes.push(ration_node):'';
  580. }
  581. }
  582. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  583. for(rg of ration_glj_nodes){
  584. rg.data.isEstimate =glj.is_evaluate?1:0;
  585. ration_nodes.push(rg);
  586. }
  587. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  588. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  589. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  590. return gljs;
  591. }
  592. };
  593. /**
  594. * 批量更新是否暂估
  595. *传入项目工料机数组
  596. */
  597. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  598. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  599. for(let glj of gljs){
  600. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  601. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  602. let conditions = [];
  603. if(pratioM&&pratioM.length>0){
  604. for(let p_key of pratioM ){
  605. conditions.push(gljOprObj.getConditionByKey(p_key));
  606. }
  607. }
  608. let tem_gljs = this.getProjectGLJs(conditions,false);
  609. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  610. }
  611. impactGLJs = impactGLJs.concat(gljs);
  612. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  613. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  614. let neeRefreshNode = [];
  615. //更新对应的工料机类型的定额
  616. for(let item of projectObj.project.Ration.datas){
  617. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  618. let tem_g = changeMap[item.projectGLJID];
  619. item.isEstimate =tem_g.is_evaluate?1:0;
  620. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  621. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  622. }
  623. }
  624. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  625. for(let rg of ration_glj_nodes){
  626. let tem_g = changeMap[rg.data.projectGLJID];
  627. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  628. neeRefreshNode.push(rg);
  629. }
  630. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  631. return [impactRationNodes,impactGLJs];
  632. };
  633. ProjectGLJ.prototype.getByID = function (ID) {
  634. return _.find(this.datas.gljList,{'id':ID});
  635. };
  636. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  637. return _.find(this.datas.gljList,function (item) {
  638. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  639. return tem_key == conkey
  640. })
  641. };
  642. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  643. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  644. let me = this;
  645. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  646. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  647. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  648. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  649. return true;
  650. }
  651. })
  652. projectObj.mainController.refreshTreeNode(nodes);
  653. }
  654. }
  655. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  656. let nodes = [];
  657. let ids = [];
  658. if(Array.isArray(id)){
  659. ids = id;
  660. }else {
  661. ids = [id];
  662. }
  663. if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  664. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  665. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  666. })
  667. }
  668. return nodes;
  669. };
  670. //根据工料机,取得所有受影响的定额节点
  671. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  672. let nodes = [];
  673. let rationMap = {};
  674. let idArray = _.map(gljs,'id');
  675. let gljMap = _.indexBy(gljs,'id');
  676. //先根据项目工料机ID,找到受影响定额的ID
  677. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  678. for (let rg of ration_glj_list) {
  679. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  680. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  681. }
  682. }
  683. for (let item of projectObj.project.mainTree.items) {
  684. if (item.sourceType == ModuleNames.ration) {
  685. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  686. let tem_g = gljMap[item.data.projectGLJID];
  687. if(tem_g){
  688. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  689. item.data.marketPrice = this.getMarketPrice(tem_g);
  690. nodes.push(item);
  691. }
  692. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  693. nodes.push(item)
  694. }
  695. }
  696. }
  697. return nodes;
  698. };
  699. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  700. for (let ration_glj of gljOprObj.sheetData) {
  701. if (ration_glj.projectGLJID == glj.id) {
  702. ration_glj.basePrice = this.getBasePrice(glj);
  703. ration_glj.marketPrice = this.getMarketPrice(glj);
  704. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  705. }
  706. }
  707. }
  708. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  709. }
  710. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  711. let parentGlj = [];
  712. //
  713. let projectGljs = this.datas.gljList;
  714. let indexList = gljKeyArray;
  715. for (let d of data) {
  716. if (d) {
  717. let glj = _.find(projectGljs, function (item) {
  718. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  719. });
  720. if (glj) {
  721. if(refreshPrice==true){
  722. d.base_price?glj.unit_price.base_price = d.base_price:'';
  723. d.market_price?glj.unit_price.market_price = d.market_price:'';
  724. this.setAdjustPrice(glj);
  725. this.refreshRationGLJPrice(glj);
  726. this.refreshTreeNodePriceIfNeed(glj);
  727. }
  728. parentGlj.push(glj);
  729. }
  730. }
  731. }
  732. return parentGlj;
  733. }
  734. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  735. switch (glj.unit_price.type + '') {
  736. // 人工: 调整基价=基价单价*调整系数
  737. case GLJTypeConst.LABOUR:
  738. case GLJTypeConst.MACHINE_LABOUR:
  739. glj.adjust_price = this.getAdjustPrice(glj);
  740. break;
  741. // 机械类型的算法
  742. case GLJTypeConst.MACHINE:
  743. console.log('机械');
  744. break;
  745. // 材料、主材、设备
  746. default:
  747. glj.adjust_price = glj.unit_price.base_price;
  748. }
  749. }
  750. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  751. let proGLJ = projectObj.project.projectGLJ;
  752. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  753. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  754. let labourCoeDatas = projectObj.project.labourCoe.datas;
  755. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  756. };
  757. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  758. let proGLJ = projectObj.project.projectGLJ;
  759. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  760. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  761. let labourCoeDatas = projectObj.project.labourCoe.datas;
  762. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  763. };
  764. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  765. let proGLJ = projectObj.project.projectGLJ;
  766. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  767. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  768. let labourCoeDatas = projectObj.project.labourCoe.datas;
  769. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  770. };
  771. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  772. let proGLJ = projectObj.project.projectGLJ;
  773. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  774. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  775. let labourCoeDatas = projectObj.project.labourCoe.datas;
  776. let tenderCoe = 1;
  777. if (projectObj.project.property.tenderSetting && gljUtil.isDef(projectObj.project.property.tenderSetting.gljPriceTenderCoe) ){
  778. tenderCoe = parseFloat(projectObj.project.property.tenderSetting.gljPriceTenderCoe);
  779. }
  780. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  781. };
  782. ProjectGLJ.prototype.isEstimateType = function(type){
  783. let typeString = type + "";
  784. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  785. return type;
  786. }
  787. return false;
  788. };
  789. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  790. let gljTypeMap = this.datas.constData.gljTypeMap;
  791. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  792. };
  793. ProjectGLJ.prototype.calcQuantity = function (init=false){
  794. let project_gljs = this.datas.gljList;
  795. let changeArray=[];
  796. let rationGLJDatas = projectObj.project.ration_glj.datas;
  797. let rationDatas = projectObj.project.Ration.datas;
  798. let billsDatas = projectObj.project.Bills.datas;
  799. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  800. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  801. this.quantityChangeMap = {};
  802. for(let pglj of project_gljs){
  803. this.quantityChangeMap[pglj.id] = pglj.quantity;
  804. }
  805. }else if(this.quantityChangeMap != null){
  806. for(let pglj of project_gljs){
  807. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  808. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  809. changeArray.push(pglj);
  810. this.quantityChangeMap[pglj.id] = pglj.quantity;
  811. }
  812. }else { //映射表没有,说明是新添加的项目工料机
  813. changeArray.push(pglj);
  814. this.quantityChangeMap[pglj.id] = pglj.quantity;
  815. }
  816. }
  817. }
  818. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  819. };
  820. ProjectGLJ.prototype.calcTenderQuantity = function (){
  821. let rationGLJDatas = projectObj.project.ration_glj.datas;
  822. let rationDatas = projectObj.project.Ration.datas;
  823. let billsDatas = projectObj.project.Bills.datas;
  824. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  825. };