project_glj.js 35 KB

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