project_glj.js 34 KB

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