ration_glj.js 33 KB

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