project_glj.js 39 KB

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