ration_glj.js 36 KB

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