project_glj.js 36 KB

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