ration_glj.js 33 KB

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