ration_glj.js 46 KB

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