project_glj.js 32 KB

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