ration_glj.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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, billQuantity) {
  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. result = gljOprObj.combineWithProjectGlj(result);
  79. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  80. let oneBill = Array.from(result);
  81. for (let glj of oneBill){
  82. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  83. };
  84. return oneBill;
  85. }
  86. // 提交数据后返回数据处理
  87. ration_glj.prototype.doAfterUpdate = function (err, data) {
  88. var me = this;
  89. if (!err) {
  90. if (data.updateTpye == 'ut_update') {
  91. me.refreshAfterUpdate(data);
  92. } else if (data.updateTpye == 'ut_delete') {
  93. me.refreshAfterDelete(data);
  94. } else {
  95. me.refreshAfterSave(data);
  96. }
  97. }
  98. projectObj.project.projectGLJ.loadData();
  99. };
  100. ration_glj.prototype.refreshAfterSave = function (data) {
  101. let me = projectObj.project.ration_glj;
  102. let neRecodes = [];
  103. if (data) {
  104. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  105. neRecodes = data.showDatas;
  106. gljOprObj.sheetData = neRecodes;
  107. }
  108. if (me.datas && Array.isArray(me.datas)) {
  109. if (data) {
  110. me.datas = me.datas.concat(neRecodes);
  111. }
  112. } else {
  113. me.datas = neRecodes;
  114. }
  115. project.projectGLJ.loadData(function () {
  116. gljOprObj.showRationGLJSheetData(true);
  117. //add to mainTree;
  118. me.addToMainTree(neRecodes);
  119. let rationID = neRecodes[0].rationID;
  120. let node = project.mainTree.nodes['id_' + rationID];
  121. if(isDef(node)){
  122. project.calcProgram.calcAndSave(node);
  123. }
  124. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  125. calcProgramObj.showData(node, false);
  126. }
  127. });
  128. };
  129. ration_glj.prototype.addToMainTree = function (datas) {
  130. datas = sortRationGLJ(datas);
  131. for (let data of datas) {
  132. if (this.needShowToTree(data)) {
  133. this.transferToNodeData(data);
  134. let parentNode = _.find(projectObj.project.mainTree.items, function (n) {//找父节点
  135. return n.sourceType == ModuleNames.ration && n.data.ID == data.rationID;
  136. });
  137. if (parentNode) {
  138. let nextNodeID = null;
  139. if (parentNode.children.length > 0) {
  140. for (let br of parentNode.children) {
  141. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  142. nextNodeID = br.getID();
  143. }
  144. }
  145. }
  146. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  147. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  148. newNode.source = data;
  149. newNode.sourceType = this.getSourceType();
  150. newNode.data = data;
  151. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  152. }
  153. }
  154. }
  155. };
  156. ration_glj.prototype.refreshAfterUpdate = function (data) {
  157. var me = this;
  158. var rationID=null;
  159. if (data.quantityRefresh) {
  160. data.glj_result.forEach(function (item) {
  161. rationID = me.refreshEachItme(item.doc, item.query);
  162. })
  163. } else {
  164. rationID = me.refreshEachItme(data.doc, data.query);
  165. }
  166. gljOprObj.showRationGLJSheetData(true);
  167. this.reCalcWhenGLJChange({rationID:rationID});
  168. };
  169. ration_glj.prototype.refreshEachItme = function (doc, query) {
  170. var glj_list = projectObj.project.ration_glj.datas;
  171. var glj_index = _.findIndex(glj_list, (glj) => {
  172. return glj.ID == query.ID;
  173. })
  174. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  175. return sd.ID==query.ID;
  176. })*/
  177. _.forEach(doc, function (n, key) {
  178. glj_list[glj_index][key] = n;
  179. });
  180. return glj_list[glj_index].rationID;
  181. };
  182. ration_glj.prototype.refreshAfterDelete = function (data) {
  183. var me = projectObj.project.ration_glj;
  184. var glj_list = me.datas;
  185. var oldData = _.remove(glj_list, data.query);
  186. _.remove(gljOprObj.sheetData, data.query);
  187. gljOprObj.showRationGLJSheetData();
  188. projectObj.project.projectGLJ.loadData();
  189. var rationNode = null;
  190. var next = null;
  191. var selected = projectObj.project.mainTree.selected;
  192. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  193. rationNode = selected;
  194. } else if (selected.sourceType == ModuleNames.ration_glj) {
  195. rationNode = selected.parent;
  196. next = true;
  197. }
  198. rationNode.data.adjustState = data.adjustState;
  199. projectObj.mainController.refreshTreeNode([rationNode]);
  200. for (let o of oldData) {
  201. if (this.needShowToTree(o)) {
  202. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  203. projectObj.mainController.deleteNode(node, next);
  204. }
  205. }
  206. };
  207. // CSL,2017.05.09
  208. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  209. this.project.beginUpdate('modifyQuantity');
  210. data.quantity = newQuantity;
  211. data.customQuantity = newQuantity;
  212. data.updateType = 'ut_update';
  213. this.project.push(this.getSourceType, data);
  214. this.project.endUpdate();
  215. };
  216. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  217. this.project.beginUpdate('modifyPrice');
  218. data.price = newPrice;
  219. data.updateType = 'ut_update';
  220. this.project.push(this.getSourceType, data);
  221. this.project.endUpdate();
  222. };
  223. ration_glj.prototype.deleteGLJ = function (data) {
  224. this.project.beginUpdate('deleteGLJ');
  225. data.customQuantity = 0;
  226. data.quantity = 0;
  227. data.rationItemQuantity = 0;
  228. data.updateType = 'ut_update';
  229. this.project.push(this.getSourceType, data);
  230. this.project.endUpdate();
  231. };
  232. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  233. var souceTypeList = [];
  234. var criteriaDataList = [];
  235. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  236. let criteria = {};
  237. criteria.ration_glj_list = [];
  238. for (let i = 0; i < data.rationGljList.length; i++) {
  239. let temdata = data.rationGljList[i];
  240. let newGLJ = {};
  241. newGLJ.projectID = parseInt(newRation.projectID);
  242. newGLJ.GLJID = temdata.gljId;
  243. newGLJ.rationID = newRation.ID;
  244. newGLJ.billsItemID = newRation.billsItemID,
  245. newGLJ.rationItemQuantity = temdata.consumeAmt;
  246. newGLJ.quantity = temdata.consumeAmt;
  247. newGLJ.glj_repository_id = data.rationRepId;
  248. criteria.ration_glj_list.push(newGLJ);
  249. }
  250. criteria.updateType = 'ut_create';
  251. souceTypeList.push(this.getSourceType());
  252. criteriaDataList.push(criteria);
  253. }
  254. var ration_coe = projectObj.project.ration_coe;
  255. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  256. souceTypeList.push(ration_coe.getSourceType());
  257. criteriaDataList.push(rationCoeData);
  258. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  259. };
  260. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  261. var updateData = [];
  262. updateData.push({
  263. 'deleteType': 'RATION',
  264. 'updateType': 'ut_delete',
  265. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  266. });
  267. return updateData;
  268. };
  269. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  270. var updateData = [];
  271. datas.forEach(function (deleteData) {
  272. if (deleteData.type == 'delete') {
  273. var billData = deleteData.data;
  274. updateData.push({
  275. 'deleteType': 'BILL',
  276. 'updateType': 'ut_delete',
  277. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  278. });
  279. }
  280. })
  281. return updateData;
  282. };
  283. ration_glj.prototype.deleteByRation = function (ration) {
  284. var glj_list = projectObj.project.ration_glj.datas;
  285. var newList = _.filter(glj_list, (glj) => {
  286. return glj.rationID != ration.ID;
  287. });
  288. if (newList != undefined) {
  289. projectObj.project.ration_glj.datas = newList;
  290. }
  291. };
  292. ration_glj.prototype.deleteByBills = function (deleteData) {
  293. var rationList = projectObj.project.Ration.datas;
  294. var deleteRationList = [];
  295. for (var i = 0; i < deleteData.length; i++) {
  296. if (deleteData[i].type == 'delete') {
  297. var billID = deleteData[i].data.ID;
  298. var raList = _.filter(rationList, (ration) => {
  299. return ration.billsItemID == billID;
  300. });
  301. deleteRationList = deleteRationList.concat(raList);
  302. }
  303. }
  304. for (var i = 0; i < deleteRationList.length; i++) {
  305. this.deleteByRation(deleteRationList[i]);
  306. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  307. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  308. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  309. }
  310. }
  311. ration_glj.prototype.updataOrdelete = function (row) {
  312. var updateData = null;
  313. if (row.rationItemQuantity == 0) {
  314. updateData = this.getUpdateData('ut_delete', {
  315. 'ID': row.ID,
  316. 'projectID': row.projectID
  317. }, {rationID: row.rationID});
  318. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  319. } else {
  320. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  321. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  322. }
  323. };
  324. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  325. var updateData = [];
  326. var newobj = {
  327. 'updateType': type,
  328. 'query': query,
  329. }
  330. if (doc) {
  331. newobj['doc'] = doc;
  332. }
  333. if (callfunction) {
  334. newobj['updateFunction'] = callfunction;
  335. }
  336. updateData.push(newobj);
  337. return updateData;
  338. };
  339. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  340. var me = this;
  341. $.bootstrapLoading.start();
  342. var callback = function (data) {
  343. let initShow = false;//是否需要表格初始化显示
  344. if (updateField == 'customQuantity') {
  345. me.refreshAfterQuantityUpdate(data, node);
  346. } else {
  347. var doc = data.doc;
  348. for (var key in doc) {
  349. recode[key] = doc[key];
  350. }
  351. if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
  352. me.updateRationAdjustState(data.adjustState, recode.rationID, node);
  353. }
  354. if (recode.subList && recode.subList.length > 0) {
  355. initShow = true;
  356. }
  357. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  358. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  359. projectObj.mainController.deleteNode(node, true);
  360. }
  361. }
  362. }
  363. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  364. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  365. gljOprObj.showRationGLJSheetData();
  366. }
  367. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  368. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  369. if (initShow == true) {
  370. gljOprObj.refreshView();
  371. }
  372. $.bootstrapLoading.end();
  373. });
  374. }
  375. var query = {
  376. 'ID': recode.ID,
  377. 'projectID': recode.projectID,
  378. 'rationID': recode.rationID
  379. };
  380. var priceInfo = {
  381. base_price: recode.basePrice,
  382. market_price: recode.marketPrice
  383. }
  384. var doc = {};
  385. doc[updateField] = newval;
  386. if (updateField == "type") {
  387. doc.shortName = projectObj.project.projectGLJ.getShortNameByID[newval];
  388. }
  389. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  390. query: query,
  391. doc: doc,
  392. priceInfo: priceInfo
  393. }, callback, function (err) {
  394. $.bootstrapLoading.end();
  395. });
  396. }
  397. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  398. var me = this;
  399. data.glj_result.forEach(function (item) {
  400. me.refreshEachItme(item.doc, item.query);
  401. })
  402. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  403. };
  404. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  405. var nodes = [];
  406. var node = _.find(projectObj.project.mainTree.items, function (n) {
  407. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  408. })
  409. if (node) {
  410. node.data.adjustState = adjustState;
  411. nodes.push(node);
  412. }
  413. if (rnode) {
  414. nodes.push(rnode);
  415. }
  416. projectObj.mainController.refreshTreeNode(nodes);
  417. };
  418. ration_glj.prototype.getGLJData = function (cb) {
  419. CommonAjax.get('/rationGlj/getGLJData', function (data) {
  420. cb(data);
  421. })
  422. };
  423. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  424. let gljList = [];
  425. let allGLJ = gljOprObj.AllRecode;
  426. let billsItemID = null;
  427. let serialNo = 0;
  428. let selectedSerialNo = null;
  429. let nextNodeID = null;
  430. let parentNodeID = null;
  431. let children = [];
  432. if (selected.sourceType === project.Bills.getSourceType()) {
  433. billsItemID = selected.data.ID;
  434. parentNodeID = selected.getID();
  435. nextNodeID = selected.tree.rootID();
  436. } else {
  437. billsItemID = selected.data.billsItemID;
  438. serialNo = selected.data.serialNo;
  439. selectedSerialNo = selected.data.serialNo;
  440. nextNodeID = selected.getNextSiblingID();
  441. parentNodeID = selected.getParentID();
  442. }
  443. children = project.Ration.getBillsSortRation(billsItemID);
  444. serialNo == 0 ? serialNo = children.length : "";
  445. for (let con_key of GLJSelection) {
  446. var glj = _.find(allGLJ, function (item) {
  447. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  448. return i_key == con_key;
  449. });
  450. if (glj) {
  451. serialNo += 1;
  452. let new_glj = {
  453. ID: project.Ration.getNewRationID(),
  454. projectID: parseInt(project.ID()),
  455. billsItemID: billsItemID,
  456. type: rationType.gljRation,
  457. code: glj.code,
  458. name: glj.name,
  459. quantity: 0,
  460. unit: glj.unit,
  461. specs: glj.specs,
  462. subType: glj.gljType,
  463. basePrice: glj.basePrice,
  464. original_code: glj.code,
  465. shortName: glj.shortName,
  466. serialNo: serialNo,
  467. GLJID: glj.ID,
  468. adjCoe: glj.adjCoe,
  469. repositoryId: glj.repositoryId
  470. }
  471. if (glj.hasOwnProperty("compilationId")) {
  472. new_glj.from = "cpt";
  473. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  474. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  475. }
  476. }
  477. gljList.push(new_glj);
  478. }
  479. }
  480. if (gljList.length == 0) {
  481. return;
  482. }
  483. let postData = {
  484. gljList: gljList,
  485. projectID: parseInt(project.ID()),
  486. billsItemID: billsItemID,
  487. rationCount: project.Ration.maxRationID()
  488. }
  489. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  490. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  491. // 更新兄弟节点的序列号
  492. if (selectedSerialNo != null) {
  493. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  494. if (selectIndex + 1 < children.length) {
  495. for (let i = selectIndex + 1; i < children.length; i++) {
  496. children[i].serialNo += gljList.length;
  497. }
  498. }
  499. }
  500. /* let newNode=null;
  501. for (let r_glj of data) {
  502. r_glj.marketUnitFee = r_glj.marketPrice;
  503. r_glj.quantity = r_glj.quantity + "";
  504. project.Ration.datas.push(r_glj);
  505. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  506. newNode.source = r_glj;
  507. newNode.sourceType = project.Ration.getSourceType();
  508. newNode.data = r_glj;
  509. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  510. }*/
  511. //this.nodes[this.prefix + parentID];
  512. callback(parentNodeID,nextNodeID,data);
  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 = gljOprObj.setGLJPrice(ration,glj);
  667. ration.basePrice = glj.unit_price.base_price;
  668. ration.marketUnitFee = glj.unit_price.market_price;
  669. ration.isAdd = glj.unit_price.is_add;
  670. var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  671. if (mixRatioMap.hasOwnProperty(connect_index)) {
  672. var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  673. ration.subList = mixRatios;
  674. }
  675. }
  676. }
  677. return ration;
  678. };
  679. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  680. if (node.data[fieldName] === value) {
  681. return;
  682. }
  683. if (fieldName == "marketUnitFee") {
  684. var decimal = getDecimal("glj.unitPrice");
  685. var newval = number_util.checkNumberValue(value, decimal);
  686. if (newval) {
  687. fieldName = "marketPrice";
  688. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  689. return;
  690. }
  691. } else {
  692. if(fieldName == "contain"){
  693. if(value==null){
  694. value="";
  695. }else {
  696. var decimal = getDecimal("glj.quantity");
  697. value = number_util.checkNumberValue(value, decimal);
  698. fieldName="customQuantity";//填入自定义消耗
  699. }
  700. }
  701. if (value !== undefined && value !== null) {
  702. if (fieldName == "subType") {
  703. node.data.subType = value;
  704. fieldName = "type";//转换成更新工料机类型
  705. }
  706. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  707. return;
  708. }
  709. }
  710. // node.data.subType = value;
  711. projectObj.mainController.refreshTreeNode([node]);
  712. };
  713. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  714. if (this.needShowToTree(data)) {
  715. this.transferToNodeData(data);
  716. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  717. }
  718. };
  719. ration_glj.prototype.needShowToTree = function (data) {
  720. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  721. return true
  722. }
  723. return false
  724. };
  725. ration_glj.prototype.findGLJNodeByID = function (ID) {
  726. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应的树节点
  727. return n.sourceType == ModuleNames.ration_glj && n.data.ID == ID;
  728. });
  729. return node;
  730. };
  731. ration_glj.prototype.findRationNodeByID = function (ID) {
  732. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应定额的树节点
  733. return n.sourceType == ModuleNames.ration && n.data.ID == ID;
  734. });
  735. return node;
  736. };
  737. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  738. let node = this.findRationNodeByID(ration_glj.rationID);
  739. if (node) {
  740. node.changed = true;
  741. project.calcProgram.calcAndSave(node);
  742. }
  743. };
  744. return new ration_glj(project);
  745. }
  746. };