ration_glj.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var ration_glj = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_glj = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var 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.getGljArrByRation = function (ration) {
  41. if (ration.type == rationType.gljRation){
  42. let glj = JSON.parse(JSON.stringify(ration));
  43. glj.type = glj.subType;
  44. glj.quantity = 1;
  45. return [glj];
  46. }
  47. else{
  48. let result = this.datas.filter(function (data) {
  49. return data.rationID === ration.ID;
  50. })
  51. result = gljOprObj.combineWithProjectGlj(result);
  52. return result;
  53. }
  54. };
  55. ration_glj.prototype.getGatherGljArrByRations = function (rations, needOneBill, billQuantity) {
  56. let result = [];
  57. let clone = function (obj) {
  58. if (obj === null) return null;
  59. var o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  60. for (var i in obj) {
  61. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
  62. }
  63. return o;
  64. }
  65. let findGlj = function (sourceGlj, gljArr) {
  66. for (let glj of gljArr) {
  67. if (glj.projectGLJID === sourceGlj.projectGLJID) {
  68. return glj;
  69. }
  70. }
  71. return null;
  72. }
  73. for (let ration of rations) {
  74. if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
  75. result.push(ration);
  76. }
  77. else{
  78. let rationGljs = this.getGljArrByRation(ration);
  79. for (let glj of rationGljs) {
  80. let sameGlj = findGlj(glj, result);
  81. if (!sameGlj) {
  82. sameGlj = clone(glj);
  83. sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
  84. result.push(sameGlj);
  85. } else {
  86. sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
  87. sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
  88. }
  89. }
  90. }
  91. }
  92. result = gljOprObj.combineWithProjectGlj(result);
  93. if (!needOneBill) return result;
  94. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  95. let oneBill = JSON.parse(JSON.stringify(result));
  96. for (let glj of oneBill){
  97. if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
  98. glj.type = glj.subType;
  99. glj.basePrice = glj.marketUnitFee;
  100. glj.marketPrice = glj.marketUnitFee;
  101. glj.adjustPrice = glj.marketUnitFee;
  102. }
  103. else if (glj.type == rationType.gljRation){
  104. glj.type = glj.subType;
  105. };
  106. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  107. };
  108. return oneBill;
  109. }
  110. // 提交数据后返回数据处理
  111. ration_glj.prototype.doAfterUpdate = function (err, data) {
  112. var me = this;
  113. if (!err) {
  114. if (data.updateTpye == 'ut_update') {
  115. me.refreshAfterUpdate(data);
  116. } else if (data.updateTpye == 'ut_delete') {
  117. me.refreshAfterDelete(data);
  118. } else {
  119. me.refreshAfterSave(data);
  120. }
  121. }
  122. projectObj.project.projectGLJ.loadData();
  123. };
  124. ration_glj.prototype.getDataByID = function (ID) {
  125. return _.find(this.datas,{'ID':ID});
  126. };
  127. ration_glj.prototype.refreshAfterSave = function (data) {
  128. let me = projectObj.project.ration_glj;
  129. let neRecodes = [];
  130. if (data) {
  131. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  132. neRecodes = data.showDatas;
  133. gljOprObj.sheetData = neRecodes;
  134. me.addDatasToList(neRecodes);
  135. }
  136. project.projectGLJ.loadData(function () {
  137. gljOprObj.showRationGLJSheetData(true);
  138. //add to mainTree;
  139. me.addToMainTree(neRecodes);
  140. let rationID = neRecodes[0].rationID;
  141. let node = project.mainTree.nodes['id_' + rationID];
  142. if(isDef(node)){
  143. project.calcProgram.calcAndSave(node);
  144. }
  145. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  146. calcProgramObj.showData(node, false);
  147. }
  148. });
  149. };
  150. ration_glj.prototype.getGljByRationID = function(rationID){
  151. return _.filter(this.datas, {'rationID': rationID});
  152. };
  153. ration_glj.prototype.addDatasToList = function (datas) {
  154. let me = projectObj.project.ration_glj;
  155. if(datas&&datas.length>0){
  156. if (me.datas && Array.isArray(me.datas)) {
  157. me.datas = me.datas.concat(datas);
  158. } else {
  159. me.datas = datas;
  160. }
  161. }
  162. };
  163. ration_glj.prototype.addToMainTree = function (datas) {
  164. datas = sortRationGLJ(datas);
  165. for (let data of datas) {
  166. if (this.needShowToTree(data)) {
  167. gljOprObj.setGLJPrice(data);
  168. this.transferToNodeData(data);
  169. let parentNode = _.find(projectObj.project.mainTree.items, function (n) {//找父节点
  170. return n.sourceType == ModuleNames.ration && n.data.ID == data.rationID;
  171. });
  172. if (parentNode) {
  173. let nextNodeID = null;
  174. if (parentNode.children.length > 0) {
  175. for (let br of parentNode.children) {
  176. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  177. nextNodeID = br.getID();
  178. }
  179. }
  180. }
  181. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  182. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  183. newNode.source = data;
  184. newNode.sourceType = this.getSourceType();
  185. newNode.data = data;
  186. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  187. }
  188. }
  189. }
  190. };
  191. ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
  192. let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
  193. let deleteNodes = [];
  194. for(let rg of glj_list){
  195. if(this.needShowToTree(rg)){
  196. let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
  197. deleteNodes.push(r_node);
  198. }
  199. }
  200. if(deleteNodes.length > 0){
  201. let rowIndex = deleteNodes[0].serialNo();
  202. if(controller.tree.m_delete(deleteNodes)){
  203. TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
  204. let rowCount = deleteNodes.length;
  205. controller.sheet.deleteRows(rowIndex, rowCount);
  206. });
  207. }
  208. }
  209. };
  210. ration_glj.prototype.refreshAfterUpdate = function (data) {
  211. var me = this;
  212. var rationID=null;
  213. if (data.quantityRefresh) {
  214. data.glj_result.forEach(function (item) {
  215. rationID = me.refreshEachItme(item.doc, item.query);
  216. })
  217. } else {
  218. rationID = me.refreshEachItme(data.doc, data.query);
  219. }
  220. gljOprObj.showRationGLJSheetData(true);
  221. this.reCalcWhenGLJChange({rationID:rationID});
  222. };
  223. ration_glj.prototype.refreshEachItme = function (doc, query) {
  224. var glj_list = projectObj.project.ration_glj.datas;
  225. var glj_index = _.findIndex(glj_list, (glj) => {
  226. return glj.ID == query.ID;
  227. })
  228. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  229. return sd.ID==query.ID;
  230. })*/
  231. _.forEach(doc, function (n, key) {
  232. glj_list[glj_index][key] = n;
  233. });
  234. return glj_list[glj_index].rationID;
  235. };
  236. ration_glj.prototype.refreshAfterDelete = function (data) {
  237. var me = projectObj.project.ration_glj;
  238. var glj_list = me.datas;
  239. var oldData = _.remove(glj_list, data.query);
  240. _.remove(gljOprObj.sheetData, data.query);
  241. gljOprObj.showRationGLJSheetData();
  242. projectObj.project.projectGLJ.loadData();
  243. var rationNode = null;
  244. var next = null;
  245. var selected = projectObj.project.mainTree.selected;
  246. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  247. rationNode = selected;
  248. } else if (selected.sourceType == ModuleNames.ration_glj) {
  249. rationNode = selected.parent;
  250. next = true;
  251. }
  252. rationNode.data.adjustState = data.adjustState;
  253. projectObj.mainController.refreshTreeNode([rationNode]);
  254. for (let o of oldData) {
  255. if (this.needShowToTree(o)) {
  256. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  257. projectObj.mainController.deleteNode(node, next);
  258. }
  259. }
  260. };
  261. // CSL,2017.05.09
  262. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  263. this.project.beginUpdate('modifyQuantity');
  264. data.quantity = newQuantity;
  265. data.customQuantity = newQuantity;
  266. data.updateType = 'ut_update';
  267. this.project.push(this.getSourceType, data);
  268. this.project.endUpdate();
  269. };
  270. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  271. this.project.beginUpdate('modifyPrice');
  272. data.price = newPrice;
  273. data.updateType = 'ut_update';
  274. this.project.push(this.getSourceType, data);
  275. this.project.endUpdate();
  276. };
  277. ration_glj.prototype.deleteGLJ = function (data) {
  278. this.project.beginUpdate('deleteGLJ');
  279. data.customQuantity = 0;
  280. data.quantity = 0;
  281. data.rationItemQuantity = 0;
  282. data.updateType = 'ut_update';
  283. this.project.push(this.getSourceType, data);
  284. this.project.endUpdate();
  285. };
  286. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  287. var souceTypeList = [];
  288. var criteriaDataList = [];
  289. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  290. let criteria = {};
  291. criteria.ration_glj_list = [];
  292. for (let i = 0; i < data.rationGljList.length; i++) {
  293. let temdata = data.rationGljList[i];
  294. let newGLJ = {};
  295. newGLJ.projectID = parseInt(newRation.projectID);
  296. newGLJ.GLJID = temdata.gljId;
  297. newGLJ.rationID = newRation.ID;
  298. newGLJ.billsItemID = newRation.billsItemID,
  299. newGLJ.rationItemQuantity = temdata.consumeAmt;
  300. newGLJ.quantity = temdata.consumeAmt;
  301. newGLJ.glj_repository_id = data.rationRepId;
  302. criteria.ration_glj_list.push(newGLJ);
  303. }
  304. criteria.updateType = 'ut_create';
  305. souceTypeList.push(this.getSourceType());
  306. criteriaDataList.push(criteria);
  307. }
  308. var ration_coe = projectObj.project.ration_coe;
  309. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  310. souceTypeList.push(ration_coe.getSourceType());
  311. criteriaDataList.push(rationCoeData);
  312. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  313. };
  314. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  315. var updateData = [];
  316. updateData.push({
  317. 'deleteType': 'RATION',
  318. 'updateType': 'ut_delete',
  319. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  320. });
  321. return updateData;
  322. };
  323. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  324. var updateData = [];
  325. datas.forEach(function (deleteData) {
  326. if (deleteData.type == 'delete') {
  327. var billData = deleteData.data;
  328. updateData.push({
  329. 'deleteType': 'BILL',
  330. 'updateType': 'ut_delete',
  331. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  332. });
  333. }
  334. })
  335. return updateData;
  336. };
  337. ration_glj.prototype.deleteByRation = function (ration) {
  338. var glj_list = projectObj.project.ration_glj.datas;
  339. _.remove(glj_list,{'rationID':ration.ID});
  340. };
  341. ration_glj.prototype.deleteByBills = function (deleteData) {
  342. var rationList = projectObj.project.Ration.datas;
  343. var deleteRationList = [];
  344. for (var i = 0; i < deleteData.length; i++) {
  345. if (deleteData[i].type == 'delete') {
  346. var billID = deleteData[i].data.ID;
  347. var raList = _.filter(rationList, (ration) => {
  348. return ration.billsItemID == billID;
  349. });
  350. deleteRationList = deleteRationList.concat(raList);
  351. }
  352. }
  353. for (var i = 0; i < deleteRationList.length; i++) {
  354. this.deleteByRation(deleteRationList[i]);
  355. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  356. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  357. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  358. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  359. }
  360. }
  361. ration_glj.prototype.updataOrdelete = function (row) {
  362. var updateData = null;
  363. if (row.rationItemQuantity == 0) {
  364. updateData = this.getUpdateData('ut_delete', {
  365. 'ID': row.ID,
  366. 'projectID': row.projectID
  367. }, {rationID: row.rationID});
  368. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  369. } else {
  370. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  371. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  372. }
  373. };
  374. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  375. var updateData = [];
  376. var newobj = {
  377. 'updateType': type,
  378. 'query': query,
  379. }
  380. if (doc) {
  381. newobj['doc'] = doc;
  382. }
  383. if (callfunction) {
  384. newobj['updateFunction'] = callfunction;
  385. }
  386. updateData.push(newobj);
  387. return updateData;
  388. };
  389. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  390. var me = this;
  391. $.bootstrapLoading.start();
  392. var callback = function (data) {
  393. let initShow = false;//是否需要表格初始化显示
  394. if (updateField == 'customQuantity') {
  395. me.refreshAfterQuantityUpdate(data, node);
  396. } else {
  397. var doc = data.doc;
  398. for (var key in doc) {
  399. recode[key] = doc[key];
  400. }
  401. if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
  402. me.updateRationAdjustState(data.adjustState, recode.rationID, node);
  403. }
  404. if (recode.subList && recode.subList.length > 0) {
  405. initShow = true;
  406. }
  407. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  408. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  409. projectObj.mainController.deleteNode(node, true);
  410. }
  411. }
  412. }
  413. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  414. gljOprObj.showRationGLJSheetData();
  415. }
  416. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  417. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  418. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  419. if (initShow == true) {
  420. gljOprObj.refreshView();
  421. }
  422. $.bootstrapLoading.end();
  423. });
  424. }
  425. var query = {
  426. 'ID': recode.ID,
  427. 'projectID': recode.projectID,
  428. 'rationID': recode.rationID
  429. };
  430. var priceInfo = {
  431. base_price: recode.basePrice,
  432. market_price: recode.marketPrice
  433. }
  434. var doc = {};
  435. doc[updateField] = newval;
  436. if (updateField == "type") {
  437. doc.shortName = projectObj.project.projectGLJ.getShortNameByID(newval);
  438. }
  439. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  440. query: query,
  441. doc: doc,
  442. priceInfo: priceInfo
  443. }, callback, function (err) {
  444. $.bootstrapLoading.end();
  445. });
  446. }
  447. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  448. var me = this;
  449. data.glj_result.forEach(function (item) {
  450. me.refreshEachItme(item.doc, item.query);
  451. })
  452. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  453. };
  454. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  455. var nodes = [];
  456. var node = _.find(projectObj.project.mainTree.items, function (n) {
  457. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  458. })
  459. if (node) {
  460. node.data.adjustState = adjustState;
  461. nodes.push(node);
  462. }
  463. if (rnode) {
  464. nodes.push(rnode);
  465. }
  466. projectObj.mainController.refreshTreeNode(nodes);
  467. };
  468. ration_glj.prototype.getGLJData = function (cb) {
  469. CommonAjax.get('/rationGlj/getGLJData', function (data) {
  470. cb(data);
  471. })
  472. };
  473. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  474. let gljList = [];
  475. let allGLJ = gljOprObj.AllRecode;
  476. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  477. let children = [];
  478. if (selected.sourceType === project.Bills.getSourceType()) {
  479. billsItemID = selected.data.ID;
  480. parentNodeID = selected.getID();
  481. nextNodeID = selected.tree.rootID();
  482. billNode = selected;
  483. } else {
  484. billsItemID = selected.data.billsItemID;
  485. serialNo = selected.data.serialNo;
  486. selectedSerialNo = selected.data.serialNo;
  487. nextNodeID = selected.getNextSiblingID();
  488. parentNodeID = selected.getParentID();
  489. billNode = selected.parent;
  490. }
  491. children = project.Ration.getBillsSortRation(billsItemID);
  492. serialNo == 0 ? serialNo = children.length : "";
  493. for (let con_key of GLJSelection) {
  494. var glj = _.find(allGLJ, function (item) {
  495. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  496. return i_key == con_key;
  497. });
  498. if (glj) {
  499. serialNo += 1;
  500. let new_glj = {
  501. ID: project.Ration.getNewRationID(),
  502. projectID: parseInt(project.ID()),
  503. billsItemID: billsItemID,
  504. type: rationType.gljRation,
  505. code: glj.code,
  506. name: glj.name,
  507. quantity: 0,
  508. unit: glj.unit,
  509. specs: glj.specs,
  510. subType: glj.gljType,
  511. basePrice: glj.basePrice,
  512. original_code: glj.code,
  513. shortName: glj.shortName,
  514. serialNo: serialNo,
  515. GLJID: glj.ID,
  516. adjCoe: glj.adjCoe,
  517. materialType:glj.materialType,
  518. materialCoe:glj.materialCoe,
  519. repositoryId: glj.repositoryId
  520. };
  521. if (glj.hasOwnProperty("compilationId")) {
  522. new_glj.from = "cpt";
  523. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  524. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  525. }
  526. }
  527. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  528. new_glj.quantityEXP="QDL";
  529. if(billNode.data.quantity){
  530. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  531. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  532. }
  533. }
  534. gljList.push(new_glj);
  535. }
  536. }
  537. if (gljList.length == 0) {
  538. return;
  539. }
  540. let postData = {
  541. gljList: gljList,
  542. projectID: parseInt(project.ID()),
  543. billsItemID: billsItemID,
  544. rationCount: project.Ration.maxRationID()
  545. }
  546. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  547. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  548. // 更新兄弟节点的序列号
  549. if (selectedSerialNo != null) {
  550. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  551. if (selectIndex + 1 < children.length) {
  552. for (let i = selectIndex + 1; i < children.length; i++) {
  553. children[i].serialNo += gljList.length;
  554. }
  555. }
  556. }
  557. callback(parentNodeID,nextNodeID,data);
  558. }, function () {
  559. $.bootstrapLoading.end();
  560. });
  561. };
  562. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  563. var gljList = [];
  564. var allGLJ = gljOprObj.AllRecode;
  565. GLJSelection.sort();
  566. _.forEach(GLJSelection, function (g) {
  567. var glj = _.find(allGLJ, function (item) {
  568. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  569. return i_key == g;
  570. });
  571. var ration_glj = {
  572. projectID: ration.projectID,
  573. GLJID: glj.ID,
  574. rationID: ration.ID,
  575. billsItemID: ration.billsItemID,
  576. rationItemQuantity: 0,
  577. quantity: 0,
  578. name: glj.name,
  579. code: glj.code,
  580. original_code: glj.code,
  581. unit: glj.unit,
  582. specs: glj.specs,
  583. basePrice: glj.basePrice,
  584. shortName: glj.shortName,
  585. type: glj.gljType,
  586. adjCoe: glj.adjCoe,
  587. createType: 'add',
  588. materialType:glj.materialType,
  589. materialCoe:glj.materialCoe,
  590. repositoryId: glj.repositoryId
  591. }
  592. if (glj.hasOwnProperty("compilationId")) {
  593. ration_glj.from = "cpt";
  594. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  595. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  596. }
  597. }
  598. gljList.push(ration_glj);
  599. });
  600. $.bootstrapLoading.start();
  601. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  602. $.bootstrapLoading.end();
  603. });
  604. };
  605. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  606. var allGLJ = gljOprObj.AllRecode;
  607. var glj = _.find(allGLJ, function (item) {
  608. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  609. return i_key == selectCode;
  610. });
  611. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  612. return callback(null);
  613. }
  614. if (oldData.createType != 'replace') {
  615. oldData.rcode = oldData.code;
  616. oldData.createType = 'replace';
  617. }
  618. oldData.GLJID = glj.ID;
  619. oldData.name = glj.name;
  620. oldData.code = glj.code;
  621. oldData.original_code = glj.code;
  622. oldData.unit = glj.unit;
  623. oldData.specs = glj.specs;
  624. oldData.basePrice = glj.basePrice;
  625. oldData.repositoryId = glj.repositoryId;
  626. oldData.materialType = glj.materialType;
  627. oldData. materialCoe = glj.materialCoe;
  628. if (glj.hasOwnProperty("compilationId")) {
  629. oldData.from = "cpt";
  630. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  631. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  632. }
  633. } else {
  634. oldData.from = "std";
  635. }
  636. $.bootstrapLoading.start();
  637. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  638. $.bootstrapLoading.end();
  639. });
  640. };
  641. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  642. var allGLJ = gljOprObj.AllRecode;
  643. var glj = _.find(allGLJ, function (item) {
  644. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  645. return i_key == selectCode;
  646. });
  647. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  648. return callback(null);
  649. }
  650. var query = {
  651. projectID: oldData.projectID,
  652. code: oldData.code,
  653. name: oldData.name,
  654. unit: oldData.unit,
  655. type: oldData.type
  656. }
  657. if (oldData.specs && oldData.specs != '') {
  658. query.specs = oldData.specs;
  659. }
  660. var doc = {
  661. GLJID: glj.ID,
  662. createType: 'replace',
  663. rationItemQuantity: 0,
  664. name: glj.name,
  665. code: glj.code,
  666. original_code: glj.code,
  667. unit: glj.unit,
  668. specs: glj.specs,
  669. type: glj.gljType,
  670. basePrice: glj.basePrice,
  671. repositoryId: glj.repositoryId,
  672. materialType: glj.materialType, //三材类别
  673. materialCoe: glj.materialCoe,
  674. projectID: oldData.projectID
  675. }
  676. if (oldData.createType == 'replace') {
  677. doc.rcode = oldData.rcode;
  678. } else {
  679. doc.rcode = oldData.code;
  680. }
  681. if (glj.hasOwnProperty("compilationId")) {
  682. doc.from = "cpt";
  683. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  684. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  685. }
  686. } else {
  687. doc.from = "std";
  688. }
  689. $.bootstrapLoading.start();
  690. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc}, callback, function () {
  691. $.bootstrapLoading.end();
  692. });
  693. };
  694. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  695. var gljList = _.filter(this.datas, function (n) {
  696. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  697. });
  698. gljList = sortRationGLJ(gljList);
  699. return gljOprObj.combineWithProjectGlj(gljList);
  700. };
  701. ration_glj.prototype.transferToNodeData = function (data) {
  702. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  703. data.subType = data.type;
  704. data.marketUnitFee = data.marketPrice;
  705. };
  706. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  707. if (ration) {
  708. var projectGLJData = projectObj.project.projectGLJ.datas;
  709. var projectGljs = projectGLJData.gljList;
  710. var mixRatioMap = projectGLJData.mixRatioMap;
  711. var glj = _.find(projectGljs, {'id': ration.projectGLJID});
  712. if (glj) {
  713. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  714. ration.isEstimate = glj.is_evaluate;
  715. }
  716. ration = gljOprObj.setGLJPrice(ration,glj);
  717. ration.basePrice = glj.unit_price.base_price;
  718. ration.marketUnitFee = glj.unit_price.market_price;
  719. ration.isAdd = glj.unit_price.is_add;
  720. var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  721. if (mixRatioMap.hasOwnProperty(connect_index)) {
  722. var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  723. ration.subList = mixRatios;
  724. }
  725. }
  726. }
  727. return ration;
  728. };
  729. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  730. if (node.data[fieldName] !== value) {
  731. if (fieldName == "marketUnitFee") {
  732. var decimal = getDecimal("glj.unitPrice");
  733. var newval = number_util.checkNumberValue(value, decimal);
  734. if (newval) {
  735. fieldName = "marketPrice";
  736. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  737. return;
  738. }
  739. } else {
  740. if(fieldName == "contain"){
  741. if(value==null){
  742. value="";
  743. }else {
  744. var decimal = getDecimal("glj.quantity");
  745. value = number_util.checkNumberValue(value, decimal);
  746. fieldName="customQuantity";//填入自定义消耗
  747. }
  748. }
  749. if (value !== undefined && value !== null) {
  750. if (fieldName == "subType") {
  751. node.data.subType = value;
  752. fieldName = "type";//转换成更新工料机类型
  753. }
  754. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  755. return;
  756. }
  757. }
  758. }
  759. // node.data.subType = value;
  760. projectObj.mainController.refreshTreeNode([node]);
  761. };
  762. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  763. if (this.needShowToTree(data)) {
  764. this.transferToNodeData(data);
  765. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  766. }
  767. };
  768. ration_glj.prototype.needShowToTree = function (data) {
  769. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  770. return true
  771. }
  772. return false
  773. };
  774. ration_glj.prototype.findGLJNodeByID = function (ID) {
  775. return projectObj.project.mainTree.findNode(ID);
  776. };
  777. ration_glj.prototype.findRationNodeByID = function (ID) {
  778. return projectObj.project.mainTree.findNode(ID);
  779. };
  780. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  781. let node = this.findRationNodeByID(ration_glj.rationID);
  782. if (node) {
  783. node.changed = true;
  784. project.calcProgram.calcAndSave(node);
  785. }
  786. };
  787. return new ration_glj(project);
  788. }
  789. };