ration_glj.js 36 KB

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