ration_glj.js 33 KB

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