ration_glj.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. me.refreshTreeNodeIfNeeded(recode);//需刷新主材和设备的工程量和含量
  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. } else {
  353. me.refreshTreeNodeIfNeeded(recode);
  354. }
  355. }
  356. }
  357. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  358. gljOprObj.showRationGLJSheetData();
  359. }
  360. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  361. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  362. if (initShow == true) {
  363. gljOprObj.refreshView();
  364. }
  365. $.bootstrapLoading.end();
  366. });
  367. }
  368. var query = {
  369. 'ID': recode.ID,
  370. 'projectID': recode.projectID,
  371. 'rationID': recode.rationID
  372. };
  373. var priceInfo = {
  374. base_price: recode.basePrice,
  375. market_price: recode.marketPrice
  376. }
  377. var doc = {};
  378. doc[updateField] = newval;
  379. if (updateField == "type") {
  380. doc.shortName = projectObj.project.projectGLJ.getShortNameByID[newval];
  381. }
  382. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  383. query: query,
  384. doc: doc,
  385. priceInfo: priceInfo
  386. }, callback, function (err) {
  387. $.bootstrapLoading.end();
  388. });
  389. }
  390. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  391. var me = this;
  392. data.glj_result.forEach(function (item) {
  393. me.refreshEachItme(item.doc, item.query);
  394. })
  395. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  396. };
  397. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  398. var nodes = [];
  399. var node = _.find(projectObj.project.mainTree.items, function (n) {
  400. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  401. })
  402. if (node) {
  403. node.data.adjustState = adjustState;
  404. nodes.push(node);
  405. }
  406. if (rnode) {
  407. nodes.push(rnode);
  408. }
  409. projectObj.mainController.refreshTreeNode(nodes);
  410. };
  411. ration_glj.prototype.getGLJData = function (cb) {
  412. CommonAjax.get('/rationGlj/getGLJData', function (data) {
  413. cb(data);
  414. })
  415. };
  416. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  417. let gljList = [];
  418. let allGLJ = gljOprObj.AllRecode;
  419. let billsItemID = null;
  420. let serialNo = 0;
  421. let selectedSerialNo = null;
  422. let nextNodeID = null;
  423. let parentNodeID = null;
  424. let children = [];
  425. if (selected.sourceType === project.Bills.getSourceType()) {
  426. billsItemID = selected.data.ID;
  427. parentNodeID = selected.getID();
  428. nextNodeID = selected.tree.rootID();
  429. } else {
  430. billsItemID = selected.data.billsItemID;
  431. serialNo = selected.data.serialNo;
  432. selectedSerialNo = selected.data.serialNo;
  433. nextNodeID = selected.getNextSiblingID();
  434. parentNodeID = selected.getParentID();
  435. }
  436. children = project.Ration.getBillsSortRation(billsItemID);
  437. serialNo == 0 ? serialNo = children.length : "";
  438. for (let con_key of GLJSelection) {
  439. var glj = _.find(allGLJ, function (item) {
  440. let i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
  441. return i_key == con_key;
  442. });
  443. if (glj) {
  444. serialNo += 1;
  445. let new_glj = {
  446. ID: project.Ration.getNewRationID(),
  447. projectID: parseInt(project.ID()),
  448. billsItemID: billsItemID,
  449. type: rationType.gljRation,
  450. code: glj.code,
  451. name: glj.name,
  452. quantity: 0,
  453. unit: glj.unit,
  454. specs: glj.specs,
  455. subType: glj.gljType,
  456. basePrice: glj.basePrice,
  457. original_code: glj.code,
  458. shortName: glj.shortName,
  459. serialNo: serialNo,
  460. GLJID: glj.ID,
  461. adjCoe: glj.adjCoe,
  462. repositoryId: glj.repositoryId
  463. }
  464. if (glj.hasOwnProperty("compilationId")) {
  465. new_glj.from = "cpt";
  466. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  467. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  468. }
  469. }
  470. gljList.push(new_glj);
  471. }
  472. }
  473. if (gljList.length == 0) {
  474. return;
  475. }
  476. let postData = {
  477. gljList: gljList,
  478. projectID: parseInt(project.ID()),
  479. billsItemID: billsItemID,
  480. rationCount: project.Ration.maxRationID()
  481. }
  482. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  483. $.bootstrapLoading.start();
  484. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  485. console.log(data);
  486. // 更新兄弟节点的序列号
  487. if (selectedSerialNo != null) {
  488. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  489. if (selectIndex + 1 < children.length) {
  490. for (let i = selectIndex + 1; i < children.length; i++) {
  491. children[i].serialNo += gljList.length;
  492. }
  493. }
  494. }
  495. for (let r_glj of data) {
  496. r_glj.marketUnitFee = r_glj.marketPrice;
  497. r_glj.quantity = r_glj.quantity + "";
  498. project.Ration.datas.push(r_glj);
  499. let newNode = project.mainTree.insert(parentNodeID, nextNodeID);
  500. newNode.source = r_glj;
  501. newNode.sourceType = project.Ration.getSourceType();
  502. newNode.data = r_glj;
  503. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  504. }
  505. let parentNode = project.mainTree.nodes[project.mainTree.prefix + parentNodeID];
  506. project.calcProgram.calcLeafAndSave(parentNode);//计算父级清单的所有子节点
  507. //this.nodes[this.prefix + parentID];
  508. callback();
  509. $.bootstrapLoading.end();
  510. }, function () {
  511. $.bootstrapLoading.end();
  512. });
  513. };
  514. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  515. var gljList = [];
  516. var allGLJ = gljOprObj.AllRecode;
  517. GLJSelection.sort();
  518. _.forEach(GLJSelection, function (g) {
  519. var glj = _.find(allGLJ, function (item) {
  520. var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
  521. return i_key == g;
  522. });
  523. var ration_glj = {
  524. projectID: ration.projectID,
  525. GLJID: glj.ID,
  526. rationID: ration.ID,
  527. billsItemID: ration.billsItemID,
  528. rationItemQuantity: 0,
  529. quantity: 0,
  530. name: glj.name,
  531. code: glj.code,
  532. original_code: glj.code,
  533. unit: glj.unit,
  534. specs: glj.specs,
  535. basePrice: glj.basePrice,
  536. shortName: glj.shortName,
  537. type: glj.gljType,
  538. adjCoe: glj.adjCoe,
  539. createType: 'add',
  540. repositoryId: glj.repositoryId
  541. }
  542. if (glj.hasOwnProperty("compilationId")) {
  543. ration_glj.from = "cpt";
  544. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  545. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  546. }
  547. }
  548. gljList.push(ration_glj);
  549. });
  550. $.bootstrapLoading.start();
  551. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  552. $.bootstrapLoading.end();
  553. });
  554. };
  555. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  556. var allGLJ = gljOprObj.AllRecode;
  557. var glj = _.find(allGLJ, function (item) {
  558. var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
  559. return i_key == selectCode;
  560. });
  561. if (selectCode == gljOprObj.getIndex(oldData, ['code', 'name', 'specs', 'unit', 'type'])) {
  562. return callback(null);
  563. }
  564. if (oldData.createType != 'replace') {
  565. oldData.rcode = oldData.code;
  566. oldData.createType = 'replace';
  567. }
  568. oldData.GLJID = glj.ID;
  569. oldData.name = glj.name;
  570. oldData.code = glj.code;
  571. oldData.original_code = glj.code;
  572. oldData.unit = glj.unit;
  573. oldData.specs = glj.specs;
  574. oldData.basePrice = glj.basePrice;
  575. oldData.repositoryId = glj.repositoryId;
  576. if (glj.hasOwnProperty("compilationId")) {
  577. oldData.from = "cpt";
  578. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  579. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  580. }
  581. } else {
  582. oldData.from = "std";
  583. }
  584. $.bootstrapLoading.start();
  585. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  586. $.bootstrapLoading.end();
  587. });
  588. };
  589. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  590. var allGLJ = gljOprObj.AllRecode;
  591. var glj = _.find(allGLJ, function (item) {
  592. var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
  593. return i_key == selectCode;
  594. });
  595. if (selectCode == gljOprObj.getIndex(oldData, ['code', 'name', 'specs', 'unit', 'type'])) {
  596. return callback(null);
  597. }
  598. var query = {
  599. projectID: oldData.projectID,
  600. code: oldData.code,
  601. name: oldData.name,
  602. unit: oldData.unit,
  603. type: oldData.type
  604. }
  605. if (oldData.specs && oldData.specs != '') {
  606. query.specs = oldData.specs;
  607. }
  608. var doc = {
  609. GLJID: glj.ID,
  610. createType: 'replace',
  611. rationItemQuantity: 0,
  612. name: glj.name,
  613. code: glj.code,
  614. original_code: glj.code,
  615. unit: glj.unit,
  616. specs: glj.specs,
  617. type: glj.gljType,
  618. basePrice: glj.basePrice,
  619. repositoryId: glj.repositoryId,
  620. projectID: oldData.projectID
  621. }
  622. if (oldData.createType == 'replace') {
  623. doc.rcode = oldData.rcode;
  624. } else {
  625. doc.rcode = oldData.code;
  626. }
  627. if (glj.hasOwnProperty("compilationId")) {
  628. doc.from = "cpt";
  629. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  630. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  631. }
  632. } else {
  633. doc.from = "std";
  634. }
  635. $.bootstrapLoading.start();
  636. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc}, callback, function () {
  637. $.bootstrapLoading.end();
  638. });
  639. };
  640. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  641. var gljList = _.filter(this.datas, function (n) {
  642. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  643. });
  644. gljList = sortRationGLJ(gljList);
  645. return gljOprObj.combineWithProjectGlj(gljList);
  646. };
  647. ration_glj.prototype.transferToNodeData = function (data) {
  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, ['code', 'name', 'specs', 'unit', 'type'])
  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 (value !== undefined && value !== null) {
  688. if (fieldName == "subType") {
  689. node.data.subType = value;
  690. fieldName = "type";//转换成更新工料机类型
  691. }
  692. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  693. return;
  694. }
  695. }
  696. // node.data.subType = value;
  697. projectObj.mainController.refreshTreeNode([node]);
  698. };
  699. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  700. if (this.needShowToTree(data)) {
  701. this.transferToNodeData(data);
  702. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  703. }
  704. };
  705. ration_glj.prototype.needShowToTree = function (data) {
  706. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  707. return true
  708. }
  709. return false
  710. };
  711. ration_glj.prototype.findGLJNodeByID = function (ID) {
  712. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应的树节点
  713. return n.sourceType == ModuleNames.ration_glj && n.data.ID == ID;
  714. });
  715. return node;
  716. };
  717. ration_glj.prototype.findRationNodeByID = function (ID) {
  718. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应定额的树节点
  719. return n.sourceType == ModuleNames.ration && n.data.ID == ID;
  720. });
  721. return node;
  722. };
  723. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及期父节点
  724. let node = this.findRationNodeByID(ration_glj.rationID);
  725. if (node) {
  726. project.calcProgram.calculate(node);
  727. project.calcProgram.saveNode(node);
  728. }
  729. };
  730. return new ration_glj(project);
  731. }
  732. };