ration_glj.js 47 KB

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