ration_glj.js 49 KB

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