ration_glj.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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. taxRate:recode.taxRate
  417. };
  418. if(updateData['type'] != undefined || updateData['type'] != null){
  419. updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
  420. }
  421. let callback = function (data) {
  422. if (updateField == 'customQuantity') {
  423. me.refreshAfterQuantityUpdate(data, node);
  424. } else {
  425. let doc = data.doc;
  426. for (let key in doc) {
  427. recode[key] = doc[key];
  428. }
  429. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  430. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  431. if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  432. projectObj.mainController.deleteNode(node, true);
  433. }
  434. }
  435. }
  436. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  437. gljOprObj.refreshView();
  438. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  439. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  440. $.bootstrapLoading.end();
  441. installationFeeObj.calcInstallationFee();
  442. // OVER_HEIGHT.reCalcOverHeightFee();
  443. });
  444. };
  445. $.bootstrapLoading.start();
  446. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  447. query: query,
  448. doc: updateData,
  449. priceInfo: priceInfo
  450. }, callback, function (err) {
  451. $.bootstrapLoading.end();
  452. });
  453. };
  454. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  455. let me = this;
  456. data.glj_result.forEach(function (item) {
  457. me.refreshEachItme(item.doc, item.query);
  458. });
  459. me.refreshRationAfterEdit(data, data.rationID, node);
  460. };
  461. ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
  462. let nodes = [];
  463. let node = this.refreshRationNode(data.name,data.adjustState,rationID);
  464. if (node) nodes.push(node);
  465. if (rnode) nodes.push(rnode);
  466. projectObj.mainController.refreshTreeNode(nodes);
  467. };
  468. ration_glj.prototype.refreshRationNode = function(name,adjustState,rationID){
  469. let node = projectObj.project.mainTree.findNode(rationID);
  470. if (!node) return null;
  471. if(gljUtil.isDef(adjustState)){
  472. node.data.adjustState = adjustState;
  473. }
  474. if(gljUtil.isDef(name)){
  475. node.data.name = name;
  476. }
  477. return node
  478. };
  479. ration_glj.prototype.getGLJDataPaging = function (condition, cb) {
  480. gljOprObj.loadingPagination = true;
  481. const property = projectObj.project.projectInfo.property;
  482. const engineerID = property.engineering_id;
  483. const actionType = $('#actionType').val();
  484. CommonAjax.post('/rationGlj/getGLJDataPaging', {engineerID, condition}, function (data) {
  485. gljOprObj.curPageTotal = data.total;
  486. data.complementaryGLJs.forEach(glj => {
  487. glj.isComplementary = true;
  488. });
  489. const gljType = condition.type === gljOprObj.pagingType.stdGLJ
  490. ? 'stdGLJ'
  491. : 'complementaryGLJs';
  492. const newData = data[gljType];
  493. // 添加组成物,类型为主材时,需要排除自身
  494. if (actionType === 'addMix' && projectGljObject.selectedProjectGLJ.type === gljType.MAIN_MATERIAL) {
  495. const pIndex = gljOprObj.getIndex(projectGljObject.selectedProjectGLJ, gljKeyArray);
  496. const delIndex = newData.findIndex(item => gljOprObj.getIndex(item, gljLibKeyArray) === pIndex);
  497. if (!~delIndex) {
  498. newData.splice(delIndex, 1);
  499. }
  500. }
  501. if (condition.init) {
  502. gljOprObj.treeData = data.treeData;
  503. gljOprObj.distTypeTree = gljOprObj.getComboData(data.distTypeTree);
  504. }
  505. // 需要重置当前页面数据(点击了分类树、搜索等等)
  506. if (condition.reset) {
  507. gljOprObj.stdGLJ = data.stdGLJ;
  508. gljOprObj.complementaryGLJs = data.complementaryGLJs;
  509. gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];
  510. } else {
  511. gljOprObj[gljType].splice(condition.index, 0, ...newData);
  512. gljOprObj.AllRecode.splice(condition.index, 0, ...newData);
  513. }
  514. // 根据缓存选中数据,设置人材机是否选中
  515. newData.forEach(item => {
  516. const connectKey = gljOprObj.getIndex(item, gljLibKeyArray);
  517. if (gljOprObj.GLJSelection.includes(connectKey)) {
  518. item.select = 1;
  519. }
  520. });
  521. // 设置人材机类型名称
  522. gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, newData);
  523. if (data.priceProperties && data.priceProperties.length > 0) {
  524. let tmp = _.find(data.priceProperties, {region: property.region, taxModel: parseInt(property.taxType)});
  525. if (tmp) {
  526. let dataCode = tmp.price.dataCode;
  527. for (let glj of data.stdGLJ) {
  528. if (glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) {
  529. glj.basePrice = glj.priceProperty[dataCode];
  530. }
  531. }
  532. }
  533. }
  534. cb(data[gljType]);
  535. gljOprObj.loadingPagination = false;
  536. }, function () {
  537. if ($.bootstrapLoading.isLoading()) {
  538. $.bootstrapLoading.end();
  539. }
  540. });
  541. };
  542. ration_glj.prototype.getGLJData = function (cb) {
  543. let property = projectObj.project.projectInfo.property;
  544. let engineerID = property.engineering_id;
  545. CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
  546. //编办中有多单价设置
  547. if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
  548. let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});
  549. if(tem){
  550. let dataCode = tem.price.dataCode;
  551. for(let glj of data.datas.stdGLJ){
  552. if(glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) glj.basePrice = glj.priceProperty[dataCode];
  553. }
  554. }
  555. };
  556. cb(data);
  557. })
  558. };
  559. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  560. let gljList = [];
  561. let allGLJ = gljOprObj.AllRecode;
  562. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  563. let pEngineer = projectObj.project.projectInfo.property.projectEngineering;
  564. let children = [];
  565. if (selected.sourceType === project.Bills.getSourceType()) {
  566. billsItemID = selected.data.ID;
  567. parentNodeID = selected.getID();
  568. nextNodeID = selected.tree.rootID();
  569. billNode = selected;
  570. } else {
  571. billsItemID = selected.data.billsItemID;
  572. serialNo = selected.data.serialNo;
  573. selectedSerialNo = selected.data.serialNo;
  574. nextNodeID = selected.getNextSiblingID();
  575. parentNodeID = selected.getParentID();
  576. billNode = selected.parent;
  577. }
  578. children = project.Ration.getBillsSortRation(billsItemID);
  579. serialNo == 0 ? serialNo = children.length : "";
  580. for (let con_key of GLJSelection) {
  581. let glj = _.find(allGLJ, function (item) {
  582. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  583. return i_key == con_key;
  584. });
  585. if (glj) {
  586. serialNo += 1;
  587. let new_glj = {
  588. ID: project.Ration.getNewRationID(),
  589. projectID: parseInt(project.ID()),
  590. billsItemID: billsItemID,
  591. type: rationType.gljRation,
  592. code: glj.code,
  593. name: glj.name,
  594. quantity: 0,
  595. unit: glj.unit,
  596. specs: glj.specs,
  597. subType: glj.gljType,
  598. model:glj.model,
  599. basePrice: glj.basePrice,
  600. marketPrice:glj.basePrice,
  601. taxRate:glj.taxRate,
  602. original_code: glj.code,
  603. shortName: glj.shortName,
  604. serialNo: serialNo,
  605. GLJID: glj.ID,
  606. adjCoe: glj.adjCoe,
  607. materialType:glj.materialType,
  608. materialCoe:glj.materialCoe,
  609. materialIndexType:glj.materialIndexType,
  610. materialIndexUnit:glj.materialIndexUnit,
  611. materialIndexCoe:glj.materialIndexCoe,
  612. repositoryId: glj.repositoryId
  613. };
  614. if(pEngineer) new_glj.programID = pEngineer;
  615. if (glj.hasOwnProperty("compilationId")) {
  616. new_glj.from = "cpt";
  617. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  618. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  619. }
  620. }
  621. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  622. new_glj.quantityEXP="QDL";
  623. if(billNode.data.quantity){
  624. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  625. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  626. }
  627. }
  628. gljList.push(new_glj);
  629. }
  630. }
  631. if (gljList.length == 0) {
  632. return;
  633. }
  634. let postData = {
  635. gljList: gljList,
  636. projectID: parseInt(project.ID()),
  637. billsItemID: billsItemID,
  638. rationCount: project.Ration.maxRationID()
  639. }
  640. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  641. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  642. // 更新兄弟节点的序列号
  643. if (selectedSerialNo != null) {
  644. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  645. if (selectIndex + 1 < children.length) {
  646. for (let i = selectIndex + 1; i < children.length; i++) {
  647. children[i].serialNo += gljList.length;
  648. }
  649. }
  650. }
  651. callback(parentNodeID,nextNodeID,data);
  652. }, function () {
  653. $.bootstrapLoading.end();
  654. });
  655. };
  656. ration_glj.prototype.getGLJDataByCodes = function (codes,callback) {
  657. if(!gljUtil.isDef(codes)||codes.length ==0) {
  658. if(callback) callback([]);
  659. return
  660. }
  661. $.bootstrapLoading.start();
  662. CommonAjax.post("/rationGlj/getGLJDataByCodes", { 'engineerID':projectObj.project.projectInfo.property.engineering_id,projectID:projectObj.project.ID(),codes:codes}, function (result) {
  663. $.bootstrapLoading.end();
  664. callback(result)
  665. });
  666. };
  667. ration_glj.prototype.getAddDataByStd = function (glj,rationID,billsItemID,projectID) {//生成添加类型的定额工料机数据
  668. let ration_glj = {
  669. projectID: projectID,
  670. GLJID: glj.ID,
  671. rationID: rationID,
  672. billsItemID: billsItemID,
  673. rationItemQuantity: 0,
  674. quantity: 0,
  675. name: glj.name,
  676. code: glj.code,
  677. original_code: glj.code,
  678. unit: glj.unit,
  679. specs: glj.specs,
  680. basePrice: glj.basePrice,
  681. marketPrice:glj.basePrice,
  682. taxRate:glj.taxRate,
  683. shortName: glj.shortName,
  684. type: glj.gljType,
  685. model:glj.model,
  686. adjCoe: glj.adjCoe,
  687. createType: 'add',
  688. materialType:glj.materialType,
  689. materialCoe:glj.materialCoe,
  690. materialIndexType:glj.materialIndexType,
  691. materialIndexUnit:glj.materialIndexUnit,
  692. materialIndexCoe:glj.materialIndexCoe,
  693. repositoryId: glj.repositoryId
  694. };
  695. if (glj.hasOwnProperty("compilationId")) {
  696. ration_glj.from = "cpt";
  697. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  698. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  699. }
  700. }
  701. return ration_glj;
  702. };
  703. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  704. const me = this,
  705. gljList = [],
  706. allGLJ = gljOprObj.AllRecode;
  707. GLJSelection.sort();
  708. GLJSelection.forEach(selKey => {
  709. const glj = allGLJ.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === selKey);
  710. if (glj) {
  711. const rationGLJ = me.getAddDataByStd(glj, ration.ID, ration.billsItemID, ration.projectID);
  712. gljList.push(rationGLJ);
  713. }
  714. });
  715. $.bootstrapLoading.start();
  716. CommonAjax.post('/rationGlj/addGLJ', gljList, callback, function () {
  717. $.bootstrapLoading.end();
  718. });
  719. };
  720. ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  721. let me = this;
  722. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  723. let priceObj = priceMap[newval];
  724. if(priceObj){
  725. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  726. recode.rcode = recode.code;
  727. recode.createType = 'replace';
  728. }
  729. recode.code = priceObj.code;
  730. recode.name = priceObj.name;
  731. recode.type = priceObj.type;
  732. recode.unit = priceObj.unit;
  733. recode.shortName = priceObj.short_name;
  734. recode.specs = priceObj.specs;
  735. recode.GLJID=priceObj.glj_id;
  736. recode.original_code = priceObj.original_code;
  737. recode.basePrice = priceObj.base_price;
  738. recode.marketPrice = priceObj.market_price;
  739. }
  740. $.bootstrapLoading.start();
  741. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  742. if (result) {
  743. //result.adjustState;
  744. let glj_list = me.datas;
  745. let data = result.data;
  746. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  747. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  748. let nodes = [rationNode];
  749. glj_list[list_index] = data;
  750. project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
  751. gljOprObj.refreshView();
  752. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  753. let node = project.ration_glj.findGLJNodeByID(data.ID);
  754. if (node) {
  755. project.ration_glj.transferToNodeData(data);
  756. node.source = data;
  757. node.data = data;
  758. }
  759. node ? nodes.push(node) : "";
  760. }
  761. rationNode.data.adjustState = result.adjustState;
  762. rationNode.data.name = result.name;
  763. projectObj.mainController.refreshTreeNode(nodes);
  764. project.calcProgram.calcAndSave(rationNode);
  765. $.bootstrapLoading.end();
  766. }
  767. }, function () {
  768. $.bootstrapLoading.end();
  769. });
  770. };
  771. ration_glj.prototype.getReplaceDataByStd = function (oldData,glj) {
  772. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  773. oldData.rcode = oldData.code;
  774. oldData.createType = 'replace';
  775. }
  776. if(oldData.createType == 'replace' && oldData.rcode == glj.code){//如果原数据已经是替换过的,这次替换又恢复成原数据,则把类型改回来
  777. oldData.createType = 'normal'
  778. }
  779. oldData.GLJID = glj.ID;
  780. oldData.name = glj.name;
  781. oldData.code = glj.code;
  782. oldData.original_code = glj.code;
  783. oldData.unit = glj.unit;
  784. oldData.specs = glj.specs;
  785. oldData.model = glj.model;
  786. oldData.basePrice = glj.basePrice;
  787. oldData.marketPrice = glj.basePrice;
  788. oldData.repositoryId = glj.repositoryId;
  789. oldData.materialType = glj.materialType;
  790. oldData. materialCoe = glj.materialCoe;
  791. oldData. materialIndexType = glj.materialIndexType;
  792. oldData. materialIndexUnit = glj.materialIndexUnit;
  793. oldData. materialIndexCoe = glj.materialIndexCoe;
  794. if (glj.hasOwnProperty("compilationId")) {
  795. oldData.from = "cpt";
  796. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  797. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  798. }
  799. } else {
  800. oldData.from = "std";
  801. }
  802. return oldData;
  803. };
  804. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  805. let allGLJ = gljOprObj.AllRecode;
  806. let glj = _.find(allGLJ, function (item) {
  807. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  808. return i_key == selectCode;
  809. });
  810. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  811. return callback(null);
  812. }
  813. oldData = this.getReplaceDataByStd(oldData,glj);
  814. $.bootstrapLoading.start();
  815. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  816. $.bootstrapLoading.end();
  817. });
  818. };
  819. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  820. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  821. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  822. let glj = _.find(allGLJ, function (item) {
  823. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  824. return i_key == selectCode;
  825. });
  826. if (selectCode == oldIndex) {
  827. return callback(null);
  828. }
  829. let query = {
  830. projectID: oldData.projectID,
  831. code: oldData.code,
  832. name: oldData.name,
  833. unit: oldData.unit,
  834. type: oldData.type
  835. }
  836. if (oldData.specs && oldData.specs != '') {
  837. query.specs = oldData.specs;
  838. }
  839. let doc = {
  840. GLJID: glj.ID,
  841. createType: 'replace',
  842. rationItemQuantity: 0,
  843. name: glj.name,
  844. code: glj.code,
  845. original_code: glj.code,
  846. unit: glj.unit,
  847. specs: glj.specs,
  848. type: glj.gljType,
  849. model:glj.model,
  850. basePrice: glj.basePrice,
  851. marketPrice:glj.basePrice,
  852. repositoryId: glj.repositoryId,
  853. materialType: glj.materialType, //三材类别
  854. materialCoe: glj.materialCoe,
  855. materialIndexType: glj.materialIndexType,
  856. materialIndexUnit: glj.materialIndexUnit,
  857. materialIndexCoe: glj.materialIndexCoe,
  858. projectID: oldData.projectID
  859. };
  860. if (glj.hasOwnProperty("compilationId")) {
  861. doc.from = "cpt";
  862. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  863. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  864. }
  865. } else {
  866. doc.from = "std";
  867. }
  868. for(let d of this.datas){//查询出所有需替换的工料机
  869. if(!gljOprObj.scopeSelectedIDMap[d.billsItemID]) continue; //如果不在选中范围的,跳过
  870. let tem_index = gljOprObj.getIndex(d, gljKeyArray);
  871. if(tem_index == oldIndex){
  872. let tem_doc = _.cloneDeep(doc);
  873. if(d.createType == 'replace'){
  874. tem_doc.rcode = d.rcode;
  875. }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
  876. tem_doc.createType = 'add';
  877. }else {
  878. tem_doc.rcode = d.code
  879. }
  880. let task = {
  881. updateOne:{
  882. filter : {ID:d.ID},
  883. update : tem_doc
  884. }
  885. };
  886. tasks.push(task);
  887. updateMap[d.ID] = tem_doc;
  888. }
  889. }
  890. $.bootstrapLoading.start();
  891. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
  892. callback(result,updateMap);
  893. }, function () {
  894. $.bootstrapLoading.end();
  895. });
  896. };
  897. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  898. let gljList = _.filter(this.datas, function (n) {
  899. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  900. });
  901. gljList = gljUtil.sortRationGLJ(gljList);
  902. return gljOprObj.combineWithProjectGlj(gljList);
  903. };
  904. ration_glj.prototype.transferToNodeData = function (data) {
  905. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  906. data.subType = data.type;
  907. };
  908. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  909. if (ration) {
  910. let projectGLJData = projectObj.project.projectGLJ.datas;
  911. let projectGljs = projectGLJData.gljList;
  912. let mixRatioMap = projectGLJData.mixRatioMap;
  913. let glj = _.find(projectGljs, {'id': ration.projectGLJID});
  914. if (glj) {
  915. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  916. ration.isEstimate = glj.is_evaluate;
  917. }
  918. ration = gljOprObj.setGLJPrice(ration,glj);
  919. ration.isAdd = glj.unit_price.is_add;
  920. let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  921. if (mixRatioMap.hasOwnProperty(connect_index)) {
  922. let mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  923. ration.subList = mixRatios;
  924. }
  925. }
  926. }
  927. return ration;
  928. };
  929. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  930. if (node.data[fieldName] !== value) {
  931. if (fieldName == "marketUnitFee") {
  932. let decimal = getDecimal("glj.unitPrice");
  933. let newval = number_util.checkNumberValue(value, decimal);
  934. if (newval) {
  935. fieldName = "marketPrice";
  936. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  937. return;
  938. }
  939. } else {
  940. if(fieldName == "contain"){
  941. if(value==null){
  942. value="";
  943. }else {
  944. let decimal = getDecimal("glj.quantity");
  945. value = number_util.checkNumberValue(value, decimal);
  946. fieldName="customQuantity";//填入自定义消耗
  947. }
  948. }
  949. if (value !== undefined && value !== null) {
  950. if (fieldName == "subType") {
  951. node.data.subType = value;
  952. fieldName = "type";//转换成更新工料机类型
  953. }
  954. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  955. return;
  956. }
  957. }
  958. }
  959. // node.data.subType = value;
  960. projectObj.mainController.refreshTreeNode([node]);
  961. };
  962. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  963. if (this.needShowToTree(data)) {
  964. this.transferToNodeData(data);
  965. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  966. }
  967. };
  968. ration_glj.prototype.needShowToTree = function (data) {
  969. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  970. return true
  971. }
  972. return false
  973. };
  974. ration_glj.prototype.findGLJNodeByID = function (ID) {
  975. return projectObj.project.mainTree.findNode(ID);
  976. };
  977. ration_glj.prototype.findRationNodeByID = function (ID) {
  978. return projectObj.project.mainTree.findNode(ID);
  979. };
  980. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  981. let node = this.findRationNodeByID(ration_glj.rationID);
  982. if (node) {
  983. node.changed = true;
  984. project.calcProgram.calcAndSave(node, async function () {
  985. await OVER_HEIGHT.reCalcOverHeightFee();
  986. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([node.parent]);
  987. });
  988. }
  989. };
  990. return new ration_glj(project);
  991. }
  992. };