ration_glj.js 47 KB

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