project_glj.js 33 KB

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