ration_glj.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. let ration_glj = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. let tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. let ration_glj = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. let sourceType = ModuleNames.ration_glj;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.ration_glj, this);
  18. };
  19. // 从后台获取数据
  20. /*glj.prototype.pullData = function (){
  21. this.project.pullData(
  22. '/glj/getData',
  23. {projectID: this.project.ID},
  24. function(result){
  25. if (result.error ===0){
  26. this.loadDatas(result.data);
  27. }
  28. else {
  29. // to do: 错误处理需要细化
  30. alert(result.message);
  31. }
  32. },
  33. function (){}//to do: 错误处理需要细化
  34. )
  35. };*/
  36. // prototype用于定义public方法
  37. ration_glj.prototype.loadData = function (datas) {
  38. this.datas = datas;
  39. };
  40. ration_glj.prototype.getGLJListByRationID = function (rationID) {
  41. return _.filter(this.datas, {'rationID': rationID})
  42. };
  43. ration_glj.prototype.getGatherGljArrByRations = function (rations, needOneBill, billQuantity) {
  44. let result = [];
  45. let clone = function (obj) {
  46. if (obj === null) return null;
  47. let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  48. for (let i in obj) {
  49. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
  50. }
  51. return o;
  52. }
  53. let findGlj = function (sourceGlj, gljArr) {
  54. for (let glj of gljArr) {
  55. if (glj.projectGLJID === sourceGlj.projectGLJID) {
  56. return glj;
  57. }
  58. }
  59. return null;
  60. }
  61. for (let ration of rations) {
  62. if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
  63. let glj = JSON.parse(JSON.stringify(ration));
  64. glj.type = glj.subType;
  65. glj.totalQuantity = parseFloatPlus(ration.quantity);
  66. glj.markertPrice = glj.marketUnitFee;
  67. glj.basePrice = glj.marketUnitFee;
  68. glj.adjustPrice = glj.marketUnitFee;
  69. result.push(glj);
  70. }
  71. else{
  72. let rationGljs = projectObj.project.calcProgram.getGljArrByRation(ration);
  73. for (let glj of rationGljs) {
  74. let sameGlj = findGlj(glj, result);
  75. if (!sameGlj) {
  76. sameGlj = clone(glj);
  77. sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
  78. result.push(sameGlj);
  79. } else {
  80. sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
  81. sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
  82. }
  83. }
  84. }
  85. }
  86. result = gljOprObj.combineWithProjectGlj(result);
  87. if (!needOneBill) return result;
  88. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  89. let oneBill = JSON.parse(JSON.stringify(result));
  90. for (let glj of oneBill){
  91. if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
  92. glj.type = glj.subType;
  93. glj.basePrice = glj.marketUnitFee;
  94. glj.marketPrice = glj.marketUnitFee;
  95. glj.adjustPrice = glj.marketUnitFee;
  96. }
  97. else if (glj.type == rationType.gljRation){
  98. glj.type = glj.subType;
  99. };
  100. // glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  101. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.process); // 广联达这里没有取舍
  102. };
  103. return oneBill;
  104. }
  105. // 提交数据后返回数据处理
  106. ration_glj.prototype.doAfterUpdate = function (err, data) {
  107. let me = this;
  108. if (!err) {
  109. if (data.updateTpye == 'ut_update') {
  110. me.refreshAfterUpdate(data);
  111. } else if (data.updateTpye == 'ut_delete') {
  112. me.refreshAfterDelete(data);
  113. } else {
  114. me.refreshAfterSave(data);
  115. }
  116. }
  117. projectObj.project.projectGLJ.loadData();
  118. };
  119. ration_glj.prototype.getDataByID = function (ID) {
  120. return _.find(this.datas,{'ID':ID});
  121. };
  122. ration_glj.prototype.refreshAfterSave = function (data) {
  123. let me = projectObj.project.ration_glj;
  124. let neRecodes = [];
  125. if (data) {
  126. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  127. neRecodes = data.showDatas;
  128. gljOprObj.sheetData = neRecodes;
  129. me.addDatasToList(neRecodes);
  130. }
  131. project.projectGLJ.loadData(function () {
  132. gljOprObj.showRationGLJSheetData(true);
  133. //add to mainTree;
  134. me.addToMainTree(neRecodes);
  135. let rationID = neRecodes[0].rationID;
  136. let node = project.mainTree.nodes['id_' + rationID];
  137. if(isDef(node)){
  138. project.calcProgram.calcAndSave(node);
  139. }
  140. if (activeSubSheetIsCalcProgram())
  141. calcProgramObj.refreshCalcProgram(node, 1);
  142. });
  143. };
  144. ration_glj.prototype.getGljByRationID = function(rationID){
  145. return _.filter(this.datas, {'rationID': rationID});
  146. };
  147. ration_glj.prototype.addDatasToList = function (datas) {
  148. let me = projectObj.project.ration_glj;
  149. if(datas&&datas.length>0){
  150. if (me.datas && Array.isArray(me.datas)) {
  151. me.datas = me.datas.concat(datas);
  152. } else {
  153. me.datas = datas;
  154. }
  155. }
  156. };
  157. ration_glj.prototype.updateGLJNodeAfterReplace = function(data){
  158. if (this.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  159. var node = this.findGLJNodeByID(data.ID);
  160. if (node) {
  161. this.transferToNodeData(data);
  162. node.source = data;
  163. node.data = data;
  164. }
  165. return node;
  166. }
  167. };
  168. ration_glj.prototype.addToMainTree = function (datas) {
  169. datas = gljUtil.sortRationGLJ(datas);
  170. for (let data of datas) {
  171. if (this.needShowToTree(data)) {
  172. gljOprObj.setGLJPrice(data);
  173. this.transferToNodeData(data);
  174. let parentNode = projectObj.project.mainTree.findNode(data.rationID);
  175. if (parentNode) {
  176. let nextNodeID = null;
  177. if (parentNode.children.length > 0) {
  178. for (let br of parentNode.children) {
  179. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  180. nextNodeID = br.getID();
  181. }
  182. }
  183. }
  184. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  185. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  186. newNode.source = data;
  187. newNode.sourceType = this.getSourceType();
  188. newNode.data = data;
  189. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  190. }
  191. }
  192. }
  193. };
  194. ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
  195. let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
  196. let deleteNodes = [];
  197. for(let rg of glj_list){
  198. if(this.needShowToTree(rg)){
  199. let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
  200. deleteNodes.push(r_node);
  201. }
  202. }
  203. if(deleteNodes.length > 0){
  204. let rowIndex = deleteNodes[0].serialNo();
  205. if(controller.tree.m_delete(deleteNodes)){
  206. TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
  207. let rowCount = deleteNodes.length;
  208. controller.sheet.deleteRows(rowIndex, rowCount);
  209. });
  210. }
  211. }
  212. };
  213. ration_glj.prototype.refreshAfterUpdate = function (data) {
  214. let me = this;
  215. let rationID= me.updateCacheAfterAdjust(data);
  216. gljOprObj.showRationGLJSheetData(true);
  217. this.reCalcWhenGLJChange({rationID:rationID});
  218. };
  219. ration_glj.prototype.updateCacheAfterAdjust=function (data) {
  220. let me = this;
  221. let rationID=null;
  222. if (data.quantityRefresh) {
  223. data.glj_result.forEach(function (item) {
  224. rationID = me.refreshEachItme(item.doc, item.query);
  225. })
  226. } else {
  227. rationID = me.refreshEachItme(data.doc, data.query);
  228. }
  229. return rationID;
  230. };
  231. ration_glj.prototype.refreshEachItme = function (doc, query) {
  232. let glj = this.refreshByID(query.ID,doc);
  233. return glj.rationID;
  234. };
  235. ration_glj.prototype.refreshByID=function (ID,doc) {
  236. let glj_list = projectObj.project.ration_glj.datas;
  237. let glj_index = _.findIndex(glj_list,{"ID":ID});
  238. _.forEach(doc, function (n, key) {
  239. glj_list[glj_index][key] = n;
  240. });
  241. return glj_list[glj_index]
  242. };
  243. ration_glj.prototype.refreshAfterDelete = function (data) {
  244. let me = projectObj.project.ration_glj;
  245. let glj_list = me.datas;
  246. let oldData = _.remove(glj_list, data.query);
  247. _.remove(gljOprObj.sheetData, data.query);
  248. gljOprObj.showRationGLJSheetData();
  249. projectObj.project.projectGLJ.loadData();
  250. let rationNode = null;
  251. let next = null;
  252. let selected = projectObj.project.mainTree.selected;
  253. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  254. rationNode = selected;
  255. } else if (selected.sourceType == ModuleNames.ration_glj) {
  256. rationNode = selected.parent;
  257. next = true;
  258. }
  259. rationNode.data.adjustState = data.adjustState;
  260. projectObj.mainController.refreshTreeNode([rationNode]);
  261. for (let o of oldData) {
  262. if (this.needShowToTree(o)) {
  263. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  264. projectObj.mainController.deleteNode(node, next);
  265. }
  266. }
  267. project.calcProgram.calcAndSave(rationNode,async function () {
  268. installationFeeObj.calcInstallationFee();
  269. await OVER_HEIGHT.reCalcOverHeightFee();
  270. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([rationNode.parent]);
  271. });
  272. };
  273. // CSL,2017.05.09
  274. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  275. this.project.beginUpdate('modifyQuantity');
  276. data.quantity = newQuantity;
  277. data.customQuantity = newQuantity;
  278. data.updateType = 'ut_update';
  279. this.project.push(this.getSourceType, data);
  280. this.project.endUpdate();
  281. };
  282. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  283. this.project.beginUpdate('modifyPrice');
  284. data.price = newPrice;
  285. data.updateType = 'ut_update';
  286. this.project.push(this.getSourceType, data);
  287. this.project.endUpdate();
  288. };
  289. ration_glj.prototype.deleteGLJ = function (data) {
  290. this.project.beginUpdate('deleteGLJ');
  291. data.customQuantity = 0;
  292. data.quantity = 0;
  293. data.rationItemQuantity = 0;
  294. data.updateType = 'ut_update';
  295. this.project.push(this.getSourceType, data);
  296. this.project.endUpdate();
  297. };
  298. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  299. let souceTypeList = [];
  300. let criteriaDataList = [];
  301. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  302. let criteria = {};
  303. criteria.ration_glj_list = [];
  304. for (let i = 0; i < data.rationGljList.length; i++) {
  305. let temdata = data.rationGljList[i];
  306. let newGLJ = {};
  307. newGLJ.projectID = parseInt(newRation.projectID);
  308. newGLJ.GLJID = temdata.gljId;
  309. newGLJ.rationID = newRation.ID;
  310. newGLJ.billsItemID = newRation.billsItemID;
  311. newGLJ.rationItemQuantity = temdata.consumeAmt;
  312. newGLJ.quantity = temdata.consumeAmt;
  313. newGLJ.glj_repository_id = data.rationRepId;
  314. criteria.ration_glj_list.push(newGLJ);
  315. }
  316. criteria.updateType = 'ut_create';
  317. souceTypeList.push(this.getSourceType());
  318. criteriaDataList.push(criteria);
  319. }
  320. let ration_coe = projectObj.project.ration_coe;
  321. let rationCoeData = ration_coe.getRationCoedata(newRation, data);
  322. souceTypeList.push(ration_coe.getSourceType());
  323. criteriaDataList.push(rationCoeData);
  324. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  325. };
  326. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  327. let updateData = [];
  328. updateData.push({
  329. 'deleteType': 'RATION',
  330. 'updateType': 'ut_delete',
  331. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  332. });
  333. return updateData;
  334. };
  335. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  336. let updateData = [];
  337. datas.forEach(function (deleteData) {
  338. if (deleteData.type == 'delete') {
  339. let billData = deleteData.data;
  340. updateData.push({
  341. 'deleteType': 'BILL',
  342. 'updateType': 'ut_delete',
  343. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  344. });
  345. }
  346. })
  347. return updateData;
  348. };
  349. ration_glj.prototype.deleteByRation = function (ration) {
  350. let glj_list = projectObj.project.ration_glj.datas;
  351. _.remove(glj_list,{'rationID':ration.ID});
  352. };
  353. ration_glj.prototype.deleteByBills = function (deleteData) {
  354. let rationList = projectObj.project.Ration.datas;
  355. let deleteRationList = [];
  356. for (let i = 0; i < deleteData.length; i++) {
  357. if (deleteData[i].type == 'delete') {
  358. let billID = deleteData[i].data.ID;
  359. let raList = _.filter(rationList, (ration) => {
  360. return ration.billsItemID == billID;
  361. });
  362. deleteRationList = deleteRationList.concat(raList);
  363. }
  364. }
  365. for (let i = 0; i < deleteRationList.length; i++) {
  366. this.deleteByRation(deleteRationList[i]);
  367. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  368. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  369. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  370. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  371. }
  372. }
  373. ration_glj.prototype.updataOrdelete = function (row) {
  374. let updateData = null;
  375. if (row.rationItemQuantity == 0) {
  376. updateData = this.getUpdateData('ut_delete', {
  377. 'ID': row.ID,
  378. 'projectID': row.projectID
  379. }, {rationID: row.rationID});
  380. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  381. } else {
  382. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  383. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  384. }
  385. };
  386. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  387. let updateData = [];
  388. let newobj = {
  389. 'updateType': type,
  390. 'query': query,
  391. }
  392. if (doc) {
  393. newobj['doc'] = doc;
  394. }
  395. if (callfunction) {
  396. newobj['updateFunction'] = callfunction;
  397. }
  398. updateData.push(newobj);
  399. return updateData;
  400. };
  401. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  402. let me = this,doc = {};
  403. doc[updateField] = newval;
  404. me.submitChange(recode,doc,updateField,node);
  405. };
  406. ration_glj.prototype.submitChange = function(recode,updateData,updateField,node){
  407. let me = this;
  408. let query = {
  409. 'ID': recode.ID,
  410. 'projectID': recode.projectID,
  411. 'rationID': recode.rationID
  412. };
  413. let priceInfo = {
  414. base_price: recode.basePrice,
  415. market_price: recode.marketPrice
  416. };
  417. if(updateData['type'] != undefined || updateData['type'] != null){
  418. updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
  419. }
  420. let callback = function (data) {
  421. if (updateField == 'customQuantity') {
  422. me.refreshAfterQuantityUpdate(data, node);
  423. } else {
  424. let doc = data.doc;
  425. for (let key in doc) {
  426. recode[key] = doc[key];
  427. }
  428. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  429. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  430. if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  431. projectObj.mainController.deleteNode(node, true);
  432. }
  433. }
  434. }
  435. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  436. gljOprObj.refreshView();
  437. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  438. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  439. $.bootstrapLoading.end();
  440. installationFeeObj.calcInstallationFee();
  441. // OVER_HEIGHT.reCalcOverHeightFee();
  442. });
  443. };
  444. $.bootstrapLoading.start();
  445. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  446. query: query,
  447. doc: updateData,
  448. priceInfo: priceInfo
  449. }, callback, function (err) {
  450. $.bootstrapLoading.end();
  451. });
  452. };
  453. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  454. let me = this;
  455. data.glj_result.forEach(function (item) {
  456. me.refreshEachItme(item.doc, item.query);
  457. });
  458. me.refreshRationAfterEdit(data, data.rationID, node);
  459. };
  460. ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
  461. let nodes = [];
  462. let node = this.refreshRationNode(data.name,data.adjustState,rationID);
  463. if (node) nodes.push(node);
  464. if (rnode) nodes.push(rnode);
  465. projectObj.mainController.refreshTreeNode(nodes);
  466. };
  467. ration_glj.prototype.refreshRationNode = function(name,adjustState,rationID){
  468. let node = projectObj.project.mainTree.findNode(rationID);
  469. if (!node) return null;
  470. if(gljUtil.isDef(adjustState)){
  471. node.data.adjustState = adjustState;
  472. }
  473. if(gljUtil.isDef(name)){
  474. node.data.name = name;
  475. }
  476. return node
  477. };
  478. ration_glj.prototype.getGLJDataPaging = function (condition, cb) {
  479. gljOprObj.loadingPagination = true;
  480. const property = projectObj.project.projectInfo.property;
  481. const engineerID = property.engineering_id;
  482. const actionType = $('#actionType').val();
  483. CommonAjax.post('/rationGlj/getGLJDataPaging', {engineerID, condition}, function (data) {
  484. gljOprObj.curPageTotal = data.total;
  485. data.complementaryGLJs.forEach(glj => {
  486. glj.isComplementary = true;
  487. });
  488. const gljType = condition.type === gljOprObj.pagingType.stdGLJ
  489. ? 'stdGLJ'
  490. : 'complementaryGLJs';
  491. const newData = data[gljType];
  492. // 添加组成物,类型为主材时,需要排除自身
  493. if (actionType === 'addMix' && projectGljObject.selectedProjectGLJ.type === gljType.MAIN_MATERIAL) {
  494. const pIndex = gljOprObj.getIndex(projectGljObject.selectedProjectGLJ, gljKeyArray);
  495. const delIndex = newData.findIndex(item => gljOprObj.getIndex(item, gljLibKeyArray) === pIndex);
  496. if (!~delIndex) {
  497. newData.splice(delIndex, 1);
  498. }
  499. }
  500. if (condition.init) {
  501. gljOprObj.treeData = data.treeData;
  502. gljOprObj.distTypeTree = gljOprObj.getComboData(data.distTypeTree);
  503. }
  504. // 需要重置当前页面数据(点击了分类树、搜索等等)
  505. if (condition.reset) {
  506. gljOprObj.stdGLJ = data.stdGLJ;
  507. gljOprObj.complementaryGLJs = data.complementaryGLJs;
  508. gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];
  509. } else {
  510. gljOprObj[gljType].splice(condition.index, 0, ...newData);
  511. gljOprObj.AllRecode.splice(condition.index, 0, ...newData);
  512. }
  513. // 根据缓存选中数据,设置人材机是否选中
  514. newData.forEach(item => {
  515. const connectKey = gljOprObj.getIndex(item, gljLibKeyArray);
  516. if (gljOprObj.GLJSelection.includes(connectKey)) {
  517. item.select = 1;
  518. }
  519. });
  520. // 设置人材机类型名称
  521. gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, newData);
  522. if (data.priceProperties && data.priceProperties.length > 0) {
  523. let tmp = _.find(data.priceProperties, {region: property.region, taxModel: parseInt(property.taxType)});
  524. if (tmp) {
  525. let dataCode = tmp.price.dataCode;
  526. for (let glj of data.stdGLJ) {
  527. if (glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) {
  528. glj.basePrice = glj.priceProperty[dataCode];
  529. }
  530. }
  531. }
  532. }
  533. cb(data[gljType]);
  534. gljOprObj.loadingPagination = false;
  535. }, function () {
  536. if ($.bootstrapLoading.isLoading()) {
  537. $.bootstrapLoading.end();
  538. }
  539. });
  540. };
  541. ration_glj.prototype.getGLJData = function (cb) {
  542. let property = projectObj.project.projectInfo.property;
  543. let engineerID = property.engineering_id;
  544. CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
  545. //编办中有多单价设置
  546. if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
  547. let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});
  548. if(tem){
  549. let dataCode = tem.price.dataCode;
  550. for(let glj of data.datas.stdGLJ){
  551. if(glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) glj.basePrice = glj.priceProperty[dataCode];
  552. }
  553. }
  554. };
  555. cb(data);
  556. })
  557. };
  558. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  559. let gljList = [];
  560. let allGLJ = gljOprObj.AllRecode;
  561. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  562. let pEngineer = projectObj.project.projectInfo.property.projectEngineering;
  563. let children = [];
  564. if (selected.sourceType === project.Bills.getSourceType()) {
  565. billsItemID = selected.data.ID;
  566. parentNodeID = selected.getID();
  567. nextNodeID = selected.tree.rootID();
  568. billNode = selected;
  569. } else {
  570. billsItemID = selected.data.billsItemID;
  571. serialNo = selected.data.serialNo;
  572. selectedSerialNo = selected.data.serialNo;
  573. nextNodeID = selected.getNextSiblingID();
  574. parentNodeID = selected.getParentID();
  575. billNode = selected.parent;
  576. }
  577. children = project.Ration.getBillsSortRation(billsItemID);
  578. serialNo == 0 ? serialNo = children.length : "";
  579. for (let con_key of GLJSelection) {
  580. let glj = _.find(allGLJ, function (item) {
  581. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  582. return i_key == con_key;
  583. });
  584. if (glj) {
  585. serialNo += 1;
  586. let new_glj = {
  587. ID: project.Ration.getNewRationID(),
  588. projectID: parseInt(project.ID()),
  589. billsItemID: billsItemID,
  590. type: rationType.gljRation,
  591. code: glj.code,
  592. name: glj.name,
  593. quantity: 0,
  594. unit: glj.unit,
  595. specs: glj.specs,
  596. subType: glj.gljType,
  597. model:glj.model,
  598. basePrice: glj.basePrice,
  599. marketPrice:glj.basePrice,
  600. original_code: glj.code,
  601. shortName: glj.shortName,
  602. serialNo: serialNo,
  603. GLJID: glj.ID,
  604. adjCoe: glj.adjCoe,
  605. materialType:glj.materialType,
  606. materialCoe:glj.materialCoe,
  607. materialIndexType:glj.materialIndexType,
  608. materialIndexUnit:glj.materialIndexUnit,
  609. materialIndexCoe:glj.materialIndexCoe,
  610. repositoryId: glj.repositoryId
  611. };
  612. if(pEngineer) new_glj.programID = pEngineer;
  613. if (glj.hasOwnProperty("compilationId")) {
  614. new_glj.from = "cpt";
  615. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  616. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  617. }
  618. }
  619. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  620. new_glj.quantityEXP="QDL";
  621. if(billNode.data.quantity){
  622. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  623. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  624. }
  625. }
  626. gljList.push(new_glj);
  627. }
  628. }
  629. if (gljList.length == 0) {
  630. return;
  631. }
  632. let postData = {
  633. gljList: gljList,
  634. projectID: parseInt(project.ID()),
  635. billsItemID: billsItemID,
  636. rationCount: project.Ration.maxRationID()
  637. }
  638. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  639. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  640. // 更新兄弟节点的序列号
  641. if (selectedSerialNo != null) {
  642. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  643. if (selectIndex + 1 < children.length) {
  644. for (let i = selectIndex + 1; i < children.length; i++) {
  645. children[i].serialNo += gljList.length;
  646. }
  647. }
  648. }
  649. callback(parentNodeID,nextNodeID,data);
  650. }, function () {
  651. $.bootstrapLoading.end();
  652. });
  653. };
  654. ration_glj.prototype.getGLJDataByCodes = function (codes,callback) {
  655. if(!gljUtil.isDef(codes)||codes.length ==0) {
  656. if(callback) callback([]);
  657. return
  658. }
  659. $.bootstrapLoading.start();
  660. CommonAjax.post("/rationGlj/getGLJDataByCodes", { 'engineerID':projectObj.project.projectInfo.property.engineering_id,projectID:projectObj.project.ID(),codes:codes}, function (result) {
  661. $.bootstrapLoading.end();
  662. callback(result)
  663. });
  664. };
  665. ration_glj.prototype.getAddDataByStd = function (glj,rationID,billsItemID,projectID) {//生成添加类型的定额工料机数据
  666. let ration_glj = {
  667. projectID: projectID,
  668. GLJID: glj.ID,
  669. rationID: rationID,
  670. billsItemID: billsItemID,
  671. rationItemQuantity: 0,
  672. quantity: 0,
  673. name: glj.name,
  674. code: glj.code,
  675. original_code: glj.code,
  676. unit: glj.unit,
  677. specs: glj.specs,
  678. basePrice: glj.basePrice,
  679. marketPrice:glj.basePrice,
  680. shortName: glj.shortName,
  681. type: glj.gljType,
  682. model:glj.model,
  683. adjCoe: glj.adjCoe,
  684. createType: 'add',
  685. materialType:glj.materialType,
  686. materialCoe:glj.materialCoe,
  687. materialIndexType:glj.materialIndexType,
  688. materialIndexUnit:glj.materialIndexUnit,
  689. materialIndexCoe:glj.materialIndexCoe,
  690. repositoryId: glj.repositoryId
  691. };
  692. if (glj.hasOwnProperty("compilationId")) {
  693. ration_glj.from = "cpt";
  694. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  695. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  696. }
  697. }
  698. return ration_glj;
  699. };
  700. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  701. const me = this,
  702. gljList = [],
  703. allGLJ = gljOprObj.AllRecode;
  704. GLJSelection.sort();
  705. GLJSelection.forEach(selKey => {
  706. const glj = allGLJ.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === selKey);
  707. if (glj) {
  708. const rationGLJ = me.getAddDataByStd(glj, ration.ID, ration.billsItemID, ration.projectID);
  709. gljList.push(rationGLJ);
  710. }
  711. });
  712. $.bootstrapLoading.start();
  713. CommonAjax.post('/rationGlj/addGLJ', gljList, callback, function () {
  714. $.bootstrapLoading.end();
  715. });
  716. };
  717. ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  718. let me = this;
  719. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  720. let priceObj = priceMap[newval];
  721. if(priceObj){
  722. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  723. recode.rcode = recode.code;
  724. recode.createType = 'replace';
  725. }
  726. recode.code = priceObj.code;
  727. recode.name = priceObj.name;
  728. recode.type = priceObj.type;
  729. recode.unit = priceObj.unit;
  730. recode.shortName = priceObj.short_name;
  731. recode.specs = priceObj.specs;
  732. recode.GLJID=priceObj.glj_id;
  733. recode.original_code = priceObj.original_code;
  734. recode.basePrice = priceObj.base_price;
  735. recode.marketPrice = priceObj.market_price;
  736. }
  737. $.bootstrapLoading.start();
  738. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  739. if (result) {
  740. //result.adjustState;
  741. let glj_list = me.datas;
  742. let data = result.data;
  743. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  744. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  745. let nodes = [rationNode];
  746. glj_list[list_index] = data;
  747. project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
  748. gljOprObj.refreshView();
  749. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  750. let node = project.ration_glj.findGLJNodeByID(data.ID);
  751. if (node) {
  752. project.ration_glj.transferToNodeData(data);
  753. node.source = data;
  754. node.data = data;
  755. }
  756. node ? nodes.push(node) : "";
  757. }
  758. rationNode.data.adjustState = result.adjustState;
  759. rationNode.data.name = result.name;
  760. projectObj.mainController.refreshTreeNode(nodes);
  761. project.calcProgram.calcAndSave(rationNode);
  762. $.bootstrapLoading.end();
  763. }
  764. }, function () {
  765. $.bootstrapLoading.end();
  766. });
  767. };
  768. ration_glj.prototype.getReplaceDataByStd = function (oldData,glj) {
  769. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  770. oldData.rcode = oldData.code;
  771. oldData.createType = 'replace';
  772. }
  773. if(oldData.createType == 'replace' && oldData.rcode == glj.code){//如果原数据已经是替换过的,这次替换又恢复成原数据,则把类型改回来
  774. oldData.createType = 'normal'
  775. }
  776. oldData.GLJID = glj.ID;
  777. oldData.name = glj.name;
  778. oldData.code = glj.code;
  779. oldData.original_code = glj.code;
  780. oldData.unit = glj.unit;
  781. oldData.specs = glj.specs;
  782. oldData.model = glj.model;
  783. oldData.basePrice = glj.basePrice;
  784. oldData.marketPrice = glj.basePrice;
  785. oldData.repositoryId = glj.repositoryId;
  786. oldData.materialType = glj.materialType;
  787. oldData. materialCoe = glj.materialCoe;
  788. oldData. materialIndexType = glj.materialIndexType;
  789. oldData. materialIndexUnit = glj.materialIndexUnit;
  790. oldData. materialIndexCoe = glj.materialIndexCoe;
  791. if (glj.hasOwnProperty("compilationId")) {
  792. oldData.from = "cpt";
  793. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  794. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  795. }
  796. } else {
  797. oldData.from = "std";
  798. }
  799. return oldData;
  800. };
  801. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  802. let allGLJ = gljOprObj.AllRecode;
  803. let glj = _.find(allGLJ, function (item) {
  804. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  805. return i_key == selectCode;
  806. });
  807. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  808. return callback(null);
  809. }
  810. oldData = this.getReplaceDataByStd(oldData,glj);
  811. $.bootstrapLoading.start();
  812. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  813. $.bootstrapLoading.end();
  814. });
  815. };
  816. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  817. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  818. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  819. let glj = _.find(allGLJ, function (item) {
  820. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  821. return i_key == selectCode;
  822. });
  823. if (selectCode == oldIndex) {
  824. return callback(null);
  825. }
  826. let query = {
  827. projectID: oldData.projectID,
  828. code: oldData.code,
  829. name: oldData.name,
  830. unit: oldData.unit,
  831. type: oldData.type
  832. }
  833. if (oldData.specs && oldData.specs != '') {
  834. query.specs = oldData.specs;
  835. }
  836. let doc = {
  837. GLJID: glj.ID,
  838. createType: 'replace',
  839. rationItemQuantity: 0,
  840. name: glj.name,
  841. code: glj.code,
  842. original_code: glj.code,
  843. unit: glj.unit,
  844. specs: glj.specs,
  845. type: glj.gljType,
  846. model:glj.model,
  847. basePrice: glj.basePrice,
  848. marketPrice:glj.basePrice,
  849. repositoryId: glj.repositoryId,
  850. materialType: glj.materialType, //三材类别
  851. materialCoe: glj.materialCoe,
  852. materialIndexType: glj.materialIndexType,
  853. materialIndexUnit: glj.materialIndexUnit,
  854. materialIndexCoe: glj.materialIndexCoe,
  855. projectID: oldData.projectID
  856. };
  857. if (glj.hasOwnProperty("compilationId")) {
  858. doc.from = "cpt";
  859. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  860. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  861. }
  862. } else {
  863. doc.from = "std";
  864. }
  865. for(let d of this.datas){//查询出所有需替换的工料机
  866. if(!gljOprObj.scopeSelectedIDMap[d.billsItemID]) continue; //如果不在选中范围的,跳过
  867. let tem_index = gljOprObj.getIndex(d, gljKeyArray);
  868. if(tem_index == oldIndex){
  869. let tem_doc = _.cloneDeep(doc);
  870. if(d.createType == 'replace'){
  871. tem_doc.rcode = d.rcode;
  872. }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
  873. tem_doc.createType = 'add';
  874. }else {
  875. tem_doc.rcode = d.code
  876. }
  877. let task = {
  878. updateOne:{
  879. filter : {ID:d.ID},
  880. update : tem_doc
  881. }
  882. };
  883. tasks.push(task);
  884. updateMap[d.ID] = tem_doc;
  885. }
  886. }
  887. $.bootstrapLoading.start();
  888. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
  889. callback(result,updateMap);
  890. }, function () {
  891. $.bootstrapLoading.end();
  892. });
  893. };
  894. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  895. let gljList = _.filter(this.datas, function (n) {
  896. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  897. });
  898. gljList = gljUtil.sortRationGLJ(gljList);
  899. return gljOprObj.combineWithProjectGlj(gljList);
  900. };
  901. ration_glj.prototype.transferToNodeData = function (data) {
  902. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  903. data.subType = data.type;
  904. };
  905. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  906. if (ration) {
  907. let projectGLJData = projectObj.project.projectGLJ.datas;
  908. let projectGljs = projectGLJData.gljList;
  909. let mixRatioMap = projectGLJData.mixRatioMap;
  910. let glj = _.find(projectGljs, {'id': ration.projectGLJID});
  911. if (glj) {
  912. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  913. ration.isEstimate = glj.is_evaluate;
  914. }
  915. ration = gljOprObj.setGLJPrice(ration,glj);
  916. ration.isAdd = glj.unit_price.is_add;
  917. let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  918. if (mixRatioMap.hasOwnProperty(connect_index)) {
  919. let mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  920. ration.subList = mixRatios;
  921. }
  922. }
  923. }
  924. return ration;
  925. };
  926. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  927. if (node.data[fieldName] !== value) {
  928. if (fieldName == "marketUnitFee") {
  929. let decimal = getDecimal("glj.unitPrice");
  930. let newval = number_util.checkNumberValue(value, decimal);
  931. if (newval) {
  932. fieldName = "marketPrice";
  933. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  934. return;
  935. }
  936. } else {
  937. if(fieldName == "contain"){
  938. if(value==null){
  939. value="";
  940. }else {
  941. let decimal = getDecimal("glj.quantity");
  942. value = number_util.checkNumberValue(value, decimal);
  943. fieldName="customQuantity";//填入自定义消耗
  944. }
  945. }
  946. if (value !== undefined && value !== null) {
  947. if (fieldName == "subType") {
  948. node.data.subType = value;
  949. fieldName = "type";//转换成更新工料机类型
  950. }
  951. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  952. return;
  953. }
  954. }
  955. }
  956. // node.data.subType = value;
  957. projectObj.mainController.refreshTreeNode([node]);
  958. };
  959. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  960. if (this.needShowToTree(data)) {
  961. this.transferToNodeData(data);
  962. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  963. }
  964. };
  965. ration_glj.prototype.needShowToTree = function (data) {
  966. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  967. return true
  968. }
  969. return false
  970. };
  971. ration_glj.prototype.findGLJNodeByID = function (ID) {
  972. return projectObj.project.mainTree.findNode(ID);
  973. };
  974. ration_glj.prototype.findRationNodeByID = function (ID) {
  975. return projectObj.project.mainTree.findNode(ID);
  976. };
  977. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  978. let node = this.findRationNodeByID(ration_glj.rationID);
  979. if (node) {
  980. node.changed = true;
  981. project.calcProgram.calcAndSave(node, async function () {
  982. await OVER_HEIGHT.reCalcOverHeightFee();
  983. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([node.parent]);
  984. });
  985. }
  986. };
  987. return new ration_glj(project);
  988. }
  989. };