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. 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. if(controller.tree.m_delete(deleteNodes)){
  199. let rowCount = deleteNodes.length;
  200. controller.sheet.deleteRows(deleteNodes[0].serialNo(), rowCount);
  201. }
  202. }
  203. };
  204. ration_glj.prototype.refreshAfterUpdate = function (data) {
  205. var me = this;
  206. var rationID=null;
  207. if (data.quantityRefresh) {
  208. data.glj_result.forEach(function (item) {
  209. rationID = me.refreshEachItme(item.doc, item.query);
  210. })
  211. } else {
  212. rationID = me.refreshEachItme(data.doc, data.query);
  213. }
  214. gljOprObj.showRationGLJSheetData(true);
  215. this.reCalcWhenGLJChange({rationID:rationID});
  216. };
  217. ration_glj.prototype.refreshEachItme = function (doc, query) {
  218. var glj_list = projectObj.project.ration_glj.datas;
  219. var glj_index = _.findIndex(glj_list, (glj) => {
  220. return glj.ID == query.ID;
  221. })
  222. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  223. return sd.ID==query.ID;
  224. })*/
  225. _.forEach(doc, function (n, key) {
  226. glj_list[glj_index][key] = n;
  227. });
  228. return glj_list[glj_index].rationID;
  229. };
  230. ration_glj.prototype.refreshAfterDelete = function (data) {
  231. var me = projectObj.project.ration_glj;
  232. var glj_list = me.datas;
  233. var oldData = _.remove(glj_list, data.query);
  234. _.remove(gljOprObj.sheetData, data.query);
  235. gljOprObj.showRationGLJSheetData();
  236. projectObj.project.projectGLJ.loadData();
  237. var rationNode = null;
  238. var next = null;
  239. var selected = projectObj.project.mainTree.selected;
  240. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  241. rationNode = selected;
  242. } else if (selected.sourceType == ModuleNames.ration_glj) {
  243. rationNode = selected.parent;
  244. next = true;
  245. }
  246. rationNode.data.adjustState = data.adjustState;
  247. projectObj.mainController.refreshTreeNode([rationNode]);
  248. for (let o of oldData) {
  249. if (this.needShowToTree(o)) {
  250. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  251. projectObj.mainController.deleteNode(node, next);
  252. }
  253. }
  254. };
  255. // CSL,2017.05.09
  256. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  257. this.project.beginUpdate('modifyQuantity');
  258. data.quantity = newQuantity;
  259. data.customQuantity = newQuantity;
  260. data.updateType = 'ut_update';
  261. this.project.push(this.getSourceType, data);
  262. this.project.endUpdate();
  263. };
  264. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  265. this.project.beginUpdate('modifyPrice');
  266. data.price = newPrice;
  267. data.updateType = 'ut_update';
  268. this.project.push(this.getSourceType, data);
  269. this.project.endUpdate();
  270. };
  271. ration_glj.prototype.deleteGLJ = function (data) {
  272. this.project.beginUpdate('deleteGLJ');
  273. data.customQuantity = 0;
  274. data.quantity = 0;
  275. data.rationItemQuantity = 0;
  276. data.updateType = 'ut_update';
  277. this.project.push(this.getSourceType, data);
  278. this.project.endUpdate();
  279. };
  280. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  281. var souceTypeList = [];
  282. var criteriaDataList = [];
  283. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  284. let criteria = {};
  285. criteria.ration_glj_list = [];
  286. for (let i = 0; i < data.rationGljList.length; i++) {
  287. let temdata = data.rationGljList[i];
  288. let newGLJ = {};
  289. newGLJ.projectID = parseInt(newRation.projectID);
  290. newGLJ.GLJID = temdata.gljId;
  291. newGLJ.rationID = newRation.ID;
  292. newGLJ.billsItemID = newRation.billsItemID,
  293. newGLJ.rationItemQuantity = temdata.consumeAmt;
  294. newGLJ.quantity = temdata.consumeAmt;
  295. newGLJ.glj_repository_id = data.rationRepId;
  296. criteria.ration_glj_list.push(newGLJ);
  297. }
  298. criteria.updateType = 'ut_create';
  299. souceTypeList.push(this.getSourceType());
  300. criteriaDataList.push(criteria);
  301. }
  302. var ration_coe = projectObj.project.ration_coe;
  303. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  304. souceTypeList.push(ration_coe.getSourceType());
  305. criteriaDataList.push(rationCoeData);
  306. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  307. };
  308. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  309. var updateData = [];
  310. updateData.push({
  311. 'deleteType': 'RATION',
  312. 'updateType': 'ut_delete',
  313. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  314. });
  315. return updateData;
  316. };
  317. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  318. var updateData = [];
  319. datas.forEach(function (deleteData) {
  320. if (deleteData.type == 'delete') {
  321. var billData = deleteData.data;
  322. updateData.push({
  323. 'deleteType': 'BILL',
  324. 'updateType': 'ut_delete',
  325. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  326. });
  327. }
  328. })
  329. return updateData;
  330. };
  331. ration_glj.prototype.deleteByRation = function (ration) {
  332. var glj_list = projectObj.project.ration_glj.datas;
  333. _.remove(glj_list,{'rationID':ration.ID});
  334. };
  335. ration_glj.prototype.deleteByBills = function (deleteData) {
  336. var rationList = projectObj.project.Ration.datas;
  337. var deleteRationList = [];
  338. for (var i = 0; i < deleteData.length; i++) {
  339. if (deleteData[i].type == 'delete') {
  340. var billID = deleteData[i].data.ID;
  341. var raList = _.filter(rationList, (ration) => {
  342. return ration.billsItemID == billID;
  343. });
  344. deleteRationList = deleteRationList.concat(raList);
  345. }
  346. }
  347. for (var i = 0; i < deleteRationList.length; i++) {
  348. this.deleteByRation(deleteRationList[i]);
  349. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  350. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  351. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  352. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  353. }
  354. }
  355. ration_glj.prototype.updataOrdelete = function (row) {
  356. var updateData = null;
  357. if (row.rationItemQuantity == 0) {
  358. updateData = this.getUpdateData('ut_delete', {
  359. 'ID': row.ID,
  360. 'projectID': row.projectID
  361. }, {rationID: row.rationID});
  362. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  363. } else {
  364. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  365. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  366. }
  367. };
  368. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  369. var updateData = [];
  370. var newobj = {
  371. 'updateType': type,
  372. 'query': query,
  373. }
  374. if (doc) {
  375. newobj['doc'] = doc;
  376. }
  377. if (callfunction) {
  378. newobj['updateFunction'] = callfunction;
  379. }
  380. updateData.push(newobj);
  381. return updateData;
  382. };
  383. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  384. var me = this;
  385. $.bootstrapLoading.start();
  386. var callback = function (data) {
  387. let initShow = false;//是否需要表格初始化显示
  388. if (updateField == 'customQuantity') {
  389. me.refreshAfterQuantityUpdate(data, node);
  390. } else {
  391. var doc = data.doc;
  392. for (var key in doc) {
  393. recode[key] = doc[key];
  394. }
  395. if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
  396. me.updateRationAdjustState(data.adjustState, recode.rationID, node);
  397. }
  398. if (recode.subList && recode.subList.length > 0) {
  399. initShow = true;
  400. }
  401. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  402. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  403. projectObj.mainController.deleteNode(node, true);
  404. }
  405. }
  406. }
  407. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  408. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  409. gljOprObj.showRationGLJSheetData();
  410. }
  411. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  412. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  413. if (initShow == true) {
  414. gljOprObj.refreshView();
  415. }
  416. $.bootstrapLoading.end();
  417. });
  418. }
  419. var query = {
  420. 'ID': recode.ID,
  421. 'projectID': recode.projectID,
  422. 'rationID': recode.rationID
  423. };
  424. var priceInfo = {
  425. base_price: recode.basePrice,
  426. market_price: recode.marketPrice
  427. }
  428. var doc = {};
  429. doc[updateField] = newval;
  430. if (updateField == "type") {
  431. doc.shortName = projectObj.project.projectGLJ.getShortNameByID(newval);
  432. }
  433. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  434. query: query,
  435. doc: doc,
  436. priceInfo: priceInfo
  437. }, callback, function (err) {
  438. $.bootstrapLoading.end();
  439. });
  440. }
  441. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  442. var me = this;
  443. data.glj_result.forEach(function (item) {
  444. me.refreshEachItme(item.doc, item.query);
  445. })
  446. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  447. };
  448. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  449. var nodes = [];
  450. var node = _.find(projectObj.project.mainTree.items, function (n) {
  451. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  452. })
  453. if (node) {
  454. node.data.adjustState = adjustState;
  455. nodes.push(node);
  456. }
  457. if (rnode) {
  458. nodes.push(rnode);
  459. }
  460. projectObj.mainController.refreshTreeNode(nodes);
  461. };
  462. ration_glj.prototype.getGLJData = function (cb) {
  463. CommonAjax.get('/rationGlj/getGLJData', function (data) {
  464. cb(data);
  465. })
  466. };
  467. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  468. let gljList = [];
  469. let allGLJ = gljOprObj.AllRecode;
  470. let billsItemID = null;
  471. let serialNo = 0;
  472. let selectedSerialNo = null;
  473. let nextNodeID = null;
  474. let parentNodeID = null;
  475. let children = [];
  476. if (selected.sourceType === project.Bills.getSourceType()) {
  477. billsItemID = selected.data.ID;
  478. parentNodeID = selected.getID();
  479. nextNodeID = selected.tree.rootID();
  480. } else {
  481. billsItemID = selected.data.billsItemID;
  482. serialNo = selected.data.serialNo;
  483. selectedSerialNo = selected.data.serialNo;
  484. nextNodeID = selected.getNextSiblingID();
  485. parentNodeID = selected.getParentID();
  486. }
  487. children = project.Ration.getBillsSortRation(billsItemID);
  488. serialNo == 0 ? serialNo = children.length : "";
  489. for (let con_key of GLJSelection) {
  490. var glj = _.find(allGLJ, function (item) {
  491. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  492. return i_key == con_key;
  493. });
  494. if (glj) {
  495. serialNo += 1;
  496. let new_glj = {
  497. ID: project.Ration.getNewRationID(),
  498. projectID: parseInt(project.ID()),
  499. billsItemID: billsItemID,
  500. type: rationType.gljRation,
  501. code: glj.code,
  502. name: glj.name,
  503. quantity: 0,
  504. unit: glj.unit,
  505. specs: glj.specs,
  506. subType: glj.gljType,
  507. basePrice: glj.basePrice,
  508. original_code: glj.code,
  509. shortName: glj.shortName,
  510. serialNo: serialNo,
  511. GLJID: glj.ID,
  512. adjCoe: glj.adjCoe,
  513. repositoryId: glj.repositoryId
  514. }
  515. if (glj.hasOwnProperty("compilationId")) {
  516. new_glj.from = "cpt";
  517. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  518. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  519. }
  520. }
  521. gljList.push(new_glj);
  522. }
  523. }
  524. if (gljList.length == 0) {
  525. return;
  526. }
  527. let postData = {
  528. gljList: gljList,
  529. projectID: parseInt(project.ID()),
  530. billsItemID: billsItemID,
  531. rationCount: project.Ration.maxRationID()
  532. }
  533. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  534. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  535. // 更新兄弟节点的序列号
  536. if (selectedSerialNo != null) {
  537. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  538. if (selectIndex + 1 < children.length) {
  539. for (let i = selectIndex + 1; i < children.length; i++) {
  540. children[i].serialNo += gljList.length;
  541. }
  542. }
  543. }
  544. /* let newNode=null;
  545. for (let r_glj of data) {
  546. r_glj.marketUnitFee = r_glj.marketPrice;
  547. r_glj.quantity = r_glj.quantity + "";
  548. project.Ration.datas.push(r_glj);
  549. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  550. newNode.source = r_glj;
  551. newNode.sourceType = project.Ration.getSourceType();
  552. newNode.data = r_glj;
  553. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  554. }*/
  555. //this.nodes[this.prefix + parentID];
  556. callback(parentNodeID,nextNodeID,data);
  557. }, function () {
  558. $.bootstrapLoading.end();
  559. });
  560. };
  561. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  562. var gljList = [];
  563. var allGLJ = gljOprObj.AllRecode;
  564. GLJSelection.sort();
  565. _.forEach(GLJSelection, function (g) {
  566. var glj = _.find(allGLJ, function (item) {
  567. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  568. return i_key == g;
  569. });
  570. var ration_glj = {
  571. projectID: ration.projectID,
  572. GLJID: glj.ID,
  573. rationID: ration.ID,
  574. billsItemID: ration.billsItemID,
  575. rationItemQuantity: 0,
  576. quantity: 0,
  577. name: glj.name,
  578. code: glj.code,
  579. original_code: glj.code,
  580. unit: glj.unit,
  581. specs: glj.specs,
  582. basePrice: glj.basePrice,
  583. shortName: glj.shortName,
  584. type: glj.gljType,
  585. adjCoe: glj.adjCoe,
  586. createType: 'add',
  587. repositoryId: glj.repositoryId
  588. }
  589. if (glj.hasOwnProperty("compilationId")) {
  590. ration_glj.from = "cpt";
  591. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  592. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  593. }
  594. }
  595. gljList.push(ration_glj);
  596. });
  597. $.bootstrapLoading.start();
  598. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  599. $.bootstrapLoading.end();
  600. });
  601. };
  602. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  603. var allGLJ = gljOprObj.AllRecode;
  604. var glj = _.find(allGLJ, function (item) {
  605. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  606. return i_key == selectCode;
  607. });
  608. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  609. return callback(null);
  610. }
  611. if (oldData.createType != 'replace') {
  612. oldData.rcode = oldData.code;
  613. oldData.createType = 'replace';
  614. }
  615. oldData.GLJID = glj.ID;
  616. oldData.name = glj.name;
  617. oldData.code = glj.code;
  618. oldData.original_code = glj.code;
  619. oldData.unit = glj.unit;
  620. oldData.specs = glj.specs;
  621. oldData.basePrice = glj.basePrice;
  622. oldData.repositoryId = glj.repositoryId;
  623. if (glj.hasOwnProperty("compilationId")) {
  624. oldData.from = "cpt";
  625. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  626. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  627. }
  628. } else {
  629. oldData.from = "std";
  630. }
  631. $.bootstrapLoading.start();
  632. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  633. $.bootstrapLoading.end();
  634. });
  635. };
  636. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  637. var allGLJ = gljOprObj.AllRecode;
  638. var glj = _.find(allGLJ, function (item) {
  639. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  640. return i_key == selectCode;
  641. });
  642. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  643. return callback(null);
  644. }
  645. var query = {
  646. projectID: oldData.projectID,
  647. code: oldData.code,
  648. name: oldData.name,
  649. unit: oldData.unit,
  650. type: oldData.type
  651. }
  652. if (oldData.specs && oldData.specs != '') {
  653. query.specs = oldData.specs;
  654. }
  655. var doc = {
  656. GLJID: glj.ID,
  657. createType: 'replace',
  658. rationItemQuantity: 0,
  659. name: glj.name,
  660. code: glj.code,
  661. original_code: glj.code,
  662. unit: glj.unit,
  663. specs: glj.specs,
  664. type: glj.gljType,
  665. basePrice: glj.basePrice,
  666. repositoryId: glj.repositoryId,
  667. projectID: oldData.projectID
  668. }
  669. if (oldData.createType == 'replace') {
  670. doc.rcode = oldData.rcode;
  671. } else {
  672. doc.rcode = oldData.code;
  673. }
  674. if (glj.hasOwnProperty("compilationId")) {
  675. doc.from = "cpt";
  676. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  677. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  678. }
  679. } else {
  680. doc.from = "std";
  681. }
  682. $.bootstrapLoading.start();
  683. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc}, callback, function () {
  684. $.bootstrapLoading.end();
  685. });
  686. };
  687. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  688. var gljList = _.filter(this.datas, function (n) {
  689. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  690. });
  691. gljList = sortRationGLJ(gljList);
  692. return gljOprObj.combineWithProjectGlj(gljList);
  693. };
  694. ration_glj.prototype.transferToNodeData = function (data) {
  695. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  696. data.subType = data.type;
  697. data.marketUnitFee = data.marketPrice;
  698. };
  699. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  700. if (ration) {
  701. var projectGLJData = projectObj.project.projectGLJ.datas;
  702. var projectGljs = projectGLJData.gljList;
  703. var mixRatioMap = projectGLJData.mixRatioMap;
  704. var glj = _.find(projectGljs, {'id': ration.projectGLJID});
  705. if (glj) {
  706. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  707. ration.isEstimate = glj.is_evaluate;
  708. }
  709. ration = gljOprObj.setGLJPrice(ration,glj);
  710. ration.basePrice = glj.unit_price.base_price;
  711. ration.marketUnitFee = glj.unit_price.market_price;
  712. ration.isAdd = glj.unit_price.is_add;
  713. var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  714. if (mixRatioMap.hasOwnProperty(connect_index)) {
  715. var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  716. ration.subList = mixRatios;
  717. }
  718. }
  719. }
  720. return ration;
  721. };
  722. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  723. if (node.data[fieldName] === value) {
  724. return;
  725. }
  726. if (fieldName == "marketUnitFee") {
  727. var decimal = getDecimal("glj.unitPrice");
  728. var newval = number_util.checkNumberValue(value, decimal);
  729. if (newval) {
  730. fieldName = "marketPrice";
  731. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  732. return;
  733. }
  734. } else {
  735. if(fieldName == "contain"){
  736. if(value==null){
  737. value="";
  738. }else {
  739. var decimal = getDecimal("glj.quantity");
  740. value = number_util.checkNumberValue(value, decimal);
  741. fieldName="customQuantity";//填入自定义消耗
  742. }
  743. }
  744. if (value !== undefined && value !== null) {
  745. if (fieldName == "subType") {
  746. node.data.subType = value;
  747. fieldName = "type";//转换成更新工料机类型
  748. }
  749. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  750. return;
  751. }
  752. }
  753. // node.data.subType = value;
  754. projectObj.mainController.refreshTreeNode([node]);
  755. };
  756. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  757. if (this.needShowToTree(data)) {
  758. this.transferToNodeData(data);
  759. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  760. }
  761. };
  762. ration_glj.prototype.needShowToTree = function (data) {
  763. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  764. return true
  765. }
  766. return false
  767. };
  768. ration_glj.prototype.findGLJNodeByID = function (ID) {
  769. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应的树节点
  770. return n.sourceType == ModuleNames.ration_glj && n.data.ID == ID;
  771. });
  772. return node;
  773. };
  774. ration_glj.prototype.findRationNodeByID = function (ID) {
  775. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应定额的树节点
  776. return n.sourceType == ModuleNames.ration && n.data.ID == ID;
  777. });
  778. return node;
  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. };