project_glj.js 32 KB

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