project_glj.js 33 KB

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