ration_glj.js 49 KB

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